braintree 不必每次都输入信用卡数据

braintree not havingt to enter credit card data each time

假设我有一位注册客户已经提供了他的信用卡数据,我不希望他在下次购买时再次输入,我该怎么做?现在我正在使用托管字段,每次测试时我都必须输入信用卡数据。

确保客户信息(包括付款方式信息)存储在 Braintree Vault 中。

您可以自己创建一个客户,可以使用付款方式,也可以使用带有账单地址的信用卡。客户创建示例;

result = braintree.Customer.create({
  "first_name": "Charity",
  "last_name": "Smith",
  "payment_method_nonce": nonce_from_the_client
})


result.is_success
# True

result.customer.id
# e.g 160923

result.customer.payment_methods[0].token
# e.g f28w39

如果您打算与客户同时创建交易,您可能需要使用 Transaction.sale() with either the options.store_in_vault_on_success or options.store_in_vault options。例如:

result = braintree.Transaction.sale({
"amount": "10.00",
"payment_method_nonce": nonce_from_the_client,
"customer": {
  "id": "a_customer_id"
},
"options": {
"store_in_vault_on_success": True,
  }
})

一旦他们的信息存储在 Vault 中,您就可以在交易 API 调用中传递他们的支付方式令牌,而不是随机数。