Jump to content
  • 0

Payment gateway log twice


Executable

Question

I created a minimalist gateway module : 

 

<?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 result

    return 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 result

    return 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,
    );
}


and the callback

 


 

<?php
require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/../../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../../includes/invoicefunctions.php';

$gatewayModuleName = basename(__FILE__, '.php');

$gatewayParams = getGatewayVariables($gatewayModuleName);

if (!$gatewayParams['type']) {
    die("Module Not Activated");
}

$secretKey = 'SECRET';
           
$invoiceId = $_POST["invoiceid"];
$transactionId = $_POST["transaction"];
$paymentAmount = $_POST["amount"];
$hash = $_POST["hash"];

$invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['name']);
checkCbTransID($transactionId);

logTransaction($gatewayParams['name'], $_POST, "TEST");

if ($success) {
    addInvoicePayment(
        $invoiceId,
        $transactionId,
        $paymentAmount,
        0,
        $gatewayModuleName
    );
}

When I try a payment and get redirected to callback/gatewaymodule.php 

logTransaction($gatewayParams['name'], $_POST, "TEST");

is triggered twice. How can I avoid that ?

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Problem is you are using the callback url as a return url.

Callback is something that should be used by a 3rd party entity, like paypal or stripe, to acknowledge the payment (or the error)
So user is NOT supposed to user the callback url at all

Return URL should be the invoice itself, not the callback URL

Link to comment
Share on other sites

  • 0
Just now, Executable said:

How the third party will know where to redirect ?

Because you are telling when you post the information to them.
The same way you are sending them information about the order, amount, signature, etc
It's just one of the hidden fields you submit.

That's the way most 3rd party work (and so does Paypal, for example)

Anyway, to be sure you have to follow the documentation given by the payment provider

Link to comment
Share on other sites

  • 0

I dont' even know what payment provider you are trying to contact, so I'm afraid I can't help.

Anyway, there are 2 options:

  • Provider is not sending the callback request
  • Your callback code is not working

You can easily check in your web server log if there is a request from your provider to the callback url.
If you find none, then check the provieder's log or ask the provider.

Also, are you sure you are sending the right information to them?

Link to comment
Share on other sites

  • 0

You still need to check if mercanet is sending data to your url (réponses automatique) AND if your webserver is receiving it.

So check the logs from mercanet's admin panel AND then check your web erver los to confirm that the callback is being transmitted before moving to the next step

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated