【问题标题】:Firebase Cloud Functions(Stripe: AddPaymentSource)Firebase 云函数(条纹:AddPaymentSource)
【发布时间】:2018-06-07 11:08:51
【问题描述】:

我有一个 Android 和 iOS 应用程序,它使用 Firebase 云功能和 Stripe 来处理付款。

在客户端,我处理令牌操作,然后写入实时数据库。编写完 addPaymentSource 云函数后,会触发存储该支付源以供将来交易使用的触发器。

有趣的是,在 iOS 上创建令牌然后将该输出保存到我​​的服务器的过程按预期工作。当我试图将我的 iOS 实现复制到我的 Android 应用程序中时,我的问题就出现了。 Firebase 云功能按预期触发,但向我的服务器输出错误。

在服务器中发现错误:

"The source hash must include an 'object' key indicating what type of source to create."

客户端代码:

public void tokenizePaymentFields(){
    Stripe stripe = new Stripe(getApplicationContext(), stripePublishableKey);

    final Card stripeCard  = new Card(validCard.getCardNumber()
    ,Integer.valueOf(validCard.getExpiredDate().substring(0,2)),Integer.valueOf(validCard.getExpiredDate().substring(3,5)),validCard.getCvvCode());

    if (!stripeCard.validateCard()) {
        Toast.makeText(getApplicationContext(),
                "There was an error validating your card.",
                Toast.LENGTH_LONG
        ).show();
        return;
    }
    stripe.createToken(
            stripeCard,
            new TokenCallback() {
                public void onSuccess(Token token) {
                    // Send token to your server
                    pushToServer(token);
                }
                public void onError(Exception error) {
                    // Show localized error message
                    activitySubmitCreditCardBinding.progressCircle.setVisibility(View.INVISIBLE);
                    Toast.makeText(getApplicationContext(),
                            error.getLocalizedMessage(),
                            Toast.LENGTH_LONG
                    ).show();
                }
            }
    );
}

Stripe(Firebase 云函数): https://github.com/firebase/functions-samples/tree/master/stripe

【问题讨论】:

    标签: java android firebase stripe-payments google-cloud-functions


    【解决方案1】:

    与其将整个token object 发送到您的服务器,不如简单地发送令牌的id,如下所示:

    public void onSuccess(Token token) {
        // Send token to your server
        pushToServer(token.getId());
    }
    

    在您的服务器端 (Firebase) 代码中,charge creation request 只需要 source 参数中的令牌 ID,而不是完整的令牌对象。

    【讨论】:

    • 太棒了。感谢您的帮助。
    猜你喜欢
    • 2018-06-28
    • 2018-08-19
    • 1970-01-01
    • 2020-08-15
    • 2019-01-18
    • 2020-06-28
    • 2017-07-31
    • 2019-10-17
    • 2019-10-29
    相关资源
    最近更新 更多