-1

ユーザーが分割払い(定期支払い)を行うウェブサイトを持っています。また、ユーザーのクレジットカード/アカウント情報をデータベースに保存したくないため、AUTHORIZE .NET Cimを使用したPCI コンプライアンスを使用しました。

私はこのライブラリをフォローしました。ここでは、すべてが初めて正常に動作します。

  1. createCustomerProfile
  2. createCustomerPaymentProfile
  3. createCustomerProfileTransaction

初めてトランザクションが機能し、すべての応答が得られます:

responsecode, transactionid, authid.

しかし、またはを使用して定期的な支払いを管理するにはどうすればよいですcustomer idcustomer 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';
  }
4

1 に答える 1