BrainTree我应在Braintree.create("YourClientSideEncryptionKey")中粘贴什么? [英] BrainTree what do I paste in Braintree.create("YourClientSideEncryptionKey");

查看:77
本文介绍了BrainTree我应在Braintree.create("YourClientSideEncryptionKey")中粘贴什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是braintree的新手.

I'm new to braintree.

我正在第一步: https://github.com/braintree/braintree_php_guide/tree/master/1_getting_paid

在index.php中有一部分

in the index.php there is a part

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

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

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

谢谢

推荐答案

最后,我能够创建第一个沙箱事务;)

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

使用AJAX代替使用index.php ...

Going AJAX instead to using index.php...

我的代码:

.JS文件(别忘了包含jquery.js ...)

.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文件

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

?>

这篇关于BrainTree我应在Braintree.create("YourClientSideEncryptionKey")中粘贴什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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