【发布时间】:2021-11-19 19:31:05
【问题描述】:
我不想创建订阅,但仍然能够在我的 SaaS 软件中使用定期计费方法:
- 注册付费计划
- 应用交易销售功能
- 创建 Braintree 客户
- 在数据库中保存支付方式令牌
- 在下个月(只要我愿意)使用支付方式令牌创建一个新的交易销售
所有这些都没有订阅功能。 Braintree 是否允许?
目前我遇到以下问题:
- 用户注册付费计划
- 交易销售以 Nonce 值执行
- 我尝试使用相同的 Nonce 在 Braintree 中创建客户,但出现错误“不能多次使用 payment_method_nonce”
这个错误是有道理的,但是我如何将当前用户注册与 Braintree 中创建的客户进行匹配,以便以后使用支付方式令牌重新使用交易销售?
https://developer.paypal.com/braintree/docs/guides/customers#create-with-payment-method
// After the Transaction Sale is executed with success I try this:
$result = $gateway->customer()->create(
[
'firstName' => $customer['name'],
'company' => $customer['company'],
'email' => $customer['email'],
'paymentMethodNonce' => $customer['payment_method_nonce']
]);
这将返回付款方式令牌,我可以像这样保存在数据库中:
$db->braintree_customer_id = $braintreeCustomer->customer->id;
$db->braintree_payment_token = $braintreeCustomer->customer->paymentMethods[0]->token;
$db->save();
在下个月,我的软件将能够使用以下方式执行付款:
$result = $gateway->transaction()->sale(
[
'amount' => $price,
'paymentMethodToken' => $token, // <--- saved in DB
'options' =>
[
'submitForSettlement' => true
]
]);
【问题讨论】: