简体   繁体   English

braintree授权验证并存储信用卡php

[英]braintree Authorization Verify and store credit card php

I build eCommerce in PHP and this page should authorize the credit card. 我使用PHP构建电子商务,并且此页面应授权信用卡。 If it is valid, I will store it on the customer page. 如果有效,我会将其存储在客户页面上。

I wrote this code for it, but I still did not get how to authorize the card not to charge it. 我为此编写了代码,但仍然没有获得如何授权卡不收取费用的方法。

the code 编码

<?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>";
}

}
?>

Full disclosure: I work at Braintree. 全面披露:我在Braintree工作。 If you have any further questions, feel free to contact support . 如果您还有其他疑问,请随时与支持小组联系。

The easiest fix for what you are trying to do is to pass the storeInVault parameter into your Transaction::sale() call. 对于您要执行的操作,最简单的解决方法是将storeInVault参数传递到您的Transaction::sale()调用中。 This saves the customer information into your vault as long as the payment is successful. 只要付款成功,这会将客户信息保存到您的保管库中。

Additionally, you can create a customer by integrating our Customer::create() call into your code with the verifyCard parameter. 另外,您可以通过将我们的Customer::create()调用与verifyCard参数集成到您的代码中来创建客户。

I recommend following the official guide at https://developers.braintreepayments.com/guides/transactions/php 我建议遵循https://developers.braintreepayments.com/guides/transactions/php上的官方指南

The way you gather credit card data (such as number or expiry date) is not compliant with the requirements Braintree imposes and may lead to suspension or termination of your account. 您收集信用卡数据(例如号码或有效期限)的方式不符合Braintree的要求,并可能导致您的帐户被暂停或终止。

Credit card data shall not be available to your server. 信用卡数据对您的服务器不可用。 You should rather use Drop-in UI or Hosted fields . 您应该使用Drop-in UIHosted字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM