Recurring Payment Plan maintenance
Allows merchant to inquire, Update and Cancel RPP (Recurring Payment Plan) record.
Download Sample Code
Environment
Please refer Demo & Live Endpoint.
Prerequisite
Required necessary certificate key for the Payment Action Request and Response. Please refer Certificate Generation Guide.
Set account credentials
//Merchant's account information
$merchantID = "JT01"; //Get MerchantID when opening account with 2C2P
$secretKey = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
Set Inquiry Parameter
//Request Information
$version = "2.4";
$processType = "I" ;
$recurringUniqueID = "59576";
PaymentType | Description |
---|---|
I | Inquiry RPP information |
U | Update RPP information |
C | Cancel RPP |
Set payment action request information
//Construct signature string
$stringToHash = $version . $merchantID . $recurringUniqueID . $processType;
$hash = strtoupper(hash_hmac('sha256', $stringToHash ,$secretKey, false)); //Compute hash value
Construct payment action request message
//Construct request message
$xml = "<RecurringMaintenanceRequest>
<version>$version</version>
<merchantID>$merchantID</merchantID>
<recurringUniqueID>$recurringUniqueID</recurringUniqueID>
<processType>$processType</processType>
<hashValue>$hash</hashValue>
</RecurringMaintenanceRequest>";
include_once('pkcs7.php');
$pkcs7 = new pkcs7();
$payload = $pkcs7->encrypt($xml,"./keys/demo2.crt"); //Encrypt payload
Submit payment action request message
include_once('HTTP.php');
//Send request to 2C2P PGW and get back response
$http = new HTTP();
$response = $http->post("https://demo2.2c2p.com/2C2PFrontend/PaymentActionV2/PaymentAction.aspx","paymentRequest=".$payload);
Read payment response and Validate Hash
//Decrypt response message and display
$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");
echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>";
//Validate response Hash
$resXml=simplexml_load_string($response);
$res_version = $resXml->version;
$res_timeStamp = $resXml->timeStamp;
$res_respCode = $resXml->respCode;
$res_respReason = $resXml->respReason;
$res_recurringUniqueID = $resXml->recurringUniqueID;
$res_recurringStatus = $resXml->recurringStatus;
$res_invoicePrefix = $resXml->invoicePrefix;
$res_currency = $resXml->currency;
$res_amount = $resXml->amount;
$res_maskedCardNo = $resXml->maskedCardNo;
$res_allowAccumulate = $resXml->allowAccumulate;
$res_maxAccumulateAmount = $resXml->maxAccumulateAmount;
$res_recurringInterval = $resXml->recurringInterval;
$res_recurringCount = $resXml->recurringCount;
$res_currentCount = $resXml->currentCount;
$res_chargeNextDate = $resXml->chargeNextDate;
$res_chargeOnDate = $resXml->chargeOnDate;
//Compute response hash
$res_stringToHash = $res_version . $res_respCode . $res_recurringUniqueID . $res_recurringStatus . $res_invoicePrefix . $res_currency .
$res_amount . $res_maskedCardNo . $res_allowAccumulate . $res_maxAccumulateAmount . $res_recurringInterval . $res_recurringCount . $res_currentCount . $res_chargeNextDate . $res_chargeOnDate;
$res_responseHash = strtoupper(hash_hmac('sha256',$res_stringToHash,$secretKey, false)); //Compute hash value
echo "<br/>hash: ".$res_responseHash."<br/>";
if(strtolower($resXml->hashValue) == strtolower($res_responseHash)){ echo "valid response"; }
else{ echo "invalid response"; }
?>
Complete Code
<?php
//Merchant's account information
$merchantID = "JT01"; //Get MerchantID when opening account with 2C2P
$secretKey = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
//Request Information
$version = "2.4";
$processType = "I" ;
$recurringUniqueID = "59576";
$recurringStatus = "";
$amount = "";
$allowAccumulate = "";
$maxAccumulateAmount= "";
$recurringInterval = "";
$recurringCount = "";
$chargeNextDate="";
$chargeOnDate="";
//Construct signature string
$stringToHash = $version . $merchantID . $recurringUniqueID . $processType . $recurringStatus . $amount . $allowAccumulate . $maxAccumulateAmount . $recurringInterval . $recurringCount . $chargeNextDate . $chargeOnDate;
$hash = strtoupper(hash_hmac('sha256', $stringToHash ,$secretKey, false)); //Compute hash value
//Construct request message
$xml = "<RecurringMaintenanceRequest>
<version>$version</version>
<merchantID>$merchantID</merchantID>
<recurringUniqueID>$recurringUniqueID</recurringUniqueID>
<processType>$processType</processType>
<recurringStatus>$recurringStatus</recurringStatus>
<amount>$amount</amount>
<allowAccumulate>$allowAccumulate</allowAccumulate>
<maxAccumulateAmount>$maxAccumulateAmount</maxAccumulateAmount>
<recurringInterval>$recurringInterval</recurringInterval>
<recurringCount>$recurringCount</recurringCount>
<chargeNextDate>$chargeNextDate</chargeNextDate>
<chargeOnDate>$chargeOnDate</chargeOnDate>
<hashValue>$hash</hashValue>
</RecurringMaintenanceRequest>";
include_once('pkcs7.php');
$pkcs7 = new pkcs7();
$payload = $pkcs7->encrypt($xml,"./keys/demo2.crt"); //Encrypt payload
include_once('HTTP.php');
//Send request to 2C2P PGW and get back response
$http = new HTTP();
$response = $http->post("https://demo2.2c2p.com/2C2PFrontend/PaymentActionV2/PaymentAction.aspx","paymentRequest=".$payload);
//Decrypt response message and display
$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");
echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>";
//Validate response Hash
$resXml=simplexml_load_string($response);
$res_version = $resXml->version;
$res_timeStamp = $resXml->timeStamp;
$res_respCode = $resXml->respCode;
$res_respReason = $resXml->respReason;
$res_recurringUniqueID = $resXml->recurringUniqueID;
$res_recurringStatus = $resXml->recurringStatus;
$res_invoicePrefix = $resXml->invoicePrefix;
$res_currency = $resXml->currency;
$res_amount = $resXml->amount;
$res_maskedCardNo = $resXml->maskedCardNo;
$res_allowAccumulate = $resXml->allowAccumulate;
$res_maxAccumulateAmount = $resXml->maxAccumulateAmount;
$res_recurringInterval = $resXml->recurringInterval;
$res_recurringCount = $resXml->recurringCount;
$res_currentCount = $resXml->currentCount;
$res_chargeNextDate = $resXml->chargeNextDate;
$res_chargeOnDate = $resXml->chargeOnDate;
//Compute response hash
$res_stringToHash = $res_version . $res_respCode . $res_recurringUniqueID . $res_recurringStatus . $res_invoicePrefix . $res_currency .
$res_amount . $res_maskedCardNo . $res_allowAccumulate . $res_maxAccumulateAmount . $res_recurringInterval . $res_recurringCount . $res_currentCount . $res_chargeNextDate . $res_chargeOnDate;
$res_responseHash = strtoupper(hash_hmac('sha256',$res_stringToHash,$secretKey, false)); //Compute hash value
echo "<br/>hash: ".$res_responseHash."<br/>";
if(strtolower($resXml->hashValue) == strtolower($res_responseHash)){ echo "valid response"; }
else{ echo "invalid response"; }
?>
Updated almost 3 years ago