尝试将数据发布到服务器时,Braintree的payment_method_nonse为空 [英] Braintree's payment_method_nonse is empty when trying to post data to server

查看:58
本文介绍了尝试将数据发布到服务器时,Braintree的payment_method_nonse为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置DROP-IN UI.我在后端使用Laravel 5.2(按照文档中的说明进行了设置:

I'm trying to set up DROP-IN UI. I'm using Laravel 5.2 on the backend ( followed the setup as explained in the docs:

[ https://laravel.com/docs/5.2/billing#braintree-配置]

我创建了一个 BraintreeController.php ,它以 json 的形式返回 client token .看起来像这样:

and i have created a BraintreeController.php and it returns the client token as json. It looks like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Braintree_ClientToken;
use App\Http\Requests;

class BraintreeController extends Controller
{
    public function token()
    {
        return response()->json(['token' => Braintree_ClientToken::generate() ], 200);
    }
} 

在这一点上,一切都很好.

At this point everything is good.

在客户端,我设置了Angularjs,这是我的 BillingController.js :

On client side i have Angularjs set up and here is my BillingController.js :

$http.get('/braintree/token').then(function(result){
    braintree.setup(result.data.token, "dropin", {
        container: "payment",
        paypal: {
             button: {
                 type: 'checkout'
             }
        }
     });
});

$('#customButton').on('click', function(event) {
      var map = {};
      $('#billForm').find('input').each(function() {
        map[$(this).attr("name")] = $(this).val();
      });
      console.log(map);

      $http.post('/order/checkout', map).then(function(result){
          console.log(result);
      });
  });

我有一个简单的html模板 billing.html ,其中包含如下形式:

And I have a simple html template billing.html containing the form like so:

<form id="billForm">
    <input type="text" name="fullname" id="fullname">
    <input type="text" name="address1" id="address1">
    <input type="text" name="city" id="city">
    <input type="text" name="postalcode" id="postalcode">

    <div id="payment"></div>
    <button id="customButton">Submit</button>
</form>

我遇到的问题是,在 BillingController.js 中,日志显示 payment_method_nonse 是空"或空字符串".有人知道我在做什么错吗?谢谢.

The problem I have is that in BillingController.js the logs are showing that the payment_method_nonse is "empty" or is "empty string". Does anyone have an idea what i am doing wrong? Thank you.

只需在已发布数据的接收端添加并向所有人显示该方法.基本上,我是在 store 方法内将表单数据发布到/order/checkout OrdersController.php 中.这是它的外观:

Just to add and show everyone the method on the receiving end of posted data. Basically i'm posting form data to /order/checkout to OrdersController.php inside the store method. And this is how it looks:

public function store(Request $request)
{
   $result = Braintree_Transaction::sale([
       'amount' => '10.00',
       'paymentMethodNonce' => $request->input('payment_method_nonce'),
       'options' => [
           'submitForSettlement' => True
       ]
   ]);

   dd($result);
}

这又吐回来了:

Error {#211
  +success: false
  #_attributes: array:8 [
    "errors" => ErrorCollection {#213
      -_errors: ValidationErrorCollection {#227
        -_errors: []
        -_nested: array:1 [
          "transaction" => ValidationErrorCollection {#214
            -_errors: array:1 [
              0 => Validation {#212
                -_attribute: "base"
                -_code: "91508"
                -_message: "Cannot determine payment method."
              }
            ]
            -_nested: array:1 [
              "creditCard" => ValidationErrorCollection {#216
                -_errors: array:1 [
                  0 => Validation {#217
                    -_attribute: "cvv"
                    -_code: "81706"
                    -_message: "CVV is required."
                  }
                ]
                -_nested: []
                #_collection: []
              }
            ]
            #_collection: []
          }
        ]
        #_collection: []
      }
    }
    "params" => array:1 [
      "transaction" => array:4 [
        "type" => "sale"
        "amount" => "10.00"
        "paymentMethodNonce" => null
        "options" => array:1 [
          "submitForSettlement" => "true"
        ]
      ]
    ]
    "message" => """
      Cannot determine payment method.\n
      CVV is required.
      """
    "creditCardVerification" => null
    "transaction" => null
    "subscription" => null
    "merchantAccount" => null
    "verification" => null
  ]
}

推荐答案

完整披露:我在Braintree工作.如有其他疑问,请随时联系我们的支持团队.

当单击表单的提交"按钮时,输入到插入"中的表单数据将变为随机.由于您的表单没有提交按钮,因此不会生成随机数.

Form data that gets entered into the Drop-in gets nonced when the form's submit button is clicked. Because your form does not have a submit button, no nonce is generated.

您可以使用 onPaymentMethodReceived回调提交表单数据.当您定义此回调时,将不会提交您的表单,这是您在上面指示的所需行为.

You can use the onPaymentMethodReceived callback to submit your form's data. When you define this callback, your form will not be submitted, which is the desired behavior you are indicating above.

以下是在定义您的 onPaymentMethodReceived 回调:

Here is an example of where to define your onPaymentMethodReceived callback:

braintree.setup('CLIENT-TOKEN-FROM-SERVER', 'dropin', {
  container: 'dropin-container',
  onPaymentMethodReceived: function (obj) {
      var map = {};
      $('#billForm').find('input').each(function() {
        map[$(this).attr("name")] = $(this).val();
      });
      map['payment_method_nonce'] = obj.nonce;
      console.log(map);

      $http.post('/order/checkout', map).then(function(result){
          console.log(result);
      });
  }
});

请记住,您的表单按钮将需要 type ='submit'属性来触发回调.

Keep in mind your form button will need the type='submit' attribute to trigger the callback.

如果您希望在定义 onPaymentMethodReceived 回调时触发表单提交,则可以遵循

If you wish to trigger your form submission while your onPaymentMethodReceived callback is defined, you can follow these instructions to do so.

这篇关于尝试将数据发布到服务器时,Braintree的payment_method_nonse为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆