【问题标题】:Stripe InvalidRequestException in javajava中的条纹InvalidRequestException
【发布时间】:2016-12-15 03:11:10
【问题描述】:

我正在尝试在我的 Android 应用中测试 Stripe 支付 API。 Android 应用向服务器发送一个令牌(令牌由 Stripe 提供给 Android 应用),然后服务器通过 Stripe 收费 API 使用该令牌向用户收费。由于我正在测试该过程,因此我使用的是 Stripe 提供的虚拟值,但是当我发起收费呼叫时,我在服务器端收到一个 InvalidRequestException。我很难测试它。 为了清楚起见,我还添加了一张图片。

这是我的代码。

try {
    Map<String, Object> chargeParams = new HashMap<String, Object>();
    chargeParams.put("amount", jsonNode.get("amount")); // amount in cents, again
    chargeParams.put("currency", "USD");
    chargeParams.put("source", token);
    chargeParams.put("description", "charge from server");

    Charge charge = Charge.create(chargeParams);
    String des = charge.getDescription();
} 
catch (CardException e) {
    // The card has been declined
}

如何测试这个过程? 请引导我走向正确的方向。

【问题讨论】:

    标签: java android stripe-payments


    【解决方案1】:

    在屏幕截图中,查看详细的错误消息。它会告诉您出了什么问题:您的集成将字符串 "&lt;com.stripe.android.model.Token@..." 作为令牌发送到 Stripe 的 API。

    从您的 Android 应用程序中,您可能会将令牌的字符串表示形式发送到服务器。相反,您只需发送令牌 ID。令牌 ID 是一个以 tok_ 开头的字符串,后跟随机字母数字字符。您可以拨打getId()访问它。

    【讨论】:

    • 哦,谢谢。我想他们应该在他们的文档中清楚地提到它。这句话来自他们的文档Your app will receive the token back, and can then send the token to an endpoint on your server, where it can be used to process a payment, establish recurring billing, or merely saved for later use.
    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 2011-03-09
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    相关资源
    最近更新 更多