如何在Braintree API中获得paymentMethodNonce?

时间:2017-08-23 20:18:44

标签: laravel-5 laravel-5.4 braintree-sandbox

我在laravel 5.4工作 当我尝试“假冒”时,我的交易是成功的。 braintree docs提供的字符串类型。但是当我试图获得paymentMethodNonce时,它总是给我一些错误,如找不到nonce。有时http错误!!!如果我尝试自己配置它! 看一下我的控制器功能

public function addOrder(Request $request){
  $customer = Braintree_Customer::create([
    'firstName' => $request->guest_name,
    'email' => $request->guest_email,
    'phone' => $request->guest_phone
  ]);
  $customer->success;
  $customer->customer->id;
  $find = Braintree_Customer::find($customer->customer->id);
  $nonceFromTheClient = Braintree_PaymentMethodNonce::find($find);
  $result = Braintree_Transaction::sale([
    'amount' => $request->subtotal,
    'paymentMethodNonce' => $nonceFromTheClient,
    'options' => [
      'submitForSettlement' => True
    ]
  ]);
  if ($result->success) {
      $settledTransaction = $result->transaction;
  } else {
      print_r($result->errors);
  }
  Cart::destroy();
  return view('guest/track', compact('result'));
}

1 个答案:

答案 0 :(得分:0)

$nonceFromTheClient = Braintree_PaymentMethodNonce::find($find);

你使用了错误的随机数,这个随机数必须来自DropIn ui,而不是在你的代码上生成。

请检查JS SDK中提供的onPaymentMethodReceived()方法。

Please check this reference