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

╄→尐↘猪︶ㄣ 提交于 2019-12-11 23:29:09

问题


I'm new to braintree.

I'm at first steps : https://github.com/braintree/braintree_php_guide/tree/master/1_getting_paid

in the index.php there is a part

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

It's not clear ; I replace the "YourClientSideEncryptionKey" by what ?

Thanks


回答1:


Finally I was able to create a first sandbox transaction ;)

Going AJAX instead to using index.php...

My code :

.JS Files (don't forget to include 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 file

<?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 ) );

?>


来源:https://stackoverflow.com/questions/36232558/braintree-what-do-i-paste-in-braintree-createyourclientsideencryptionkey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!