Авторизуйтесь .net CIM с регулярным платежом

У меня есть сайт, где пользователи делают платежи в рассрочка (регулярные платежи). И поскольку я не хочу хранить информацию о кредитной карте пользователя / учетной записи в моей базе данных, я использовал Соответствие PCI для которого я использовал АВТОРИЗАЦИЯ .NET CIM.

Я следил за этим библиотека, где все отлично работает в первый раз, т.е.

  1. createCustomerProfile
  2. createCustomerPaymentProfile
  3. 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';
}

-1

Решение

Вы не можете создавать или управлять подписками через CIM, поскольку это только средство для создания и управления платежными учетными записями. Только флаг повторяющегося выставления счета является пометкой о том, что созданный вами платежный аккаунт будет использоваться для повторного выставления счетов. Это на самом деле не настроить подписку.

Поэтому, если вы хотите использовать это как систему регулярных платежей, вам нужно написать свой собственный механизм регулярных платежей, чтобы фактически планировать и обрабатывать платежи.

0

Другие решения

Других решений пока нет …