Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for paymentMethodOrder #1662

Merged
merged 10 commits into from
May 24, 2024

Conversation

charliecruzan-stripe
Copy link
Collaborator

@charliecruzan-stripe charliecruzan-stripe commented May 16, 2024

Summary

Adds support for paymentMethodOrder to PaymentSheet, and also adds support for the experimental field allowsRemovalOfLastSavedPaymentMethod. This could be removed/changed at any time

Motivation

parity with native libraries

closes #1656

@charliecruzan-stripe charliecruzan-stripe merged commit b2369b3 into master May 24, 2024
3 of 5 checks passed
@charliecruzan-stripe charliecruzan-stripe deleted the charliecruzan-5-16 branch May 24, 2024 00:00
@mariobrubio
Copy link

Hey @charliecruzan-stripe. I was testing this allowsRemovalOfLastSavedPaymentMethod flag and it seems it doesn't work.

I'm using 0.38.2 and I can actually delete the card if I only have one. The sheet should prevent the user to delete the last saved card.

@charliecruzan-stripe
Copy link
Collaborator Author

can you share how you're using it? Are you using Expo?

@mariobrubio
Copy link

mariobrubio commented Jul 19, 2024

can you share how you're using it? Are you using Expo?

Thanks for replying @charliecruzan-stripe I'm not using expo, I'm using rn-cli.

Here's how I'm using it.

<CustomerSheetBeta.CustomerSheet
  visible={customerSheetVisible}
  setupIntentClientSecret={setupIntent}
  customerEphemeralKeySecret={ephemeralKeySecret}
  customerId={customer}
  allowsRemovalOfLastSavedPaymentMethod={false}
  returnURL={'stripe-example://stripe-redirect'}
  onResult={({ error, paymentOption, paymentMethod }) => {
    console.log('error', error);
    setCustomerSheetVisible(false);              
    if (paymentOption) {
      setSelectedPaymentOption(paymentOption);
      console.log(JSON.stringify(paymentOption, null, 2));
    }
    if (paymentMethod) {
      setSelectedPaymentMethod(paymentMethod);
      console.log(JSON.stringify(paymentMethod, null, 2));
    }
  }}
  
/>

I based my work from the CustomerSheetScreen

The only difference would be that I'm not passing a CustomerAdapter

@charliecruzan-stripe
Copy link
Collaborator Author

charliecruzan-stripe commented Jul 19, 2024

and you re-ran pod install after upgrading to 0.38.2? is this on ios or android or both

@mariobrubio
Copy link

and you re-ran pod install after upgrading to 0.38.2? is this on ios or android or both

Just did it, deleted pods and re-installed them. Still unable to "prevent" the users to delete the last saved card.

I'm testing on iOS.

@mariobrubio
Copy link

Also - if you have two cards and you delete the "selected" one, shouldn't the other card get selected automatically? - what if the card is expired? These cases are apparently not covered and I'm not seeing any props that help with this.

@mariobrubio
Copy link

@charliecruzan-stripe - just a friendly reminder on the above. 🙏

@@ -89,7 +91,11 @@ class CustomerSheetFragment : Fragment() {
.googlePayEnabled(googlePayEnabled)
.headerTextForSelectionScreen(headerTextForSelectionScreen)
.preferredNetworks(mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")))
.allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod ?: true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this always defaulting to true? if I inject allowsRemovalOfLastSavedPaymentMethod being false this code would default to true @charliecruzan-stripe

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the elvis operator tests whether the left hand side is non-null: https://kotlinlang.org/docs/null-safety.html#elvis-operator

here's some sample code to prove this will evaluate to false if allowsRemovalOfLastSavedPaymentMethod is false

@mariobrubio
Copy link

As I'm testing on iOS I forced the following to be false and it worked.

@_spi(STP) public var allowsRemovalOfLastSavedPaymentMethod = false

That means the variable is not getting changed in between the bridge and the native code.

@charliecruzan-stripe
Copy link
Collaborator Author

This is working on iOS for me as well, can you share a sample project that reproduces this?

@mariobrubio
Copy link

mariobrubio commented Jul 22, 2024

This is working on iOS for me as well, can you share a sample project that reproduces this?

@charliecruzan-stripe I'm literally now running the example app from this repository and the following does not work:

allowsRemovalOfLastSavedPaymentMethod={false}

within:

{useComponent && customerAdapter && (
        <CustomerSheetBeta.CustomerSheet
          visible={customerSheetVisible}
          setupIntentClientSecret={setupIntent}
          customerEphemeralKeySecret={ephemeralKeySecret}
          customerId={customer}
          allowsRemovalOfLastSavedPaymentMethod={false}
          returnURL={'stripe-example://stripe-redirect'}
          onResult={({ error, paymentOption, paymentMethod }) => {
            setCustomerSheetVisible(false);
            if (error) {
              Alert.alert(error.code, error.localizedMessage);
            }
            if (paymentOption) {
              setSelectedPaymentOption(paymentOption);
              console.log(JSON.stringify(paymentOption, null, 2));
            }
            if (paymentMethod) {
              console.log(JSON.stringify(paymentMethod, null, 2));
            }
          }}
          customerAdapter={customerAdapter}
        />
      )}

image

@mariobrubio
Copy link

I managed to understand why this was happening.

I was referencing both the component and the programmatically initialized sheets. When I removed the component one the flag started to work. It is tricky, hope this gets documented so future devs won't spend much time troubleshooting. Thanks for the support @charliecruzan-stripe

Copy link
Collaborator

@davidme-stripe davidme-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[allowsRemovalOfLastSavedPaymentMethod] for the stripe-react-native
3 participants