首页 > 解决方案 > 如何在android中更新条带默认设置客户默认源

问题描述

我目前正在使用条纹 'com.stripe:stripe-android:15.0.1' 并调用 presentPaymentMethodSelection 来呈现支付活动流程。我正在使用订阅服务,因此我只需要显示卡片、设置默认卡片并添加新卡片。我认为对于 android stripe 仍然没有像 ios 这样的 onClick stripe 默认源更新。所以我使用 setCustomerDefaultSource 来解决这个目的。

问题 1:获取 default-source = null。

2:无法更新卡=收到“没有这样的来源:'pm_************************'”

点击卡时收到错误:

errorCode = 400
errorMessage = "No such source: 'pm_*********************'"
stripeError = {Stripe****} 
 charge = ""
 code = "resource_missing"
 declineCode = ""
 message = "No such source: 'pm_*********************'"
 param = "source"
 type = "invalid_request_error"
 shadow$_klass_ = {Cla***} "class com.stripe.android.StripeError"
 shadow$_monitor_ = 0

这是一张卡片信息

0 = {PaymentMethod0} 
 billingDetails = {PaymentMethod$Billin} 
 card = {PaymentMethod$Car} 
 cardPresent = null
 created = {Long@10} 
 customerId = "cus_**************er"
 id = "pm_*********************"
 ideal = null
 liveMode = false
 metadata = {HashMap@###}  size = 0
 type = "card"
 shadow$_klass_ = {Class@$$$} "class com.stripe.android.model.PaymentMethod"
 shadow$_monitor_ = 0

以及下面函数paymentId的参数:“pm_************************”

     mCustomerSessionN.setCustomerDefaultSource(paymentId, Source.SourceType.CARD, new CustomerSession.CustomerRetrievalListener() {
            @Override
            public void onCustomerRetrieved(@NonNull Customer customer) {
                Log.d("", "onCustomerRetrieved: " + customer);
                Toast.makeText(getApplicationContext(), "Card is added ", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onError(int errorCode, @NonNull String errorMessage, @Nullable StripeError stripeError) {
                Log.d("", "onCustomerRetrieved: " + errorMessage);
                Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_SHORT).show();
            }
        });
    } catch (Exception e) {

    }
}

标签: androidstripe-payments

解决方案


Stripe 的移动 SDK 组件,例如您正在使用的 PaymentSession/CustomerSession,现在默认创建 PaymentMethod 对象(例如 Stripe Android 在 v9.1.0 之后移动到 PaymentMethod 对象)。

PaymentMethod 对象与传统的 Token/Source/Card 对象有些不同,因为它们仍然可以附加到 Customer,但它们不会自动具有“默认”概念。

现在,您正在将sourceCustomer 上的字段设置为 PaymentMethod 对象,该对象不受支持(source是一个遗留字段,因此它仅支持 Token 或 Source 对象)。

相反,您想要的是使用attachPaymentMethod()CustomerSession [0] 上的函数,将 PaymentMethod 附加到客户。

然后在服务器端,当您创建订阅时,您还将通过default_payment_method: pm_123指定要在 [1] 上创建订阅的附加 PaymentMethod 中的哪个。

[0] https://stripe.dev/stripe-android/stripe/com.stripe.android/-customer-session/attach-payment-method.html

[1] https://stripe.com/docs/api/subscriptions/object#subscription_object-default_payment_method


推荐阅读