【问题标题】:android stripe - get payment methods (sources / saved cards)?android stripe - 获取付款方式(来源/保存的卡)?
【发布时间】:2021-01-10 11:09:36
【问题描述】:

第 1 步:

CustomerSession.initCustomerSession

第 2 步:

CustomerSession.getInstance().retrieveCurrentCustomer

第 3 步:

我得到了客户(测试环境):{"hasMore":false,"id":"cus_I4xevY1VmbpCGL","sources":[],"totalCount":0,"url":"/v1/customers /cus_I4xevY1VmbpCGL/sources"}

但来源是空的,尽管在条纹仪表板中我可以看到付款方式(卡)已保存。

我想做的是做一个自定义 PaymentMethodsActivity

【问题讨论】:

  • customer.sources 在最新的 API 版本中被删除:stripe.com/docs/upgrades#2020-08-27(它通常也已被弃用,您应该使用 PaymentMethods,例如 stripe.dev/stripe-android/stripe/com.stripe.android/…
  • 如果您确实需要它,您应该使用比最新版本更旧的 API 版本创建您的临时密钥,因为它是您在后端创建临时密钥时设置的版本,它决定了 API 版本 CustomerSession使用,我想。
  • customer.sources 也只返回旧卡对象,我认为这可能是这里的问题。真正的解决方案是像我提到的那样使用customerSession.getPaymentMethods,这就是实现您的用例的方法。 sources 是遗留的,你应该忽略它。
  • 你说得对……我用过

标签: android stripe-payments


【解决方案1】:
  CustomerSession.getInstance().getPaymentMethods(PaymentMethod.Type.Card, new CustomerSession.PaymentMethodsRetrievalListener() {
        @Override
        public void onPaymentMethodsRetrieved(@NonNull List<PaymentMethod> paymentMethods) {
            Log.d("testcustumer-size", paymentMethods.size()+" ");
            if (paymentMethods.size() > 0) {
                for (PaymentMethod method : paymentMethods) {
                    Log.d("testcustumer", method.id);
                    Log.d("testcustumer", method.card.last4);
                    Log.d("testcustumer", method.card.expiryMonth + "/" + method.card.expiryYear);
                }
                adapter = new CardsAdapter(paymentMethods);
                cardsRV.setAdapter(adapter);
                ((CardsAdapter) adapter).setOnItemClickListener((position, v) -> {
                   // paymentIntent(paymentMethods.get(position).card,paymentIntentClientSecret);
                    stripe.confirmPayment(SavedCardsActivity.this,
                            ConfirmPaymentIntentParams.createWithPaymentMethodId(
                                    paymentMethods.get(position).id,
                                    paymentIntentClientSecret,
                                    null
                            )
                    );
                });
            }
        }
        @Override
        public void onError(int errorCode, @NonNull String errorMessage, @Nullable StripeError stripeError) {

        }
    });

【讨论】:

    猜你喜欢
    • 2021-02-14
    • 2020-08-16
    • 2021-07-28
    • 2021-09-02
    • 2021-03-11
    • 2019-07-05
    • 1970-01-01
    • 2022-11-08
    • 2016-05-14
    相关资源
    最近更新 更多