import type { PaymentMethodCreateParams , ApplePay , PaymentSheet , CreatePaymentMethodResult , RetrievePaymentIntentResult , RetrieveSetupIntentResult , ConfirmPaymentResult , HandleCardActionResult , ConfirmSetupIntentResult , CreateTokenForCVCUpdateResult , ApplePayResult , ApplePayError , StripeError , InitPaymentSheetResult , PresentPaymentSheetResult , ConfirmPaymentSheetPaymentResult , ConfirmSetupIntent , CreateTokenResult , Card , PayWithGooglePayResult , GooglePayInitResult , GooglePay , CreateGooglePayPaymentMethodResult , OpenApplePaySetupResult , } from '../types' ; import { useCallback , useEffect , useState } from 'react' ; import { isiOS } from '../helpers' ; import NativeStripeSdk from '../NativeStripeSdk' ; import { confirmPayment , createPaymentMethod , retrievePaymentIntent , retrieveSetupIntent , confirmApplePayPayment , confirmSetupIntent , createTokenForCVCUpdate , handleCardAction , handleURLCallback , presentApplePay , updateApplePaySummaryItems , initPaymentSheet , presentPaymentSheet , confirmPaymentSheetPayment , createToken , initGooglePay , createGooglePayPaymentMethod , presentGooglePay , openApplePaySetup , } from '../functions' ; /**
 * useStripe hook
 */ export function useStripe ( ) { const [ isApplePaySupported , setApplePaySupported ] = useState < boolean | null > ( null ) ; useEffect ( ( ) => { async function checkApplePaySupport ( ) { const isSupported = isiOS && ( await NativeStripeSdk . isApplePaySupported ( ) ) ; setApplePaySupported ( isSupported ) ; } checkApplePaySupport ( ) ; } , [ ] ) ; const _createPaymentMethod = useCallback ( async ( data , options = { } ) : Promise < CreatePaymentMethodResult > => { return createPaymentMethod ( data , options ) ; } , [ ] ) ; const _createToken = useCallback ( async ( params ) : Promise < CreateTokenResult > => { return createToken ( params ) ; } , [ ] ) ; const _retrievePaymentIntent = useCallback ( async ( clientSecret ) : Promise < RetrievePaymentIntentResult > => { return retrievePaymentIntent ( clientSecret ) ; } , [ ] ) ; const _retrieveSetupIntent = useCallback ( async ( clientSecret ) : Promise < RetrieveSetupIntentResult > => { return retrieveSetupIntent ( clientSecret ) ; } , [ ] ) ; const _confirmPayment = useCallback ( async ( paymentIntentClientSecret , data , options = { } ) : Promise < ConfirmPaymentResult > => { return confirmPayment ( paymentIntentClientSecret , data , options ) ; } , [ ] ) ; const _presentApplePay = useCallback ( async ( params ) : Promise < ApplePayResult > => { return presentApplePay ( params ) ; } , [ ] ) ; const _updateApplePaySummaryItems = useCallback ( async ( summaryItems , errorAddressFields = [ ] ) : Promise < { error ? : StripeError < ApplePayError > ; } > => { return updateApplePaySummaryItems ( summaryItems , errorAddressFields ) ; } , [ ] ) ; const _confirmApplePayPayment = useCallback ( async ( clientSecret ) : Promise < { error ? : StripeError < ApplePayError > ; } > => { return confirmApplePayPayment ( clientSecret ) ; } , [ ] ) ; const _handleCardAction = useCallback ( async ( paymentIntentClientSecret ) : Promise < HandleCardActionResult > => { return handleCardAction ( paymentIntentClientSecret ) ; } , [ ] ) ; const _confirmSetupIntent = useCallback ( async ( paymentIntentClientSecret , data , options = { } ) : Promise < ConfirmSetupIntentResult > => { return confirmSetupIntent ( paymentIntentClientSecret , data , options ) ; } , [ ] ) ; const _createTokenForCVCUpdate = useCallback ( async ( cvc ) : Promise < CreateTokenForCVCUpdateResult > => { return createTokenForCVCUpdate ( cvc ) ; } , [ ] ) ; const _initPaymentSheet = useCallback ( async ( params ) : Promise < InitPaymentSheetResult > => { return initPaymentSheet ( params ) ; } , [ ] ) ; const _presentPaymentSheet = useCallback ( async ( ) : Promise < PresentPaymentSheetResult > => { return presentPaymentSheet ( ) ; } , [ ] ) ; const _confirmPaymentSheetPayment = useCallback ( async ( ) : Promise < ConfirmPaymentSheetPaymentResult > => { return confirmPaymentSheetPayment ( ) ; } , [ ] ) ; const _handleURLCallback = useCallback ( async ( url ) : Promise < boolean > => { return handleURLCallback ( url ) ; } , [ ] ) ; const _initGooglePay = useCallback ( async ( params ) : Promise < GooglePayInitResult > => { return initGooglePay ( params ) ; } , [ ] ) ; const _presentGooglePay = useCallback ( async ( params ) : Promise < PayWithGooglePayResult > => { return presentGooglePay ( params ) ; } , [ ] ) ; const _createGooglePayPaymentMethod = useCallback ( async ( params ) : Promise < CreateGooglePayPaymentMethodResult > => { return createGooglePayPaymentMethod ( params ) ; } , [ ] ) ; const _openApplePaySetup = useCallback ( async ( ) : Promise < OpenApplePaySetupResult > => { return openApplePaySetup ( ) ; } , [ ] ) ; return { retrievePaymentIntent : _retrievePaymentIntent , retrieveSetupIntent : _retrieveSetupIntent , confirmPayment : _confirmPayment , createPaymentMethod : _createPaymentMethod , handleCardAction : _handleCardAction , isApplePaySupported : isApplePaySupported , presentApplePay : _presentApplePay , confirmApplePayPayment : _confirmApplePayPayment , confirmSetupIntent : _confirmSetupIntent , createTokenForCVCUpdate : _createTokenForCVCUpdate , updateApplePaySummaryItems : _updateApplePaySummaryItems , handleURLCallback : _handleURLCallback , confirmPaymentSheetPayment : _confirmPaymentSheetPayment , presentPaymentSheet : _presentPaymentSheet , initPaymentSheet : _initPaymentSheet , createToken : _createToken , initGooglePay : _initGooglePay , presentGooglePay : _presentGooglePay , createGooglePayPaymentMethod : _createGooglePayPaymentMethod , openApplePaySetup : _openApplePaySetup , } ; }