首页 > 解决方案 > PHP Braintree 网关 API

问题描述

请耐心等待,我正在尝试为我的 wordpress 预订系统创建一个 Braintree 网关,但不了解 php。我已经从 Braintree 下载了 php 库文件,并使用下面的代码实现了 api 连接区域和创建事务。此代码是从另一个网关获取和调整的!这是一个很好的使用方法吗?这行得通吗?

我的代码

                        $config = new Braintree\Configuration();
                        $config->environment($api_keys_merchant_id);
                        $config->merchantId(trim($api_keys_merchant_id));
                        $config->publicKey(trim($api_keys_public_key));
                        $config->privateKey(trim($api_keys_private_key));
                        $gateway = new Braintree\Gateway($config);

                        // Create transaction
                        $result = $gateway->transaction()->sale([
                        'amount' => $price,
                        'paymentMethodNonce' => 'nonceFromTheClient',
                              '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());
                     } ```

标签: phpwordpressintegrationpayment-gatewaybraintree

解决方案


$gateway = new Braintree_Gateway([
    'environment' => $api_keys_merchant_id,
    'merchantId' => trim($api_keys_merchant_id),
    'publicKey' => 'use_your_public_key',
    'privateKey' => 'use_your_private_key'
]);

$result = $gateway->transaction()->sale([
                        'amount' => $price,
                        'paymentMethodNonce' => 'nonceFromTheClient',
                        '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());
                     }

推荐阅读