簡體   English   中英

braintree授權驗證並存儲信用卡php

[英]braintree Authorization Verify and store credit card php

我使用PHP構建電子商務,並且此頁面應授權信用卡。 如果有效,我會將其存儲在客戶頁面上。

我為此編寫了代碼,但仍然沒有獲得如何授權卡不收取費用的方法。

編碼

<?php
if($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST['card_number']) && !empty($_POST['card_name']) && !empty($_POST['expiry_month']) && !empty($_POST['expiry_year']) && !empty($_POST['cvv']))
{
$card_number=str_replace("+","",$_POST['card_number']);  
$card_name=$_POST['card_number'];
$expiry_month=$_POST['expiry_month'];
$expiry_year=$_POST['expiry_year'];
$cvv=$_POST['cvv'];
$expirationDate=$expiry_month.'/'.$expiry_year;

require_once 'braintree/Braintree.php';
Braintree_Configuration::environment('production'); /* this is sandbox or production */
Braintree_Configuration::merchantId('id');
Braintree_Configuration::publicKey('public');
Braintree_Configuration::privateKey('secrit ');

$result = Braintree_Transaction::sale(array(
'amount' => 0,
'creditCard' => array(
'number' => $card_number,
'cardholderName' => $card_name,
'expirationDate' => $expirationDate,
'cvv' => $cvv
)
));

//echo "<pre>";
echo $result->message;
die;
if ($result->success) 
{
    //print_r("success!: " . $result->transaction->id);
    if($result->transaction->id)
    {
        $braintreeCode=$result->transaction->id;
        echo "<h2>Your payment successfully done ".$braintreeCode."</h2>";
    }
}else if ($result->transaction){
        echo "<pre>";
        print_r($result->transaction);
        //echo '{"OrderStatus": [{"status":"2"}]}';

}else{

    echo "<h2>Your payment is not completed</h2>";
}

}
?>

全面披露:我在Braintree工作。 如果您還有其他疑問,請隨時與支持小組聯系。

對於您要執行的操作,最簡單的解決方法是將storeInVault參數傳遞到您的Transaction::sale()調用中。 只要付款成功,這會將客戶信息保存到您的保管庫中。

另外,您可以通過將我們的Customer::create()調用與verifyCard參數集成到您的代碼中來創建客戶。

我建議遵循https://developers.braintreepayments.com/guides/transactions/php上的官方指南

您收集信用卡數據(例如號碼或有效期限)的方式不符合Braintree的要求,並可能導致您的帳戶被暫停或終止。

信用卡數據對您的服務器不可用。 您應該使用Drop-in UIHosted字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM