BrainTree 我要在 Braintree.create("YourClientSideEncryptionKey"); 中粘贴什么?

BrainTree what do I paste in Braintree.create("YourClientSideEncryptionKey");

我是 braintree 的新手。

我刚开始:https://github.com/braintree/braintree_php_guide/tree/master/1_getting_paid

在index.php中有一部分

 var braintree = Braintree.create("YourClientSideEncryptionKey");

不清楚;我将 "YourClientSideEncryptionKey" 替换为什么?

谢谢

我终于能够创建第一个沙盒交易 ;)

AJAX 改为使用 index.php...

我的代码:

.JS 文件(不要忘记包含 jquery.js...)

function braintreeTest ( cardNumber, CVV, ExpirMonth, ExpirYear , phpVariable_message_DivID ) { 

    $.ajax ({
        type: 'POST', 
        url: '___url_of_braintree_php_file___',
        dataType: 'json',
        data:'cardNumber='+encodeURIComponent (cardNumber)+
             '&cardCVV='+encodeURIComponent(CVV)+
             '&cardExpirationMonth='+encodeURIComponent(ExpirMonth)+
             '&cardExpirationYear='+encodeURIComponent(ExpirYear),
        cache: false,
        success: function(data){
            $('#'+phpVariable_message_DivID).html(data.phpVariable_message1);
        },
        error: function(request, status, error){
            console.log ( 'request.responseText --> ' + request.responseText + ' status --> ' + status + ' error --> ' + error );
        }
    });

}

PHP 文件

<?php 

function clean ( $toClean ){
    $toClean = trim ( $toClean ) ; 
    $toClean = addslashes ( $toClean ) ; 
    return $toClean;
}

$phpVariable_message1 = '' ;
$cardNumber__from_post = '' ; 
$cardCVV__from_post = '' ; 
$cardExpirationMonth__from_post = '' ; 
$cardExpirationYear__from_post = '' ; 

if ( isset($_REQUEST['cardNumber']) ) { $cardNumber__from_post = clean ( $_REQUEST['cardNumber'] ) ; } // 4111111111111111 
if ( isset($_REQUEST['cardCVV']) ) { $cardCVV__from_post = clean ( $_REQUEST['cardCVV'] ) ; } // 555 
if ( isset($_REQUEST['cardExpirationMonth']) ) { $cardExpirationMonth__from_post = clean ( $_REQUEST['cardExpirationMonth'] ) ; } // 02 
if ( isset($_REQUEST['cardExpirationYear']) ) { $cardExpirationYear__from_post = clean ( $_REQUEST['cardExpirationYear'] ) ; } // 17 

require_once '__PATH_TO_/braintree_php/lib/Braintree.php';

Braintree_Configuration::environment("sandbox");
Braintree_Configuration::merchantId('use_your_merchant_id');
Braintree_Configuration::publicKey('use_your_public_key');
Braintree_Configuration::privateKey('use_your_private_key');

$result = Braintree_Transaction::sale(array(
    "amount" => "11.11",
    "creditCard" => array(
        "number" => $cardNumber__from_post,
        "cvv" => $cardCVV__from_post,
        "expirationMonth" => $cardExpirationMonth__from_post,
        "expirationYear" => $cardExpirationYear__from_post
    ),
    "options" => array(
        "submitForSettlement" => true
    )
));

if ($result->success) {
    $phpVariable_message1 .= "Success! Transaction ID: " . $result->transaction->id;
} else if ($result->transaction) {
    $phpVariable_message1 .= "Error: " . $result->message;
    $phpVariable_message1 .= "<br/>";
    $phpVariable_message1 .= "Code: " . $result->transaction->processorResponseCode;
} else {
    $phpVariable_message1 .= "Validation errors:<br/>";
    foreach (($result->errors->deepAll()) as $error) {
        $phpVariable_message1 .= "- " . $error->message . "<br/>";
    }
}
}

echo json_encode(array("phpVariable_message1" => $phpVariable_message1 ) );

?>