How do I save Apple Pay transaction on a customer?

折月煮酒 提交于 2020-01-17 13:48:12

问题


I implemented Apple Pay into my app and it works fine, but currently when I use apple pay the transaction isn't linked to a user, when I add a customer/user parameter on my cloud code I get this error.

error:
type: "invalid_request_error"
message: "Customer cus_xxx does not have a linked card with ID tok_xxxx."
param: "card"
code: "missing"

Parse.Cloud.define("chargeApplePay", function(request, response){
Stripe.Charges.create({
amount: 100 * 100,
currency: "usd",
customer: request.params.idcustomer,
token: request.params.tokenid
},{
  success: function(httpResponse) {
    response.success("success");
  },
  error: function(httpResponse) {
    response.error(httpResponse)
    }
  });
});

回答1:


Instead of passing in a token parameter as the ID of the token you created, you could omit this parameter altogether when creating the charge and pass in only the customer parameter instead: https://stripe.com/docs/api/node#create_charge-customer

This assumes that you already created a customer and saved that token as a payment source for that customer before making this charge: https://stripe.com/docs/charges#saving-credit-card-details-for-later

If you do want to charge a specific card for that customer (as opposed to the default card on record), you'd pass in the card ID (card_*) as the source: https://stripe.com/docs/api/node#create_charge-source



来源:https://stackoverflow.com/questions/37951550/how-do-i-save-apple-pay-transaction-on-a-customer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!