【问题标题】:delete user card from Stripe Android从 Stripe Android 中删除用户卡
【发布时间】:2017-05-06 18:06:23
【问题描述】:

我正在尝试使用此代码从条带中删除卡:

第一次尝试:

com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
String cardId = token.getCard().getId();
customer = Customer.retrieve(payments.appPreference.getStripeCustomerId());
DeletedExternalAccount delete = customer.getSources().retrieve(cardId).delete();

错误: 我收到 com.stripe.exception.InvalidRequestException: No such source: card_xxxxxxxxxxxxxxxxxxxxxx;请求ID:req_xxxxxxxxxxxx

第二次尝试:

com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);    
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
DeletedCard delete = token.getCard().delete();

错误: com.stripe.exception.APIConnectionException:API 请求 Stripe 期间出现 IOException (https://api.stripe.com):null 请检查您的互联网连接,然后重试。如果此问题仍然存在,您应该通过https://twitter.com/stripestatus 查看 Stripe 的服务状态,或通过 support@stripe.com 告知我们。

原因:java.net.MalformedURLException

谁能帮我解决这个问题?

【问题讨论】:

    标签: java android stripe-payments


    【解决方案1】:

    无法在您的 Android 应用程序中执行任何此操作,因为这些调用需要您的 Secret API 密钥。您绝不应该在您的 Android 应用程序中使用 Secret API 密钥,否则攻击者可能会得到它,然后代表您创建费用、退款或转账。

    您需要做的是在服务器端处理此代码。您将调用删除卡 [API][1] 并确保在代码中传递正确的客户和卡 ID。在 Java 中,但在服务器端,你会这样做:

    Customer customer = Customer.retrieve("cus_XXXXXXX");
    customer.getSources().retrieve("card_YYYYYY").delete();
    

    【讨论】:

    • 我知道它从移动端不安全。但我想知道为什么它不起作用。我正在尝试使用正确的客户 ID 和卡 ID(来自令牌),但出现错误。
    • @SANAT:如果来自令牌的卡将无法使用。您希望卡片 ID 存储在客户上,您可以通过 API 或仪表板进行查找。
    【解决方案2】:

    @koopajah 是对的。它从移动端不安全。

    这是因为我创建了 Token 但没有调用 api 来创建卡片。 令牌有 Card 对象,但未分配给任何客户端。所以,我收到了这个错误。

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2013-07-22
      • 2020-05-21
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多