stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.29k stars 262 forks source link

CurrencyCode prop missing on ApplePay settings for initPaymentSheet #1333

Open jamzi opened 1 year ago

jamzi commented 1 year ago

Describe the bug

We initialized a new payment sheet with support for Apple Pay. In the initPaymentSheet is a config object for Apple Pay with the ApplePayParams: https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#ApplePayParams

When we use the cartItems with the item (label, amount, paymentType), and we see this in the native Apple Pay sheet.

The issue is that ApplePayParams does not accept any currencyCode param and the value of cartItems is displayed only in USD. The Apple docs show that PkPaymentRequest received currencyCode (https://developer.apple.com/documentation/passkit/pkpaymentrequest/1619248-currencycode) .

Is there a way to get this working, to either enable currencyCode to be passed in or suggest another way of doing this?

To Reproduce

  1. Create a new initPaymentSheet
  2. Pass in ApplePay params
  3. Observe the Apple Pay native sheet always showing USD

Expected behavior

ApplePayParams enable you to pass the currencyCode param.

Screenshots

image image

Smartphone (please complete the following information):

charliecruzan-stripe commented 1 year ago

Hi! On iOS, the currency code is taken from the payment intent that's created on the server

Screen Shot 2023-03-17 at 4 13 00 PM
jamzi commented 1 year ago

@charliecruzan-stripe Hey Charlie, we are using Setup Intent (future payment instead of immediate payment intent on the server.

The NodeJS call for stripe.setupIntents.create does not include currency or amount.

image

Currently the only workaround was to handle Apple Pay payment outside of the initPaymentSheet call with confirmPlatformPaySetupIntent, where we could specify the currencyCode.

charliecruzan-stripe commented 1 year ago

Ah I see what you mean, yeah we do need to add support for that!

pratikdhody commented 1 year ago

Any progress on this @charliecruzan-stripe?

pratikdhody commented 1 year ago

@charliecruzan-stripe any update on this please?

charliecruzan-stripe commented 1 year ago

No update yet, have not started work on this

pratikdhody commented 1 year ago

@charliecruzan-stripe - any updates please?

pratikdhody commented 1 year ago

@charliecruzan-stripe - any updates please?

projectnatz commented 5 months ago

We also encountered this problem on our application. Apple is becoming more strict during the reviews and demands that all Apple Pay details are present and correct. We need to be able to customize the currency of the Apple Pay summary and/or cart items during a payment method configuration (setup intent created from server).

tm00-git commented 3 months ago

@charliecruzan-stripe hi, any news on this issue? Thanks!

tm00-git commented 3 months ago

@charliecruzan-stripe Hey Charlie, we are using Setup Intent (future payment instead of immediate payment intent on the server.

The NodeJS call for stripe.setupIntents.create does not include currency or amount.

image

Currently the only workaround was to handle Apple Pay payment outside of the initPaymentSheet call with confirmPlatformPaySetupIntent, where we could specify the currencyCode.

Hi @jamzi, may you please describe the workaround while we wait for the fix in place? Many thanks.

tm00-git commented 2 months ago

Any news on a fix or at least workaround? Thanks!

mihailox commented 1 month ago

Will preface this with the following: This is in no way a good workaround, should be used just as a temporariy patch until this is fixed internally. Someone with a bit more time can probably make it nicer/more versatile so will leave this here.

Issue stemps from Pods -> StripePaymentSheet -> STPApplePayContext+PaymentSheet.swift where we have:

let paymentRequest = StripeAPI.paymentRequest(
          withMerchantIdentifier: applePay.merchantId,
          country: applePay.merchantCountryCode,
          currency: intent.currency ?? "USD"
      )

Considering SetupIntent does not allow for currency to be set nor we have that option within initPaymentSheet the quickest way i found is to actually just change the default based on need. This works for situations where single currency is needed.

Within podfile and under post_install do |installer| amend your post_install hook to include:

installer.pods_project.targets.each do |target|
      if target.name == 'StripePaymentSheet'
        # Access the source build phase to find the Swift file
        target.source_build_phase.files.each do |file|
          if file.display_name.include?('STPApplePayContext+PaymentSheet.swift')
            # Use `file.file_ref` to get the file reference
            file_ref = file.file_ref
            # Use the real path method to get the correct file path
            path = file_ref.real_path # This should give you the correct absolute path

            # Ensure the file has write permissions
            if File.exist?(path)
              puts "Setting write permissions for #{path}" # Debugging line
              system("chmod +w '#{path}'") # This sets write permissions

              # Now proceed to replace "USD" with "GBP"
              file_content = File.read(path)
              updated_content = file_content.gsub('"USD"', '"GBP"') # Replace "USD" with "GBP"
              File.write(path, updated_content)
              puts "Replaced currency in #{path}"
            else
              puts "File does not exist at path: #{path}" # Debugging line if file doesn't exist
            end
          end
        end
      end
     end

I've tested it both locally (device and simulator) and on a ci/cd built app and it works.

Replace "GBP" with desired currency as per need.

Again please use with caution.