简体   繁体   English

Braintree-过帐付款方式

[英]Braintree - What to post for paymentMethodNonce

I am just getting started with Braintree and using it's API in PHP. 我刚刚开始使用Braintree,并在PHP中使用它的API。

I have come across one thing, the "paymentMethodNouce" which is posted from the HTML file. 我碰到了一件事,从HTML文件发布的“ paymentMethodNouce”。

My question, is what does this need to include? 我的问题是,这需要包括什么? Ie do we post the send the credit card, billing information through here? 即我们是否通过此处发布发送信用卡,账单信息? And in what content does the form need to be in? 表格需要包含哪些内容? Ie Should it be like this: 即应该是这样的:

    <form> 
      <input type="text" name="payment['creditcard']" value="124214124" />
      <input type="text" name"payment['billingaddress']" value="12312313"/>
   </form>

If this is not correct, what actually get's passed through to the paymentMethodNonce and how is the credit card details handled? 如果这是不正确的,那么实际将什么传递给paymentMethodNonce以及如何处理信用卡详细信息?

Let me describe the procedure 让我描述一下程序

Payment method nonce 付款方式随机数

The payment method nonce is a string returned by the client SDK to represent a payment method. 付款方式现时是客户端SDK返回的表示付款方式的string This string is a reference to the customer payment method details that were provided in your payment form and should be sent to your server where it can be used with the server SDKs to create a new transaction request . 此字符串是对您在付款表格中提供的客户付款方式详细信息的引用,应将其发送到服务器,在此可以与服务器SDK一起使用以创建新的交易请求

To setup braintree 设置braintree

  1. First configure the environment and API credentials 首先配置环境和API凭据

    Braintree_Configuration::environment('sandbox'); Braintree_Configuration :: environment('sandbox'); Braintree_Configuration::merchantId('use_your_merchant_id'); Braintree_Configuration :: merchantId('use_your_merchant_id'); Braintree_Configuration::publicKey('use_your_public_key'); Braintree_Configuration :: publicKey('use_your_public_key'); Braintree_Configuration::privateKey('use_your_private_key'); Braintree_Configuration :: privateKey('use_your_private_key');

  2. Get client token via ajax call from your server 通过来自服务器的Ajax调用获取客户端令牌

    echo($clientToken = Braintree_ClientToken::generate()); echo($ clientToken = Braintree_ClientToken :: generate());

  3. Use client token returned from braintree to set up your form. 使用从braintree返回的客户端令牌来设置您的表单。 Your form will be visible only if you have client token available. 仅当您有客户端令牌可用时,表单才可见

  4. Your form will now be rendering on your client. 现在,您的表单将在您的客户端上呈现。 User fills in all info and submits the form. 用户填写所有信息并提交表格。

  5. If eveything went fine braintree will return payment method nonce for that user. 如果一切顺利,braintree将为该用户返回付款方式随机数
  6. Store the payment method nonce on your server. 付款方式随机数存储在您的服务器上。

    $nonce = $_POST["payment_method_nonce"] $ nonce = $ _POST [“ payment_method_nonce”]

  7. Use that payment method nonce to perform the transaction in future. 使用该付款方式随机数在以后执行交易。

    $result = Braintree_Transaction::sale([ 'amount' => '100.00', 'paymentMethodNonce' => nonceFromTheClient ]); $ result = Braintree_Transaction :: sale([['amount'=>'100.00','paymentMethodNonce'=> nonceFromTheClient]);

In addition to WitVault's answer , you have several solutions to go from step 5 to 6. You can send it with an AJAX call or create a hidden input in your form: 除了WitVault的答案外 ,您还可以从第5步到第6步中找到几种解决方案。您可以通过AJAX调用将其发送,也可以在表单中创建隐藏的输入:

<input type="hidden" name="payment_method_nonce">

And when your token is generated, set the latter as value of the input element then submit the form: 在生成令牌时,将后者设置为input元素的值,然后提交表单:

var form = document.querySelector('#payment_form');
form.addEventListener('submit', function (event) {
   event.preventDefault();
   hostedFieldsInstance.tokenize(function (tokenizeErr, payload) {
      document.querySelector('input[name="payment_method_nonce"]').value = payload.nonce;
      form.submit();
   });
}, false);

Then step 6 will allow you to retrieve the token. 然后,第6步将允许您检索令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM