braintree支付网关一步步与PHP集成

时间:2015-03-30 12:00:02

标签: php braintree

我是braintree与PHP集成的新手,我在互联网上搜索过我无法在我的网站上找到正确的实现。

任何人都可以帮助我一步一步地为我的网站整合braintree,包括创建沙箱。

提前致谢。

1 个答案:

答案 0 :(得分:1)

<?php
require_once 'lib/Braintree.php';
Braintree_Configuration::environment('sandbox'); /* this is sandbox or production */
Braintree_Configuration::merchantId('Your ID');
Braintree_Configuration::publicKey('Your Public Key');
Braintree_Configuration::privateKey('Your Private key');

$result = Braintree_Transaction::sale(array(
    'amount' => $amount,
    'orderId' => 'Your Order ID' , /* It should be unique */
    'creditCard' => array(
        'number' =>  '41111111111111111',
        'expirationDate' => '07/16',
        'cardholderName' => 'NAME',
    )
));

if ($result->success) {
    /* your success condition */
}else if ($result->transaction) {
    $msg .= "Error processing transaction:<br>" ;
    $msg .="\n  code: " . $result->transaction->processorResponseCode ;
    $msg .="\n  text: " . $result->transaction->processorResponseText ;
    echo $msg ; 
}