android - 如何在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) {
}
}
解决方案
Stripe 的移动 SDK 组件,例如您正在使用的 PaymentSession/CustomerSession,现在默认创建 PaymentMethod 对象(例如 Stripe Android 在 v9.1.0 之后移动到 PaymentMethod 对象)。
PaymentMethod 对象与传统的 Token/Source/Card 对象有些不同,因为它们仍然可以附加到 Customer,但它们不会自动具有“默认”概念。
现在,您正在将source
Customer 上的字段设置为 PaymentMethod 对象,该对象不受支持(source
是一个遗留字段,因此它仅支持 Token 或 Source 对象)。
相反,您想要的是使用attachPaymentMethod()
CustomerSession [0] 上的函数,将 PaymentMethod 附加到客户。
然后在服务器端,当您创建订阅时,您还将通过default_payment_method: pm_123
指定要在 [1] 上创建订阅的附加 PaymentMethod 中的哪个。
[1] https://stripe.com/docs/api/subscriptions/object#subscription_object-default_payment_method
推荐阅读
- javascript - Fetch-api OpenWeather,访问属性“名称”值并显示它的问题
- plugins - 即使在 android 和 Flutter 插件安装设置之后也不会创建 Flutter 应用程序
- vercel - Vercel 上具有多个部署、环境变量和机密的一个存储库?
- javascript - 从位于数组内的数组中删除逗号
- javascript - 如何使用 JavaScript 在数组内打印数组
- python - 如何从列表中生成一列复选框
- linux - 是否有可能在 Linux 上拥有一个完全静态链接的 GUI 应用程序?
- database - 如何从 AWS S3 存储桶上的配置单元发送结果中获取 JSON 格式的查询结果?
- javascript - 用 JS 实现 CRC8 校验和
- spring - 无法从 LocalContainerEntityManagerFactoryBean(休眠 OGM 提供程序)检索 EntityManager