====== PHP XML Subscriptions ====== The sample code below requires the **{{:developer:sample_codes:gateway_xml_php_api.zip|PHP XML API}}**.\\ **Settings file (%gatewaySampleFileName_account.inc):** ---- \\ **Subscription registration:** SetNewStoredSubscriptionValues($name, $description, $periodType, $length, $currency, $recurringAmount, $initialAmount, $type, $onUpdate, $onDelete); else if($recurringAmount != "" || $initialAmount != "") $subreg->SetSubscriptionAmounts($recurringAmount, $initialAmount); if($endDate != "") $subreg->SetEndDate($endDate); if($eDCCDecision != "") $subreg->EDCCDecision($eDCCDecision); $response = $subreg->ProcessRequestToGateway($secret,$testMode,$gateway); if($response->IsError())echo 'AN ERROR OCCURED, Subscription not created. Error details: ' . $response->ErrorString(); else { $expectedResponseHash = md5($terminalId.$response->MerchantReference().$response->DateTime().$secret); $merchantReference =$response->MerchantReference(); if($expectedResponseHash != $response->Hash()) { echo 'SUBSCRIPTION REGISTRATION FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to clarify if your card will be billed.'; if(isset($merchantReference))echo 'Please quote %Gateway Terminal ID: ' . $terminalId . ', and Subscription Merchant Reference: ' . $response->MerchantReference() . ' when mailling or calling.'; } else echo "Subscription successfully setup and setup payment processed succesfully."; } ?> ---- \\ **Subscription update:** SetSubName($name); if($description != "") $subupd->SetDescription($description); if($periodType != "") $subupd->SetPeriodType($periodType); if($length != "") $subupd->SetLength($length); if($recurringAmount != "") $subupd->SetRecurringAmount($recurringAmount); if($type != "") $subupd->SetSubType($type); if($startDate != "") $subupd->SetStartDate($startDate); if($endDate != "") $subupd->SetEndDate($endDate); if($eDCCDecision != "") $subupd->EDCCDecision($eDCCDecision); $response = $subupd->ProcessRequestToGateway($secret,$testMode,$gateway); if($response->IsError()) { echo 'AN ERROR OCCURED, Subscription not updated. Error details: ' . $response->ErrorString(); } else { $expectedResponseHash = md5($terminalId.$response->MerchantReference().$response->DateTime().$secret); if($expectedResponseHash != $response->Hash()) { echo 'SUBSCRIPTION UPDATE FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to clarify if your card will be billed.'; $merchantRef = $response->MerchantReference(); if(isset($merchantRef)) { echo 'Please quote %Gateway Terminal ID: ' . $terminalId . ', and Subscription Merchant Reference: ' . $response->MerchantReference() . ' when mailling or calling.'; } } else echo "Subscription successfully updated."; } ?> ---- \\ **Subscription deletion:** ProcessRequestToGateway($secret,$testMode,$gateway); if($response->IsError()) { echo 'AN ERROR OCCURED, Subscription not deleted. Error details: ' . $response->ErrorString(); } else { $expectedResponseHash = md5($terminalId.$response->MerchantReference().$response->DateTime().$secret); if($expectedResponseHash != $response->Hash()) { $merchantRef = $response->MerchantReference(); echo 'SUBSCRIPTION DELETION FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to clarify if your card will be billed.'; if(isset($merchantRef)) { echo 'Please quote %Gateway Terminal ID: ' . $terminalId . ', and Subscription Merchant Reference: ' . $merchantRef . ' when mailling or calling.'; } } else { echo "Subscription successfully deleted."; } } ?>