如何在Braintree API中获得paymentMethodNonce?

问题描述:

我正在laravel 5.4 当我尝试braintree文档提供的'fake_nonce'类型的字符串时,我的交易成功了。但是,当我试图得到paymentMethodNonce它总是给我错误像nonce没有找到。有时http错误!如果我尝试自己配置它! 在我的控制器功能,需要采取下述如何在Braintree API中获得paymentMethodNonce?

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')); 
} 
+0

请帮帮我! –

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

一看你使用了错误的随机数,这个随机数必须来自脱入UI,而不是在您的代码生成。

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

Please check this reference