Php 使用定期付款授权.net CIM
我有一个网站,用户做分期付款(定期付款)。由于我不想在我的数据库中存储用户的信用卡/帐户信息,我使用了PCI compliance,我使用了AUTHORIZE.NET Cim 我遵循这一点,第一次一切都很好Php 使用定期付款授权.net CIM,php,authorize.net,recurring-billing,authorize.net-cim,Php,Authorize.net,Recurring Billing,Authorize.net Cim,我有一个网站,用户做分期付款(定期付款)。由于我不想在我的数据库中存储用户的信用卡/帐户信息,我使用了PCI compliance,我使用了AUTHORIZE.NET Cim 我遵循这一点,第一次一切都很好 createCustomerProfile createCustomerPaymentProfile createCustomerProfileTransaction 第一次交易成功,我得到了所有的回应: responsecode, transactionid, authid. 但是如何使
responsecode, transactionid, authid.
但是如何使用客户id
或客户付款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';
}
require('AuthnetCIM.class.php');//类,该类具有所有函数
$cim=new AuthNetCim(“*******”、“*******”、“apitest”);
//步骤1:创建客户档案
//创建唯一的假电子邮件地址、说明和客户ID
//$email_address='user'。时间()@域名",;
$email_address=$row['custemail1'];
$description='每月会员编号'。md5(uniqid(rand(),true));
$customer_id=substr(md5(uniqid(rand(),true)),16,16);
$cardcvv=$_POST['cardcvv'];
$cardno=$\u POST['cardno1']。$\u POST['cardno2']。$\u POST['cardno3']。$\u POST['cardno4'];
$phone=$\u POST['billphone\u 1'].-'$_张贴['billphone_2'].-'$_张贴['billphone_3'];
$cim->setParameter($email',$email\u地址);
$cim->setParameter('description',$description);
$cim->setParameter('merchantCustomerId',$customer\u id);
$cim->createCustomerProfile();
//获取从请求返回的配置文件ID
如果($cim->isSuccessful())
{
$profile_id=$cim->getProfileID();
$query=“更新订单集cust\u proid='$profile\u id'其中orderid='$orderid'限制1”;
$result=mysql\u query($query)或die(“发生了以下错误:
”.mysql\u error());
$responseNode=$cim->getResponseText();
$authorization=$cim->getResponse();
}
//步骤2:创建付款配置文件
$cim->setParameter('customerProfileId',$profile\u id);
$cim->setParameter('billToFirstName',$\u POST['cardname']);
$cim->setParameter('billToAddress',$\u 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',$\u POST['cardexpyy'].-'.$\u POST['cardexpmm']);//(YYYY-MM)
$cim->createCustomerPaymentProfile();
//获取从请求返回的付款配置文件ID
如果($cim->isSuccessful())
{
$payment_profile_id=$cim->getPaymentProfileId();
$query2=“更新订单集客户付款项目='$payment\U proid'$payment\U proid',其中订单id='$orderid'限制1”;
$result2=mysql\u query($query2)或die(“发生了以下错误:
”.mysql\u error());
$responseNode=$cim->getResponse();
$authorization=$cim->getResponse();
}
elseif($cim->isError())
{
$responseNode=$cim->getResponse();
$authorization=$cim->getResponse();
$approvalstatus='Deced';
}
其他的
{
//echo“无效卡,未生成支付专业id”;
$responsenote='无效卡';
$authorization='拒绝';
$approvalstatus='Deced';
}
//步骤4:处理事务
$purchase_amount='5';
如果($row['cust\u pay\u proid']='')
{
$payment_profile_id=$cim->getPaymentProfileId();
}
否则{
$payment_profile_id=$row['cust_pay_proid'];
}
//如果未创建getPaymentProfileId,即无效卡/或付款问题
如果($payment\u profile\u id!='')
{
//处理交易
$cim->setParameter('amount',$purchase\u amount);
$cim->setParameter('customerProfileId',$profile\u id);
$cim->setParameter('customerPaymentProfileId',$payment\u profile\u id);
$cim->setParameter('cardCode',$cardcvv);
$cim->setParameter('recurringBilling',true);//用于定期计费
$cim->createCustomerProfileTransaction('profileTransAuthCapture');
//获取从请求返回的付款配置文件ID
如果($cim->isSuccessful())
{
$auth_code=$cim->getAuthCode();
$query3=“更新订单集验证码='$auth\u code',其中orderid='$orderid'限制1”;
$result3=mysql\u query($query3)或die(“发生了以下错误:
”.mysql\u error());
$responseNode=$cim->getResponse();
$authorization=$cim->getResponse();
$transactionid=$cim->getTransactionID();
$approvalstatus='Approved';
}
elseif($cim->isError())
{
$responseNode=$cim->getResponse();
$authorization=$cim->getResponse();
$approvalstatus='Deced';
}
其他的
{
$responsenote='无效的配置文件/付款id';
$authorization='拒绝';
$approvalstatus='Deced';
}
}
其他的
{
$responseNode=$cim->getResponse();
$authorization=$cim->getResponse();
$approvalstatus='Deced';
}
您不能通过CIM创建或管理订阅,因为它只是创建和管理支付帐户的一种手段。重复计费标志仅表示您创建的此付款帐户将用于重复计费。它实际上并没有设置订阅
因此,如果您想将其用作定期计费系统,您需要编写自己的定期计费引擎来实际安排和处理付款。Authorize.Net将在即将发布的版本中添加此功能。@rhldr他们这样做会让很多人感到高兴。@johncode,这是如何实现的?因为,我没有存储