Android Stripe-获取付款方式(来源/保存的卡)?

时间:2020-09-24 07:42:11

标签: android stripe-payments

第1步:

CustomerSession.initCustomerSession

第2步:

CustomerSession.getInstance()。retrieveCurrentCustomer

第3步:

我正在获取custumer(测试环境):{“ hasMore”:false,“ id”:“ cus_I4xevY1VmbpCGL”,“ sources”:[],“ totalCount”:0,“ url”:“ / v1 / customers / cus_I4xevY1VmbpCGL / sources“}

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

我要做的事情是制作一个客户付款方式 enter image description here

1 个答案:

答案 0 :(得分: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) {

        }
    });