Braintreegateway 未捕获的异常 [英] braintreegateway Uncaught exception

查看:32
本文介绍了Braintreegateway 未捕获的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 sandbox 模式下使用 braintreegateway 和以下代码.>

代码来自开发者网站

require_once 'braintree/lib/Braintree.php';Braintree_Configuration::environment('sandbox');Braintree_Configuration::merchantId('marchentid');Braintree_Configuration::publicKey('publickey');Braintree_Configuration::privateKey('privatekey');$result = Braintree_Transaction::sale(['金额' =>'100.00','orderId' =>'123','merchantAccountId' =>'marentid','paymentMethodNonce' =>'nonceFromTheClient','客户' =>['名字' =>'卡皮尔','姓氏' =>'史密斯','公司' =>'我的公司','电话' =>'1234567890','网站' =>'http://mywebsite.com','电子邮件' =>'我的电子邮件'],'计费' =>['名字' =>'卡皮尔','姓氏' =>'史密斯','公司' =>'我的公司','街道地址' =>'地址','扩展地址' =>'套房 403','地方' =>'印度','地区' =>'在','邮政编码' =>'邮政编码','countryCodeAlpha2' =>'在'],'运输' =>['名字' =>'卡皮尔','姓氏' =>'史密斯','公司' =>'我的公司','街道地址' =>'地址','扩展地址' =>'套房 403','地方' =>'印度','地区' =>'在','邮政编码' =>'邮政编码','countryCodeAlpha2' =>'在'],'选项' =>['submitForSettlement' =>真的]]);如果 ($result->success) {print_r("success!: ". $result->transaction->id);} else if ($result->transaction) {print_r("错误处理事务:");print_r("\n 代码:". $result->transaction->processorResponseCode);print_r("\n text: ". $result->transaction->processorResponseText);} 别的 {print_r("验证错误:\n");print_r($result->errors->deepAll());}

结果是

<块引用>

致命错误:未捕获的异常 'Braintree\Exception\Authorization' in/var/www/html/api/braintree/lib/Braintree/Util.php:61 堆栈跟踪:#0/var/www/html/api/braintree/lib/Braintree/Http.php(47):Braintree\Util::throwStatusCodeException(403) #1/var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(443):Braintree\Http->post('/merchants/dmmt...', Array) #2/var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(49):Braintree\TransactionGateway->_doCreate('/transactions', Array) #3/var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(268):Braintree\TransactionGateway->create(Array) #4/var/www/html/api/braintree/lib/Braintree/Transaction.php(494):Braintree\TransactionGateway->sale(Array) #5/var/www/html/api/payment.php(58): Braintree\Transaction::sale(Array)

6 {main} 在第 61 行的/var/www/html/api/braintree/lib/Braintree/Util.php 中抛出

这里出了什么问题?

解决方案

完全披露:我在 Braintree 工作.如果您有任何其他问题,请随时联系支持.

就像@mfahadi 提到的那样,一个潜在的问题可能是您的代码在 Braintree_Configuration 调用中没有您的密钥,但是您永远不应该将您的密钥发布到 StackOverflow,即使对于沙箱帐户也是如此.所以如果它是故意过滤的:做得好.如果没有,请查看获取客户端密钥的指南.>

第二个问题是你没有用实际的客户端随机数替换下面一行中的nonceFromTheClient":

'paymentMethodNonce' =>'nonceFromTheClient',

您可以在测试参考指南中找到测试随机数 .>

并将上面的行替换为下面的行以解决您的第二个问题:

'paymentMethodNonce' =>'假有效现时',

I am using braintreegateway with the following code in sandbox mode.

Code is used from developer site

require_once 'braintree/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('marchentid');
Braintree_Configuration::publicKey('publickey');
Braintree_Configuration::privateKey('privatekey');

$result = Braintree_Transaction::sale([
            'amount' => '100.00',
            'orderId' => '123',
            'merchantAccountId' => 'marchentid',
            'paymentMethodNonce' => 'nonceFromTheClient',
            'customer' => [
                'firstName' => 'kapil',
                'lastName' => 'Smith',
                'company' => 'mycompany',
                'phone' => '1234567890',
                'website' => 'http://mywebsite.com',
                'email' => 'myemail'
            ],
            'billing' => [
                'firstName' => 'kapil',
                'lastName' => 'Smith',
                'company' => 'mycompany',
                'streetAddress' => 'address',
                'extendedAddress' => 'Suite 403',
                'locality' => 'India',
                'region' => 'IN',
                'postalCode' => 'zipcode',
                'countryCodeAlpha2' => 'IN'
            ],
            'shipping' => [
                'firstName' => 'kapil',
                'lastName' => 'Smith',
                'company' => 'mycompany',
                'streetAddress' => 'address',
                'extendedAddress' => 'Suite 403',
                'locality' => 'India',
                'region' => 'IN',
                'postalCode' => 'zipcode',
                'countryCodeAlpha2' => 'IN'
            ],
            'options' => [
                'submitForSettlement' => true
            ]
        ]);

if ($result->success) {
    print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
    print_r("Error processing transaction:");
    print_r("\n  code: " . $result->transaction->processorResponseCode);
    print_r("\n  text: " . $result->transaction->processorResponseText);
} else {
    print_r("Validation errors: \n");
    print_r($result->errors->deepAll());
}

and the result is

Fatal error: Uncaught exception 'Braintree\Exception\Authorization' in /var/www/html/api/braintree/lib/Braintree/Util.php:61 Stack trace: #0 /var/www/html/api/braintree/lib/Braintree/Http.php(47): Braintree\Util::throwStatusCodeException(403) #1 /var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(443): Braintree\Http->post('/merchants/dmmt...', Array) #2 /var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(49): Braintree\TransactionGateway->_doCreate('/transactions', Array) #3 /var/www/html/api/braintree/lib/Braintree/TransactionGateway.php(268): Braintree\TransactionGateway->create(Array) #4 /var/www/html/api/braintree/lib/Braintree/Transaction.php(494): Braintree\TransactionGateway->sale(Array) #5 /var/www/html/api/payment.php(58): Braintree\Transaction::sale(Array)

6 {main} thrown in /var/www/html/api/braintree/lib/Braintree/Util.php on line 61

what's wrong here?

解决方案

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

Like @mfahadi mentioned, one potential problem may be that that your code doesn't have your keys in the Braintree_Configuration calls, but you should never post your keys to StackOverflow, even for sandbox accounts. So if it was intentionally filtered: well done. If not, check out the guide to get your client keys.

The second problem is you did not replace 'nonceFromTheClient' in the line below with an actual client nonce:

'paymentMethodNonce' => 'nonceFromTheClient',

You can find a test nonce in the testing reference guide.

And replace the line above with the line below to fix your second problem:

'paymentMethodNonce' => 'fake-valid-nonce',

这篇关于Braintreegateway 未捕获的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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