braintreegateway未被捕获的例外

时间:2016-06-24 13:19:36

标签: php api payment-gateway braintree

我在sandbox模式下使用braintreegateway以下代码。

代码用于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());
}

,结果是

  

致命错误:未捕获的异常' Braintree \ Exception \ Authorization'在   /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)

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

6 {main}

这里有什么问题?

2 个答案:

答案 0 :(得分:2)

您只是尝试运行示例代码,该代码具有您必须提供的信息的占位符。您必须添加该信息才能正常工作。

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

在上面的代码中,你必须从Braintree conrol面板中提供你的merchentid,publikey和privatekey。

'paymentMethodNonce' => 'nonceFromTheClient',

然后从客户端添加nounce。我建议阅读PHP服务器实现和托管字段的文档以获得详细的理解。

Hosted Fileds Docs

PHP Server Docs

*不添加评论,因为我没有足够的声誉。

答案 1 :(得分:1)

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

与@mfahadi一样,一个潜在的问题可能是您的代码在Braintree_Configuration调用中没有您的密钥,但您永远不应将密钥发布到StackOverflow,即使对于沙盒帐户也是如此。所以,如果它被故意过滤:干得好。如果没有,请查看get your client keys的指南。

第二个问题是你没有用实际的客户端现时替换下面一行中的'nonceFromTheClient':

'paymentMethodNonce' => 'nonceFromTheClient',

您可以找到测试随机数in the testing reference guide.

并用下面的行替换上面的行来解决第二个问题:

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