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

Get default payment method on the UI side #1977

Closed
mansoorshahsaid opened this issue Dec 18, 2019 · 10 comments · Fixed by #2179
Closed

Get default payment method on the UI side #1977

mansoorshahsaid opened this issue Dec 18, 2019 · 10 comments · Fixed by #2179
Assignees
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@mansoorshahsaid
Copy link

mansoorshahsaid commented Dec 18, 2019

Summary

Any way to get the default payment method and then set it on UI side? On iOS, it is possible by setting paymentContext.defaultPaymentMethod = "card_token_id"
and then by doing that it reflects it on the UI side. Calling
let card = paymentContext.selectedPaymentOption
gets the correct card along with its information.

SDK version

12.8.0

Other information

On iOS we can do
paymentContext.defaultPaymentMethod = "card_token_id"
then
let card = paymentContext.selectedPaymentOption
is that possible on Android?

@mshafrir-stripe
Copy link
Collaborator

@mansoorshahsaid can you help me understand how you're using defaultPaymentMethod?

The stripe-ios SDK docs recommend to no longer use this property

@mshafrir-stripe mshafrir-stripe self-assigned this Dec 20, 2019
@mshafrir-stripe mshafrir-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label Dec 20, 2019
@mansoorshahsaid
Copy link
Author

Ah thank you for your response, I'll upgrade to the new SDK version on iOS for the pre-selection of the last payment. On the Android side, do we have anything similar? Can the SDK pre-select my last payment?

@mshafrir-stripe
Copy link
Collaborator

@mansoorshahsaid I'm still not clear what "pre-select my last payment" means. Do you mean have the SDK show something in the UI that you provide, or have the SDK up the last payment used for a given customer?

@Wajahat-Jawaid
Copy link

Wajahat-Jawaid commented Dec 23, 2019

Hey I came across the same problem. The problem is, PaymentSession needs to be persisted across user session. I've implemented the listener as follows

private inner class PaymentSessionListenerImpl constructor(
        activity: PaymentActivity
    ) : PaymentSession.ActivityPaymentSessionListener<PaymentActivity>(activity) {

        override fun onCommunicatingStateChanged(isCommunicating: Boolean) {
        }

        override fun onError(errorCode: Int, errorMessage: String) {
        }

        override fun onPaymentSessionDataChanged(data: PaymentSessionData) {
            // Update UI with the selected payment method info
        }
    }

Now what I need to implement is whenever user launches this Activity either by navigating from the other activities or even launching a new instance of the app, onPaymentSessionDataChanged should be called to preset the last selected payment method and update the UI

@mansoorshahsaid
Copy link
Author

@mshafrir Hey sorry for the late response. You pointed out how the new iOS version of the Stripe SDK recommending not to use defaultPaymentMethod so I updated the SDK. Now everything works perfectly without me needed to do anything on the client side. When I close the app and reopen it after selecting my payment method and adding funds, my payment method is preselected on the iOS page. The variable paymentContext.selectedPaymentOption contains my Card object after reopening the iOS page.

If you want to check it out, this is the feature I'm talking about on iOS: stripe/stripe-ios#1445

It would be great to have the same feature on Android! Currently there is no object that stores the last payment method.

@mansoorshahsaid
Copy link
Author

@mshafrir Hey sorry any update on this?

@mshafrir-stripe
Copy link
Collaborator

@mansoorshahsaid @Wajahat-Jawaid if I understand correctly, when a customer selects a payment method (and potentially completes a purchase), and then later comes back to make another purchase, that payment method should be persisted and then made accessible? Maybe via something like paymentSession.defaultPaymentMethodId?

@Ariandr
Copy link

Ariandr commented Jan 23, 2020

@mshafrir-stripe
Yes, that's exactly what's needed!

@mansoorshahsaid
Copy link
Author

mansoorshahsaid commented Jan 23, 2020

@mshafrir-stripe Exactly, the payment method should be persisted when the user comes back to make another purchase. It was previously implemented on iOS with paymentContext.defaultPaymentMethod = payment_id but now like you said this field is not recommended for use anymore. Therefore now on the development side, we don't need to set a defaultPaymentMethodId anymore. The SDK automatically handles the persistency of the default payment method.

While having paymentSession.defaultPaymentMethodId would be a great start. I was wondering if the Android SDK could handle the default payment method automatically like the iOS SDK does.

@Ariandr
Copy link

Ariandr commented Jan 23, 2020

@mansoorshahsaid @mshafrir-stripe
Yes, on iOS the persistency is handled locally on the user device and isn't connected to the cloud customer object.

It would be great to have the same in Android SDK.

mshafrir-stripe added a commit that referenced this issue Feb 13, 2020
Summary
When a customer starts a new `PaymentSession`, if they
have previously selected a payment method (determined
via `PaymentSessionPrefs`), fetch the full `PaymentMethod`
object from the API and update the `PaymentSessionData`.

This behavior will only be triggered when
`PaymentSessionConfig.shouldPrefetchCustomer == true`.

Motivation
Fixes #1977

Testing
- Add unit tests
- Manually verify
mshafrir-stripe added a commit that referenced this issue Feb 14, 2020
Summary
When a customer starts a new `PaymentSession`, if they
have previously selected a payment method (determined
via `PaymentSessionPrefs`), fetch the full `PaymentMethod`
object from the API and update the `PaymentSessionData`.

This behavior will only be triggered when
`PaymentSessionConfig.shouldPrefetchCustomer == true`.

Motivation
Fixes #1977

Testing
- Add unit tests
- Manually verify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants