【问题标题】:PHP Braintree - create flow with Recurring Billing without using SubscriptionsPHP Braintree - 在不使用订阅的情况下使用定期计费创建流程
【发布时间】:2021-11-19 19:31:05
【问题描述】:

我不想创建订阅,但仍然能够在我的 SaaS 软件中使用定期计费方法:

  1. 注册付费计划
  2. 应用交易销售功能
  3. 创建 Braintree 客户
  4. 在数据库中保存支付方式令牌
  5. 在下个月(只要我愿意)使用支付方式令牌创建一个新的交易销售

所有这些都没有订阅功能。 Braintree 是否允许

目前我遇到以下问题:

  1. 用户注册付费计划
  2. 交易销售以 Nonce 值执行
  3. 我尝试使用相同的 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
    ]
]);

【问题讨论】:

    标签: php braintree


    【解决方案1】:

    已解决

    这个问题的答案“所有这些都没有订阅功能。Braintree 允许吗?”是的。

    关于错误“不能多次使用 payment_method_nonce”,我必须首先使用 nonce 创建客户,然后使用令牌执行销售。

    $result = $gateway->customer()->create(
    [
        'firstName' => $customer['name'],
        'company' => $customer['company'],
        'email' => $customer['email'],
        'paymentMethodNonce' => $customer['payment_method_nonce']
    ]);
    
    // We now execute the payment with the token returned
    $braintree->executePayment($result->customer->paymentMethods[0]->token, $total);
    

    由于我将令牌保存在数据库中,因此我可以在下个月随时再次执行付款,而无需用户干预。

    【讨论】:

      猜你喜欢
      • 2016-12-16
      • 2018-02-26
      • 2016-04-18
      • 2015-02-08
      • 2014-09-18
      • 2021-05-19
      • 2013-04-03
      • 2019-02-22
      • 2012-12-09
      相关资源
      最近更新 更多