簡體   English   中英

PHP Braintree - 在不使用訂閱的情況下使用循環計費創建流程

[英]PHP Braintree - create flow with Recurring Billing without using Subscriptions

我不想創建訂閱,但仍然能夠在我的 SaaS 軟件中使用定期計費方法:

  1. 注冊付費計划
  2. 申請交易銷售 function
  3. 創建 braintree 客戶
  4. 在數據庫中保存支付方式令牌
  5. 在下個月(任何我想要的時候)使用支付方式令牌創建一個新的交易銷售

所有這些都沒有訂閱功能。 布倫特里允許嗎?

目前我遇到以下問題:

  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
    ]
]);

解決了

這個問題的答案“所有這些都沒有訂閱功能。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);

由於我將令牌保存在數據庫中,因此我可以在下個月隨時再次執行付款,而無需用戶干預。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM