react-native-passkit-apple-pay
Version:
A React Native library for integrating Apple Pay with Conekta payment processor using PassKit framework
117 lines (116 loc) • 3.93 kB
TypeScript
/**
* React Native PassKit Apple Pay for Conekta
*
* A React Native library for integrating Apple Pay with Conekta as payment processor
* using PassKit framework.
*
* @author Conekta <alexis.nahuel@conekta.com>
* @license MIT
*/
import React, { PropsWithChildren } from 'react';
import { TouchableOpacityProps } from 'react-native';
/**
* Apple Pay payment method information as returned by PassKit
*/
export interface ApplePayPaymentMethod {
displayName: string;
network: string;
type: string;
}
/**
* Apple Pay payment data header containing cryptographic information
* Required for Conekta's Apple Pay token validation
*/
export interface ApplePayPaymentDataHeader {
publicKeyHash: string;
ephemeralPublicKey: string;
transactionId: string;
}
/**
* Apple Pay payment data containing encrypted payment information
*/
export interface ApplePayPaymentData {
data: string;
signature: string;
header: ApplePayPaymentDataHeader;
version: string;
}
/**
* Complete Apple Pay token structure for Conekta integration
* This token should be sent directly to Conekta's API for processing
*/
export interface ApplePayToken {
paymentData: ApplePayPaymentData;
paymentMethod: ApplePayPaymentMethod;
transactionIdentifier: string;
}
/**
* Configuration context for Apple Pay integration with Conekta
*/
interface ApplePayContextType {
merchantIdentifier: string;
supportedNetworks: string[];
countryCode: string;
currencyCode: string;
}
interface ApplePayProviderProps extends ApplePayContextType {
}
/**
* Payment summary for display in Apple Pay sheet
* Amount should be in the smallest currency unit (e.g., cents for MXN)
*/
interface PaymentSummary {
label: string;
amount: string;
}
interface ApplePayButtonProps extends TouchableOpacityProps {
/**
* Payment details for the transaction
*/
payment: PaymentSummary;
/**
* Callback executed when payment is authorized and token is received
* The application is responsible for processing the token with Conekta's API
*/
onPaymentToken: (token: ApplePayToken) => void;
/**
* Optional callback executed when payment initiation fails or user cancels
*/
onError?: (error: Error) => void;
children: React.ReactNode;
}
/**
* Provider component that configures global Apple Pay parameters for Conekta integration
* All ApplePayButton components within this provider will use these settings
*
* @param merchantIdentifier - Your merchant ID registered with Conekta
* @param countryCode - Country code where your business operates
* @param currencyCode - Local currency code for your market
* @param supportedNetworks - Payment networks supported by Conekta
*/
export declare const ApplePayProvider: React.FC<PropsWithChildren<ApplePayProviderProps>>;
/**
* Hook to access Apple Pay configuration context
* Must be used within an ApplePayProvider
*/
export declare const useApplePayContext: () => ApplePayContextType;
/**
* A wrapper component that converts its children into an Apple Pay button
* Initiates the native payment flow when pressed and returns a token
*
* The token returned by this component should be sent directly to your
* backend for processing with Conekta's charges/orders API
*/
export declare const ApplePayButton: React.FC<ApplePayButtonProps>;
/**
* Completes the Apple Pay transaction from the JavaScript side
* Must be called after Conekta has processed the payment
*
* This function signals to the native Apple Pay UI whether the payment
* succeeded or failed, allowing the user to see the appropriate feedback
*
* @param success - true if Conekta payment was successful, false otherwise
* @param errorMessage - Error message to display if success is false
*/
export declare const completeApplePayPayment: (success: boolean, errorMessage?: string | null) => Promise<void>;
export {};