【发布时间】: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