import NativeSQIPCore from './modules/NativeSQIPCore'; import NativeSQIPCardEntry from './modules/NativeSQIPCardEntry'; import NativeSQIPBuyer from './modules/NativeSQIPBuyer'; import { createInAppPaymentsError, verifyBooleanType, verifyIntegerType, verifyNumberType, verifyObjectType, verifyStringType, verifyThemeType, } from './utils'; import { type BuyerVerificationSuccessCallback, type CancelAndCompleteCallback, type CardDetails, type CardEntryConfig, type FailureCallback, GooglePayEnvironment, type GooglePayConfig, type NonceSuccessCallback, type NonceSuccessCallbackWithResult, type ErrorDetails, type ThemeType, type ApplePayConfig, PaymentType, type ApplePayNonceSuccessCallbackWithResult, type ApplePayCancelAndCompleteCallback, ApplePayNonceSuccessState, } from './types'; import { ErrorCodes, GooglePayPriceStatus } from './types'; import NativeSQIPGooglePay from './modules/NativeSQIPGooglePay'; import NativeSQIPApplePay from './modules/NativeSQIPApplePay'; export * from './types'; let onCardNonceRequestSuccessCached: | ((cardDetails: CardDetails) => void) | undefined; let lastApplePayNonceRequestState: { state: ApplePayNonceSuccessState; errorMessage?: string; } = { state: ApplePayNonceSuccessState.Canceled, errorMessage: undefined }; function buildVerificationNativeParams(cardEntryConfig: CardEntryConfig) { verifyObjectType(cardEntryConfig, 'cardEntryConfig should be an object'); verifyStringType( cardEntryConfig.squareLocationId, 'squareLocationId should be a valid string' ); verifyStringType( cardEntryConfig.buyerAction, 'buyerAction should be a valid string' ); verifyNumberType(cardEntryConfig.amount, 'amount should be a valid number'); verifyStringType( cardEntryConfig.currencyCode, 'currencyCode should be a valid string' ); return { locationId: cardEntryConfig.squareLocationId!, buyerAction: cardEntryConfig.buyerAction!, money: { amount: cardEntryConfig.amount, currencyCode: cardEntryConfig.currencyCode, }, contact: { givenName: cardEntryConfig.givenName, familyName: cardEntryConfig.familyName, addressLines: cardEntryConfig.addressLines, city: cardEntryConfig.city, countryCode: cardEntryConfig.countryCode, email: cardEntryConfig.email, phone: cardEntryConfig.phone, postalCode: cardEntryConfig.postalCode, region: cardEntryConfig.region, }, }; } export namespace SQIPCore { export function setSquareApplicationId(applicationId: string): void { verifyStringType(applicationId, 'applicationId should be a valid string'); NativeSQIPCore.setSquareApplicationId(applicationId); } export function getSquareApplicationId(): string | null { return NativeSQIPCore.getSquareApplicationId(); } } export namespace SQIPCardEntry { /** * @deprecated Use * `startCardEntryFlow( * collectPostalCode: boolean, * onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, * onCardEntryCancel?: CancelAndCompleteCallback * )` instead. Now you don't need to completeCardEntry */ export function startCardEntryFlow( config: CardEntryConfig, onCardNonceRequestSuccess: NonceSuccessCallback, onCardEntryCancel: CancelAndCompleteCallback ): void; export function startCardEntryFlow( collectPostalCode: boolean, onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, onCardEntryCancel?: CancelAndCompleteCallback ): void; export function startCardEntryFlow( param: CardEntryConfig | boolean, onCardNonceRequestSuccess?: | NonceSuccessCallback | NonceSuccessCallbackWithResult, onCardEntryCancel?: CancelAndCompleteCallback ): void { let collectPostalCode: boolean = true; if (typeof param === 'boolean') { verifyBooleanType(param, 'collectPostalCode should be a boolean.'); collectPostalCode = param; } else { let cardEntryInternalConfig: CardEntryConfig = { collectPostalCode: true, }; if (param) { verifyObjectType(param, 'cardEntryConfig should be an object.'); cardEntryInternalConfig = param; } if (cardEntryInternalConfig.collectPostalCode != null) { verifyBooleanType( cardEntryInternalConfig.collectPostalCode, 'cardEntryConfig.collectPostalCode should be a boolean.' ); } else { cardEntryInternalConfig.collectPostalCode = true; } collectPostalCode = cardEntryInternalConfig.collectPostalCode; } onCardNonceRequestSuccessCached = (cardDetails: CardDetails) => { if (onCardNonceRequestSuccess) { Promise.resolve(onCardNonceRequestSuccess(cardDetails)) .then((result) => { if (result) { if (result.success) { NativeSQIPCardEntry.completeCardEntry(() => { if (result.onCardEntryComplete) { result.onCardEntryComplete(); } }); onCardNonceRequestSuccessCached = undefined; } else { showCardNonceProcessingInternal( result.errorMessage ?? 'Unknown error' ); } } }) .catch((error: any) => { showCardNonceProcessingInternal(String(error) ?? 'Unknown error'); }); } else { NativeSQIPCardEntry.completeCardEntry(() => {}); } }; NativeSQIPCardEntry.startCardEntryFlow( collectPostalCode, (cardDetails: CardDetails) => { if (onCardNonceRequestSuccessCached) { onCardNonceRequestSuccessCached(cardDetails); } }, () => { if (onCardEntryCancel) onCardEntryCancel(); } ); } /** * @deprecated Use * `onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult,` * see `startCardEntryFlow` instead. Now you don't need to completeCardEntry * manually. */ export function completeCardEntry( onCardEntryComplete?: CancelAndCompleteCallback ): void { NativeSQIPCardEntry.completeCardEntry(() => { if (onCardEntryComplete) { onCardEntryComplete(); } }); } /** * @deprecated Use * `onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult,` * see `startCardEntryFlow`. Now you don't need * to showCardNonceProcessingError manually. */ export function showCardNonceProcessingError(errorMessage: string): void { showCardNonceProcessingInternal(errorMessage); } function showCardNonceProcessingInternal(errorMessage: string): void { if (onCardNonceRequestSuccessCached) { NativeSQIPCardEntry.updateOnCardNonceRequestSuccessCallback( onCardNonceRequestSuccessCached ); } verifyStringType(errorMessage, 'errorMessage should be a string'); NativeSQIPCardEntry.showCardNonceProcessingError(errorMessage); } export function startGiftCardEntryFlow( onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, onCardEntryCancel?: CancelAndCompleteCallback ): void; /** * @deprecated Use * `startGiftCardEntryFlow( * onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, * onCardEntryCancel?: CancelAndCompleteCallback * )` instead. Now you don't need to completeCardEntry */ export function startGiftCardEntryFlow( onCardNonceRequestSuccess: NonceSuccessCallback, onCardEntryCancel: CancelAndCompleteCallback ): void; export function startGiftCardEntryFlow( onCardNonceRequestSuccess?: | NonceSuccessCallbackWithResult | NonceSuccessCallback, onCardEntryCancel?: CancelAndCompleteCallback ): void { onCardNonceRequestSuccessCached = (cardDetails: CardDetails) => { if (onCardNonceRequestSuccess) { Promise.resolve(onCardNonceRequestSuccess(cardDetails)) .then((result) => { if (result) { if (result.success) { NativeSQIPCardEntry.completeCardEntry(() => { if (result.onCardEntryComplete) { result.onCardEntryComplete(); } }); onCardNonceRequestSuccessCached = undefined; } else { showCardNonceProcessingInternal( result.errorMessage ?? 'Unknown error' ); } } }) .catch((error: any) => { showCardNonceProcessingInternal(String(error) ?? 'Unknown error'); }); } else { NativeSQIPCardEntry.completeCardEntry(() => {}); } }; NativeSQIPCardEntry.startGiftCardEntryFlow( (cardDetails: CardDetails) => { if (onCardNonceRequestSuccessCached) { onCardNonceRequestSuccessCached(cardDetails); } }, () => { if (onCardEntryCancel) onCardEntryCancel(); } ); } /** * @deprecated Use * `SQIPBuyer.startBuyerVerificationFlow( * paymentSourceId: string, * cardEntryConfig: CardEntryConfig, * onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, * onBuyerVerificationFailure?: FailureCallback, * )` instead. */ export function startBuyerVerificationFlow( paymentSourceId: string, cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess: BuyerVerificationSuccessCallback, onBuyerVerificationFailure: FailureCallback, _onCardEntryCancel: CancelAndCompleteCallback ): void { SQIPBuyer.startBuyerVerificationFlow( paymentSourceId, cardEntryConfig, onBuyerVerificationSuccess, onBuyerVerificationFailure ); } /** * Collects a card nonce, then runs buyer verification (3DS) on that nonce. * Do not pass a `paymentSourceId` — verification always uses the collected nonce. */ export function startCardEntryFlowWithBuyerVerification( collectPostalCode: boolean, cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onCardEntryCancel?: CancelAndCompleteCallback ): void; /** * @deprecated `paymentSourceId` is ignored. Combined verification methods * collect a nonce first, then run 3DS on that nonce. */ export function startCardEntryFlowWithBuyerVerification( collectPostalCode: boolean, paymentSourceId: string, cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, onCardEntryCancel?: CancelAndCompleteCallback ): void; export function startCardEntryFlowWithBuyerVerification( collectPostalCode: boolean, paymentSourceIdOrConfig: string | CardEntryConfig, configOrSuccess?: CardEntryConfig | BuyerVerificationSuccessCallback, successOrFailure?: BuyerVerificationSuccessCallback | FailureCallback, failureOrNonceOrCancel?: | FailureCallback | NonceSuccessCallbackWithResult | CancelAndCompleteCallback, _nonceOrCancel?: NonceSuccessCallbackWithResult | CancelAndCompleteCallback, maybeCancel?: CancelAndCompleteCallback ): void { verifyBooleanType( collectPostalCode, 'collectPostalCode should be a boolean.' ); const hasPaymentSourceId = typeof paymentSourceIdOrConfig === 'string'; const cardEntryConfig = ( hasPaymentSourceId ? configOrSuccess : paymentSourceIdOrConfig ) as CardEntryConfig; const onBuyerVerificationSuccess = ( hasPaymentSourceId ? successOrFailure : configOrSuccess ) as BuyerVerificationSuccessCallback | undefined; const onBuyerVerificationFailure = ( hasPaymentSourceId ? failureOrNonceOrCancel : successOrFailure ) as FailureCallback | undefined; const onCardEntryCancel = ( hasPaymentSourceId ? maybeCancel : failureOrNonceOrCancel ) as CancelAndCompleteCallback | undefined; const { locationId, buyerAction, money, contact } = buildVerificationNativeParams(cardEntryConfig); NativeSQIPCardEntry.startCardEntryFlowWithBuyerVerification( collectPostalCode, locationId, buyerAction, money, contact, (verificationResult) => { if (onBuyerVerificationSuccess) { onBuyerVerificationSuccess(verificationResult); } }, (errorDetails) => { if (onBuyerVerificationFailure) { onBuyerVerificationFailure(errorDetails as ErrorDetails); } }, (_cardDetails: CardDetails) => { // Card entry auto-completes before 3DS; this callback is unused. }, () => { if (onCardEntryCancel) onCardEntryCancel(); } ); } /** * Collects a gift-card nonce, then runs buyer verification (3DS) on that nonce. * Do not pass a `paymentSourceId` — verification always uses the collected nonce. */ export function startGiftCardEntryFlowWithBuyerVerification( cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onCardEntryCancel?: CancelAndCompleteCallback ): void; /** * @deprecated `paymentSourceId` is ignored. Combined verification methods * collect a nonce first, then run 3DS on that nonce. */ export function startGiftCardEntryFlowWithBuyerVerification( paymentSourceId: string, cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onCardNonceRequestSuccess?: NonceSuccessCallbackWithResult, onCardEntryCancel?: CancelAndCompleteCallback ): void; export function startGiftCardEntryFlowWithBuyerVerification( paymentSourceIdOrConfig: string | CardEntryConfig, configOrSuccess?: CardEntryConfig | BuyerVerificationSuccessCallback, successOrFailure?: BuyerVerificationSuccessCallback | FailureCallback, failureOrNonceOrCancel?: | FailureCallback | NonceSuccessCallbackWithResult | CancelAndCompleteCallback, _nonceOrCancel?: NonceSuccessCallbackWithResult | CancelAndCompleteCallback, maybeCancel?: CancelAndCompleteCallback ): void { const hasPaymentSourceId = typeof paymentSourceIdOrConfig === 'string'; const cardEntryConfig = ( hasPaymentSourceId ? configOrSuccess : paymentSourceIdOrConfig ) as CardEntryConfig; const onBuyerVerificationSuccess = ( hasPaymentSourceId ? successOrFailure : configOrSuccess ) as BuyerVerificationSuccessCallback | undefined; const onBuyerVerificationFailure = ( hasPaymentSourceId ? failureOrNonceOrCancel : successOrFailure ) as FailureCallback | undefined; const onCardEntryCancel = ( hasPaymentSourceId ? maybeCancel : failureOrNonceOrCancel ) as CancelAndCompleteCallback | undefined; const { locationId, buyerAction, money, contact } = buildVerificationNativeParams(cardEntryConfig); NativeSQIPCardEntry.startGiftCardEntryFlowWithBuyerVerification( locationId, buyerAction, money, contact, (verificationResult) => { if (onBuyerVerificationSuccess) { onBuyerVerificationSuccess(verificationResult); } }, (errorDetails) => { if (onBuyerVerificationFailure) { onBuyerVerificationFailure(errorDetails as ErrorDetails); } }, (_cardDetails: CardDetails) => { // Gift card entry auto-completes before 3DS; this callback is unused. }, () => { if (onCardEntryCancel) onCardEntryCancel(); } ); } export function setIOSCardEntryTheme(theme: ThemeType): void { verifyThemeType(theme); NativeSQIPCardEntry.setIOSCardEntryTheme(theme); } } export namespace SQIPBuyer { export function startBuyerVerificationFlow( paymentSourceId: string, cardEntryConfig: CardEntryConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback ): void { verifyStringType( paymentSourceId, 'paymentSourceId should be a valid string' ); const { locationId, buyerAction, money, contact } = buildVerificationNativeParams(cardEntryConfig); NativeSQIPBuyer.startBuyerVerificationFlow( paymentSourceId, locationId, buyerAction, money, contact, (verificationResult) => { if (onBuyerVerificationSuccess) { onBuyerVerificationSuccess(verificationResult); } }, (errorDetails) => { if (onBuyerVerificationFailure) { onBuyerVerificationFailure(errorDetails as ErrorDetails); } } ); } } export namespace SQIPGooglePay { export function initializeGooglePay( squareLocationId: string, environment: GooglePayEnvironment ): void { verifyStringType( squareLocationId, 'squareLocationId should be a valid string' ); verifyIntegerType( environment.valueOf(), 'environment should be a valid integer' ); NativeSQIPGooglePay.initializeGooglePay( squareLocationId, environment.valueOf() ); } export async function canUseGooglePay(): Promise { try { return await NativeSQIPGooglePay.canUseGooglePay(); } catch (error) { throw createInAppPaymentsError(error); } } export async function requestGooglePayNonce( googlePayConfig: GooglePayConfig, onGooglePayNonceRequestSuccess?: NonceSuccessCallback, onGooglePayNonceRequestFailure?: FailureCallback, onGooglePayCanceled?: CancelAndCompleteCallback ): Promise { verifyObjectType( googlePayConfig, 'googlePayConfig should be a valid object' ); verifyStringType( googlePayConfig.price, 'googlePayConfig.price should be a valid string' ); verifyStringType( googlePayConfig.currencyCode, 'googlePayConfig.currencyCode should be a valid string' ); verifyIntegerType( googlePayConfig.priceStatus.valueOf(), 'googlePayConfig.priceStatus should be a valid integer' ); try { await NativeSQIPGooglePay.requestGooglePayNonce( googlePayConfig, (cardDetails: CardDetails) => { if (onGooglePayNonceRequestSuccess) { onGooglePayNonceRequestSuccess(cardDetails); } }, (errorDetails) => { if (onGooglePayNonceRequestFailure) { onGooglePayNonceRequestFailure(errorDetails as ErrorDetails); } }, () => { if (onGooglePayCanceled) { onGooglePayCanceled(); } } ); } catch (error) { throw createInAppPaymentsError(error); } } /** * Collects a Google Pay nonce, then runs buyer verification (3DS) on that nonce. * Do not pass a `paymentSourceId` — verification always uses the collected nonce. */ export async function requestGooglePayNonceWithBuyerVerification( cardEntryConfig: CardEntryConfig, googlePayConfig: GooglePayConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onGooglePayNonceRequestFailure?: FailureCallback, onGooglePayCanceled?: CancelAndCompleteCallback ): Promise; /** * @deprecated `paymentSourceId` is ignored. Combined verification methods * collect a nonce first, then run 3DS on that nonce. */ export async function requestGooglePayNonceWithBuyerVerification( paymentSourceId: string, cardEntryConfig: CardEntryConfig, googlePayConfig: GooglePayConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onGooglePayNonceRequestSuccess?: NonceSuccessCallback, onGooglePayNonceRequestFailure?: FailureCallback, onGooglePayCanceled?: CancelAndCompleteCallback ): Promise; export async function requestGooglePayNonceWithBuyerVerification( paymentSourceIdOrConfig: string | CardEntryConfig, configOrGooglePayConfig: CardEntryConfig | GooglePayConfig, googlePayConfigOrSuccess?: | GooglePayConfig | BuyerVerificationSuccessCallback, successOrFailure?: BuyerVerificationSuccessCallback | FailureCallback, failureOrNonceSuccess?: FailureCallback | NonceSuccessCallback, nonceSuccessOrNonceFailure?: | NonceSuccessCallback | FailureCallback | CancelAndCompleteCallback, nonceFailureOrCancel?: FailureCallback | CancelAndCompleteCallback, maybeCancel?: CancelAndCompleteCallback ): Promise { const hasPaymentSourceId = typeof paymentSourceIdOrConfig === 'string'; const cardEntryConfig = ( hasPaymentSourceId ? configOrGooglePayConfig : paymentSourceIdOrConfig ) as CardEntryConfig; const googlePayConfig = ( hasPaymentSourceId ? googlePayConfigOrSuccess : configOrGooglePayConfig ) as GooglePayConfig; const onBuyerVerificationSuccess = ( hasPaymentSourceId ? successOrFailure : googlePayConfigOrSuccess ) as BuyerVerificationSuccessCallback | undefined; const onBuyerVerificationFailure = ( hasPaymentSourceId ? failureOrNonceSuccess : successOrFailure ) as FailureCallback | undefined; const onGooglePayNonceRequestFailure = ( hasPaymentSourceId ? nonceFailureOrCancel : failureOrNonceSuccess ) as FailureCallback | undefined; const onGooglePayCanceled = ( hasPaymentSourceId ? maybeCancel : nonceSuccessOrNonceFailure ) as CancelAndCompleteCallback | undefined; verifyObjectType(googlePayConfig, 'googlePayConfig should be an object'); verifyStringType( googlePayConfig.price, 'googlePayConfig.price should be a valid string' ); verifyStringType( googlePayConfig.currencyCode, 'googlePayConfig.currencyCode should be a valid string' ); verifyIntegerType( googlePayConfig.priceStatus.valueOf(), 'googlePayConfig.priceStatus should be a valid integer' ); const { locationId, buyerAction, money, contact } = buildVerificationNativeParams(cardEntryConfig); try { await NativeSQIPGooglePay.requestGooglePayNonceWithBuyerVerification( googlePayConfig, locationId, buyerAction, money, contact, (verificationResult) => { if (onBuyerVerificationSuccess) { onBuyerVerificationSuccess(verificationResult); } }, (errorDetails) => { if (onBuyerVerificationFailure) { onBuyerVerificationFailure(errorDetails as ErrorDetails); } }, (_cardDetails: CardDetails) => { // Google Pay auto-completes before 3DS; this callback is unused. }, (errorDetails) => { if (onGooglePayNonceRequestFailure) { onGooglePayNonceRequestFailure(errorDetails as ErrorDetails); } }, () => { if (onGooglePayCanceled) { onGooglePayCanceled(); } } ); } catch (error) { throw createInAppPaymentsError(error); } } /** * @deprecated Use `GooglePayPriceStatus` instead. * @example 'import { GooglePayPriceStatus } from "react-native-square-in-app-payments";' */ export const TotalPriceStatusNotCurrentlyKnown = GooglePayPriceStatus.TotalPriceStatusNotCurrentlyKnown; /** * @deprecated Use `GooglePayPriceStatus` instead. * @example 'import { GooglePayPriceStatus } from "react-native-square-in-app-payments";' */ export const TotalPriceStatusEstimated = GooglePayPriceStatus.TotalPriceStatusEstimated; /** * @deprecated Use `GooglePayPriceStatus` instead. * @example 'import { GooglePayPriceStatus } from "react-native-square-in-app-payments";' */ export const TotalPriceStatusFinal = GooglePayPriceStatus.TotalPriceStatusFinal; /** * @deprecated Use `GooglePayEnvironment` instead. * @example 'import { GooglePayEnvironment } from "react-native-square-in-app-payments";' */ export const EnvironmentProduction = GooglePayEnvironment.EnvironmentProduction; /** * @deprecated Use `GooglePayEnvironment` instead. * @example 'import { GooglePayEnvironment } from "react-native-square-in-app-payments";' */ export const EnvironmentTest = GooglePayEnvironment.EnvironmentTest; } export namespace SQIPApplePay { export function initializeApplePay(applePayMerchantId: string): void { verifyStringType( applePayMerchantId, 'applePayMerchantId should be a valid string' ); NativeSQIPApplePay.initializeApplePay(applePayMerchantId); } export async function canUseApplePay(): Promise { try { return await NativeSQIPApplePay.canUseApplePay(); } catch (error) { throw createInAppPaymentsError(error); } } /** * @deprecated now you don't need to call this method manually. * use `requestApplePayNonce` with `ApplePayNonceSuccessCallbackWithResult` instead. */ export function completeApplePayAuthorization( isSuccess: boolean, errorMessage?: string ): void { completeApplePayAuthorizationInternal(isSuccess, errorMessage); } function completeApplePayAuthorizationInternal( isSuccess: boolean, errorMessage?: string ): void { verifyBooleanType(isSuccess, 'isSuccess should be a valid boolean'); if (errorMessage) { verifyStringType(errorMessage, 'errorMessage should be a valid string'); } NativeSQIPApplePay.completeApplePayAuthorization( isSuccess, errorMessage ?? '' ); } /** @deprecated Use `requestApplePayNonceWithParams` instead. */ export async function requestApplePayNonce( applePayConfig: ApplePayConfig, onApplePayNonceRequestSuccess: NonceSuccessCallback, onApplePayNonceRequestFailure: FailureCallback, onApplePayComplete: CancelAndCompleteCallback ): Promise; export async function requestApplePayNonce( applePayConfig: ApplePayConfig, onApplePayNonceRequestSuccess?: ApplePayNonceSuccessCallbackWithResult, onApplePayNonceRequestFailure?: FailureCallback, onApplePayComplete?: ApplePayCancelAndCompleteCallback ): Promise; export async function requestApplePayNonce( applePayConfig: ApplePayConfig, onApplePayNonceRequestSuccess?: | NonceSuccessCallback | ApplePayNonceSuccessCallbackWithResult, onApplePayNonceRequestFailure?: FailureCallback, onApplePayComplete?: | CancelAndCompleteCallback | ApplePayCancelAndCompleteCallback ): Promise { verifyObjectType(applePayConfig, 'applePayConfig should be a valid object'); verifyStringType( applePayConfig.price, 'applePayConfig.price should be a valid string' ); verifyStringType( applePayConfig.summaryLabel, 'applePayConfig.summaryLabel should be a valid string' ); verifyStringType( applePayConfig.countryCode, 'applePayConfig.countryCode should be a valid string' ); verifyStringType( applePayConfig.currencyCode, 'applePayConfig.currencyCode should be a valid string' ); let { paymentType } = applePayConfig; if (!applePayConfig.paymentType) { paymentType = PaymentType.PaymentTypeFinal; } else { verifyIntegerType( applePayConfig.paymentType, 'applePayConfig.paymentType should be a valid integer' ); } try { await NativeSQIPApplePay.requestApplePayNonce( applePayConfig.price, applePayConfig.summaryLabel, applePayConfig.countryCode, applePayConfig.currencyCode, paymentType!.valueOf(), (cardDetails: CardDetails) => { if (onApplePayNonceRequestSuccess) { Promise.resolve(onApplePayNonceRequestSuccess(cardDetails)).then( (result) => { if (result) { lastApplePayNonceRequestState = { state: result.state, errorMessage: result.errorMessage, }; completeApplePayAuthorizationInternal( result.state === ApplePayNonceSuccessState.Succeeded, result.errorMessage ); } } ); } }, (errorDetails) => { if (onApplePayNonceRequestFailure) { lastApplePayNonceRequestState = { state: ApplePayNonceSuccessState.Failure, errorMessage: (errorDetails as ErrorDetails).message ?? 'Unknown error', }; completeApplePayAuthorizationInternal( false, (errorDetails as ErrorDetails).message ?? 'Unknown error' ); onApplePayNonceRequestFailure(errorDetails as ErrorDetails); } }, () => { if (onApplePayComplete) { onApplePayComplete( lastApplePayNonceRequestState.state, lastApplePayNonceRequestState.errorMessage ); lastApplePayNonceRequestState = { state: ApplePayNonceSuccessState.Canceled, errorMessage: undefined, }; } } ); } catch (error) { throw createInAppPaymentsError(error); } } /** * Collects an Apple Pay nonce, then runs buyer verification (3DS) on that nonce. * Do not pass a `paymentSourceId` — verification always uses the collected nonce. */ export async function requestApplePayNonceWithBuyerVerification( cardEntryConfig: CardEntryConfig, applePayConfig: ApplePayConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onApplePayNonceRequestFailure?: FailureCallback, onApplePayComplete?: ApplePayCancelAndCompleteCallback ): Promise; /** * @deprecated `paymentSourceId` is ignored. Combined verification methods * collect a nonce first, then run 3DS on that nonce. */ export async function requestApplePayNonceWithBuyerVerification( paymentSourceId: string, cardEntryConfig: CardEntryConfig, applePayConfig: ApplePayConfig, onBuyerVerificationSuccess?: BuyerVerificationSuccessCallback, onBuyerVerificationFailure?: FailureCallback, onApplePayNonceRequestSuccess?: ApplePayNonceSuccessCallbackWithResult, onApplePayNonceRequestFailure?: FailureCallback, onApplePayComplete?: ApplePayCancelAndCompleteCallback ): Promise; export async function requestApplePayNonceWithBuyerVerification( paymentSourceIdOrConfig: string | CardEntryConfig, configOrApplePayConfig: CardEntryConfig | ApplePayConfig, applePayConfigOrSuccess?: ApplePayConfig | BuyerVerificationSuccessCallback, successOrFailure?: BuyerVerificationSuccessCallback | FailureCallback, failureOrNonceSuccess?: | FailureCallback | ApplePayNonceSuccessCallbackWithResult, nonceSuccessOrNonceFailure?: | ApplePayNonceSuccessCallbackWithResult | FailureCallback | ApplePayCancelAndCompleteCallback, nonceFailureOrComplete?: | FailureCallback | ApplePayCancelAndCompleteCallback, maybeComplete?: ApplePayCancelAndCompleteCallback ): Promise { const hasPaymentSourceId = typeof paymentSourceIdOrConfig === 'string'; const cardEntryConfig = ( hasPaymentSourceId ? configOrApplePayConfig : paymentSourceIdOrConfig ) as CardEntryConfig; const applePayConfig = ( hasPaymentSourceId ? applePayConfigOrSuccess : configOrApplePayConfig ) as ApplePayConfig; const onBuyerVerificationSuccess = ( hasPaymentSourceId ? successOrFailure : applePayConfigOrSuccess ) as BuyerVerificationSuccessCallback | undefined; const onBuyerVerificationFailure = ( hasPaymentSourceId ? failureOrNonceSuccess : successOrFailure ) as FailureCallback | undefined; const onApplePayNonceRequestFailure = ( hasPaymentSourceId ? nonceFailureOrComplete : failureOrNonceSuccess ) as FailureCallback | undefined; const onApplePayComplete = ( hasPaymentSourceId ? maybeComplete : nonceSuccessOrNonceFailure ) as ApplePayCancelAndCompleteCallback | undefined; verifyObjectType(applePayConfig, 'applePayConfig should be a valid object'); verifyStringType( applePayConfig.price, 'applePayConfig.price should be a valid string' ); verifyStringType( applePayConfig.summaryLabel, 'applePayConfig.summaryLabel should be a valid string' ); verifyStringType( applePayConfig.countryCode, 'applePayConfig.countryCode should be a valid string' ); verifyStringType( applePayConfig.currencyCode, 'applePayConfig.currencyCode should be a valid string' ); let { paymentType } = applePayConfig; if (!applePayConfig.paymentType) { paymentType = PaymentType.PaymentTypeFinal; } else { verifyIntegerType( applePayConfig.paymentType, 'applePayConfig.paymentType should be a valid integer' ); } const { locationId, buyerAction, money, contact } = buildVerificationNativeParams(cardEntryConfig); try { await NativeSQIPApplePay.requestApplePayNonceWithBuyerVerification( applePayConfig.price, applePayConfig.summaryLabel, applePayConfig.countryCode, applePayConfig.currencyCode, paymentType!.valueOf(), locationId, buyerAction, money, contact, (verificationResult) => { if (onBuyerVerificationSuccess) { onBuyerVerificationSuccess(verificationResult); } }, (errorDetails) => { if (onBuyerVerificationFailure) { onBuyerVerificationFailure(errorDetails as ErrorDetails); } }, (_cardDetails: CardDetails) => { // Apple Pay auto-completes before 3DS; this callback is unused. }, (errorDetails) => { if (onApplePayNonceRequestFailure) { lastApplePayNonceRequestState = { state: ApplePayNonceSuccessState.Failure, errorMessage: (errorDetails as ErrorDetails).message ?? 'Unknown error', }; completeApplePayAuthorizationInternal( false, (errorDetails as ErrorDetails).message ?? 'Unknown error' ); onApplePayNonceRequestFailure(errorDetails as ErrorDetails); } }, () => { if (onApplePayComplete) { onApplePayComplete( lastApplePayNonceRequestState.state, lastApplePayNonceRequestState.errorMessage ); lastApplePayNonceRequestState = { state: ApplePayNonceSuccessState.Canceled, errorMessage: undefined, }; } } ); } catch (error) { throw createInAppPaymentsError(error); } } } /** * @deprecated Use `ErrorCodes` instead. * @example 'import { ErrorCodes } from "react-native-square-in-app-payments";' */ export const SQIPErrorCodes = ErrorCodes;