<?php
if(!defined("WHMCS")){die("This file cannot be accessed directly");}function gatewaymodule_MetaData(){return array('DisplayName'=>'Sample Payment Gateway Module','APIVersion'=>'1.1',// Use API Version 1.1'DisableLocalCreditCardInput'=>true,'TokenisedStorage'=>false,);}function gatewaymodule_config(){return array(// the friendly display name for a payment gateway should be// defined here for backwards compatibility'FriendlyName'=> array('Type'=>'System','Value'=>'Sample Third Party Payment Gateway Module',),// a text field type allows for single line text input'accountID'=> array('FriendlyName'=>'Account ID','Type'=>'text','Size'=>'25','Default'=>'','Description'=>'Enter your account ID here',),// a password field type allows for masked text input'secretKey'=> array('FriendlyName'=>'Secret Key','Type'=>'password','Size'=>'25','Default'=>'','Description'=>'Enter secret key here',),// the yesno field type displays a single checkbox option'testMode'=> array('FriendlyName'=>'Test Mode','Type'=>'yesno','Description'=>'Tick to enable test mode',),// the dropdown field type renders a select menu of options'dropdownField'=> array('FriendlyName'=>'Dropdown Field','Type'=>'dropdown','Options'=> array('option1'=>'Display Value 1','option2'=>'Second Option','option3'=>'Another Option',),'Description'=>'Choose one',),// the radio field type displays a series of radio button options'radioField'=> array('FriendlyName'=>'Radio Field','Type'=>'radio','Options'=>'First Option,Second Option,Third Option','Description'=>'Choose your option!',),// the textarea field type allows for multi-line text input'textareaField'=> array('FriendlyName'=>'Textarea Field','Type'=>'textarea','Rows'=>'3','Cols'=>'60','Description'=>'Freeform multi-line text input field',),);}function gatewaymodule_link($params){// Invoice Parameters
$invoiceId = $params['invoiceid'];
$amount = $params['amount'];
$currencyCode = $params['currency'];
$transaction ="TEST". rand(100000,999999);
$ReturnUrl ="https://mydomain/modules/gateways/callback/gatewaymodule.php";
$secretKey ="SECRET";
$hash=hash('sha256', $invoiceId.$amount.$currencyCode.$transaction.$normalReturnUrl.$secretKey);
$htmlOutput ="
<form method='post' action='https://payment-gateway.com/'>
<input type='hidden' name='amount' value='$amount'>
<input type='hidden' name='ReturnUrl' value='$ReturnUrl'>
<input type='hidden' name='transaction' value='$transaction'>
<input type='hidden' name='invoiceid' value='$invoiceId'>
<input type='hidden' name='currency' value='$currencyCode'>
<input type='hidden' name='hash' value='$seal'>
<input type='submit' value='Pay'><br>
</form>
";return $htmlOutput;}function gatewaymodule_refund($params){// Gateway Configuration Parameters
$accountId = $params['accountID'];
$secretKey = $params['secretKey'];
$testMode = $params['testMode'];
$dropdownField = $params['dropdownField'];
$radioField = $params['radioField'];
$textareaField = $params['textareaField'];// Transaction Parameters
$transactionIdToRefund = $params['transid'];
$refundAmount = $params['amount'];
$currencyCode = $params['currency'];// Client Parameters
$firstname = $params['clientdetails']['firstname'];
$lastname = $params['clientdetails']['lastname'];
$email = $params['clientdetails']['email'];
$address1 = $params['clientdetails']['address1'];
$address2 = $params['clientdetails']['address2'];
$city = $params['clientdetails']['city'];
$state = $params['clientdetails']['state'];
$postcode = $params['clientdetails']['postcode'];
$country = $params['clientdetails']['country'];
$phone = $params['clientdetails']['phonenumber'];// System Parameters
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];// perform API call to initiate refund and interpret resultreturn array(// 'success' if successful, otherwise 'declined', 'error' for failure'status'=>'success',// Data to be recorded in the gateway log - can be a string or array'rawdata'=> $responseData,// Unique Transaction ID for the refund transaction'transid'=> $refundTransactionId,// Optional fee amount for the fee value refunded'fees'=> $feeAmount,);}function gatewaymodule_cancelSubscription($params){// Gateway Configuration Parameters
$accountId = $params['accountID'];
$secretKey = $params['secretKey'];
$testMode = $params['testMode'];
$dropdownField = $params['dropdownField'];
$radioField = $params['radioField'];
$textareaField = $params['textareaField'];// Subscription Parameters
$subscriptionIdToCancel = $params['subscriptionID'];// System Parameters
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];// perform API call to cancel subscription and interpret resultreturn array(// 'success' if successful, any other value for failure'status'=>'success',// Data to be recorded in the gateway log - can be a string or array'rawdata'=> $responseData,);}
Question
Executable
I created a minimalist gateway module :
and the callback :
When I try a payment and get redirected to callback/gatewaymodule.php
is triggered twice. How can I avoid that ?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.