我有一个网站,用户可以在其中分期付款(定期付款)。而且由于我不想将用户的信用卡/帐户信息存储在我的数据库中,因此我使用了PCI 合规性,为此我使用了AUTHORIZE .NET Cim。
我跟着这个图书馆,第一次一切正常,即
- 创建客户资料
- createCustomerPaymentProfile
- createCustomerProfileTransaction
第一次交易有效,我得到了所有的回应:
responsecode, transactionid, authid.
但是我如何管理经常性付款customer id
或customer payment id.
我什至设置了:$cim->setParameter('recurringBilling',true);
这是完整的代码:
require('AuthnetCIM.class.php'); // class that has all the functions
$cim = new AuthNetCim('*******', '**********', 'apitest');
// Step 1: create Customer Profile
// Create unique fake email address, description, and customer ID
// $email_address = 'user' . time() . '@domain.com';
$email_address = $row['custemail1'];
$description = 'Monthly Membership No. ' . md5(uniqid(rand(), true));
$customer_id = substr(md5(uniqid(rand(), true)), 16, 16);
$cardcvv = $_POST['cardcvv'];
$cardno = $_POST['cardno1'].$_POST['cardno2'].$_POST['cardno3'].$_POST['cardno4'];
$phone = $_POST['billphone_1'] . '-' . $_POST['billphone_2'] . '-' . $_POST['billphone_3'];
$cim->setParameter('email', $email_address);
$cim->setParameter('description', $description);
$cim->setParameter('merchantCustomerId', $customer_id);
$cim->createCustomerProfile();
// Get the profile ID returned from the request
if ($cim->isSuccessful())
{
$profile_id = $cim->getProfileID();
$query = "UPDATE orders SET cust_proid='$profile_id' where orderid='$orderid' LIMIT 1";
$result = mysql_query($query) or die("The following error has occurred:<br>" . mysql_error());
$responsenote = $cim->getResponseText();
$authorization = $cim->getResponse();
}
// Step 2: create Payment Profile
$cim->setParameter('customerProfileId', $profile_id);
$cim->setParameter('billToFirstName', $_POST['cardname']);
$cim->setParameter('billToAddress', $_POST['billaddress1']);
$cim->setParameter('billToCity', $_POST['billcity']);
$cim->setParameter('billToState', $_POST['billstate']);
$cim->setParameter('billToZip', $_POST['billzip']);
$cim->setParameter('billToCountry', 'USA');
$cim->setParameter('billToPhoneNumber', $phone);
$cim->setParameter('cardNumber', str_replace('-', '', $cardno));
$cim->setParameter('expirationDate', $_POST['cardexpyy'].'-'.$_POST['cardexpmm']); // (YYYY-MM)
$cim->createCustomerPaymentProfile();
// Get the payment profile ID returned from the request
if ($cim->isSuccessful())
{
$payment_profile_id = $cim->getPaymentProfileId();
$query2 = "UPDATE orders SET cust_pay_proid='$payment_profile_id' where orderid='$orderid' LIMIT 1";
$result2 = mysql_query($query2) or die("The following error has occurred:<br>" . mysql_error());
$responsenote = $cim->getResponse();
$authorization = $cim->getResponse();
}
elseif($cim->isError())
{
$responsenote = $cim->getResponse();
$authorization = $cim->getResponse();
$approvalstatus='Declined';
}
else
{
// echo 'Invalid Card, payment pro id not generated';
$responsenote = 'Invalid Card';
$authorization = 'Declined';
$approvalstatus='Declined';
}
// Step 4: Process a transaction
$purchase_amount = '5';
if($row['cust_pay_proid'] == '')
{
$payment_profile_id = $cim->getPaymentProfileId();
}
else {
$payment_profile_id = $row['cust_pay_proid'];
}
// if getPaymentProfileId not created i.e invalid card/ or issue with payment
if($payment_profile_id != '')
{
// Process the transaction
$cim->setParameter('amount', $purchase_amount);
$cim->setParameter('customerProfileId', $profile_id);
$cim->setParameter('customerPaymentProfileId', $payment_profile_id);
$cim->setParameter('cardCode', $cardcvv);
$cim->setParameter('recurringBilling',true); // for recurring
$cim->createCustomerProfileTransaction('profileTransAuthCapture');
// Get the payment profile ID returned from the request
if ($cim->isSuccessful())
{
$auth_code = $cim->getAuthCode();
$query3 = "UPDATE orders SET auth_code='$auth_code' where orderid='$orderid' LIMIT 1";
$result3 = mysql_query($query3) or die("The following error has occurred:<br>" . mysql_error());
$responsenote = $cim->getResponse();
$authorization = $cim->getResponse();
$transactionid=$cim->getTransactionID();
$approvalstatus='Approved';
}
elseif($cim->isError())
{
$responsenote = $cim->getResponse();
$authorization = $cim->getResponse();
$approvalstatus='Declined';
}
else
{
$responsenote = 'Invalid Profile/payment id';
$authorization = 'Declined';
$approvalstatus='Declined';
}
}
else
{
$responsenote = $cim->getResponse();
$authorization = $cim->getResponse();
$approvalstatus='Declined';
}