Jump to content

Need help to generate dynamic transaction reference


gingerol

Recommended Posts

Please I need help with a custom payment gateway module.

 

The payment gateway script takes as input the Receipt # which is used as the "Transaction ID".

 

The gateway has a response "Duplicate Transaction Reference", and it spits this whenever there is an attempt to repeat a failed transaction. This makes it impossible to re-try a failed transaction.

 

In WHMCS, for every order, the "Order ID" is unique and does not change.

The Receipt # is unique and does not change.

 

Both of the above are good for financial reasons and there is no problem with it.

 

The problem however is that the Gateway requires that each call to it should be considered a unique event that is associated with a unique ID. Irrespective of whether the payment attempt is successful or not, a unique code should be generated and used for each attempt.

 

In summary, this particular Payment Gateway wants the client to be able to repeat a payment attempt.

 

Now the question: How can I generate such a dynamic code for each transaction in WHMCS?

 

Please help me, because it's the very last stage in this gateway integration process, and this has stumped me for several months now.

 

I'm very grateful in advance for any light at all.

Link to comment
Share on other sites

It seems that one way to achieve this is to append a Timestamp to the transaction reference number before submitting to payment gateway.

 

Since Timestamp changes each time, this would make each transref number unique.

 

Please can anyone tell me how to do this?

Link to comment
Share on other sites

Here is the code area for the first call to the gateway:

 

//************************************************

 

//Call this function in the onclick event of your button or however else

 

// you want to open the Plupay window (e.g. frames, ajax etc...)

 

// passing the amount and the transaction reference youre using..

 

// NOTE: Amount should be in minor denomination i.e. 5000 should be sent as 500000 (Five hundred thousand)

 

// NOTE: Transaction ID (trnxID) should have been saved in your db already before calling the dialog box.

 

// so that you can use it to query for transaction status later. ( if youre using the web service option)

 

//*********************************

 

function doPayment()

 

{

 

 

 

var trnxId = "'.$params['invoiceid'].'";

 

var cadpid = "'.$params['cadpid'].'";

 

var mertId = "'.$params['merchantid'].'";

 

var amount = "'.($params['amount']*100).'";

 

 

var url = "https://Plupay.plupay.com/Plupay_pilot/purchase.aspx";

 

var fullUrl = url + "?CADPID="+cadpid+"&MERTID="+mertId+"&TXNREF="+trnxId+"&AMT="+amount+"&TRANTYPE=00";

 

 

 

showWindow(fullUrl); //function in Plupay_PopUp_Caller.txt

 

}

 

</script>

 

<form name="form" method="post" action="'.$params['systemurl'].'/modules/gateways/callback/Plupay.php">

 

<input type="hidden" name="trnxId" value="'.$params['invoiceid'].'" />

 

<input type="button" name="Submit" onClick="javascript:doPayment();" value="PAY NOW">

 

</form>

 

';

 

return $code;

 

}

 

I am very poor at scripts but can follow instructions of cut and paste. If you wouldn't mind tell me precisely where and how to place the time code here. Thanks!

 

Also, I forsee a problem:

 

Transaction ID is needed by WHMCS to be same as given to the order in question. Otherwise, it would not be able to automatically mark an invoice as paid, because it would not recognize it when it returns.

 

Therefore, although we want to pass a unique ID to the payment gateway, we desire this only at the "exit" point (as represented by the above code), but on it's return, we wish to retain a transaction id that WHMCS gave out initially.

 

Many thanks for your time.

Link to comment
Share on other sites

The ID that whmcs gave for the order is an ORDER ID and does not have to be the same as the TRANSACTION ID. They are two different things, one is the ID for the ORDER and the other is the ID for the TRANSACTION.

 

 

Going by what you have posted use it like this

replace this

var trnxId = "'.$params['invoiceid'].'";

with this

var trnxId = time();

then parse back trnxId as the TRANSACTION ID

Link to comment
Share on other sites

I changed it thus, but now the payment popup window does not work.

 

//************************************************

//Call this function in the onclick event of your button or however else

// you want to open the Plupay window (e.g. frames, ajax etc...)

// passing the amount and the transaction reference youre using..

// NOTE: Amount should be in minor denomination i.e. 5000 should be sent as 500000 (Five hundred thousand)

// NOTE: Transaction ID (trnxID) should have been saved in your db already before calling the dialog box.

// so that you can use it to query for transaction status later. ( if youre using the web service option)

//*********************************

function doPayment()

{



var trnxId = time();

var cadpid = "'.$params['cadpid'].'";

var mertId = "'.$params['merchantid'].'";

var amount = "'.($params['amount']*100).'";


var url = "https://Plupay.plupay.com/Plupay_pilot/purchase.aspx";

var fullUrl = url + "?CADPID="+cadpid+"&MERTID="+mertId+"&TXNREF="+trnxId+"&AMT="+amount+"&TRANTYPE=00";



showWindow(fullUrl); //function in Plupay_PopUp_Caller.txt

}

</script>

<form name="form" method="post" action="'.$params['systemurl'].'/modules/gateways/callback/Plupay.php">

<input type="hidden" name="trnxId" value="'.$params['invoiceid'].'" />

<input type="button" name="Submit" onClick="javascript:doPayment();" value="PAY NOW">

</form>

';

return $code;

}

Link to comment
Share on other sites

Yes... I just realised you arn't using php. It's java.

 

My supreme ignorance shines forth!

 

You're absolutely right, it's Java.

 

I should never question gurus :)

 

Please can anyone help me through this java 'roadblock'?

Link to comment
Share on other sites

I update this in case someone can help me further.

 

I have been able to make the transaction ID dynamic with the following javascript codes:

 

var minutes = currentTime.getSeconds()

var timestamp = (minutes)*73

 

and

concatenating transaction id and timestamp thus:

 

"&TXNREF="+trnxId+timestamp+

 

So, the transaction goes through successfully.

 

There is now a new challenge. After payment is made and a call returns to the Callback script, I need that the Transaction ID be presented WITHOUT the timestamp, in order that WHMCS recognizes it and links it to the payment in question.

 

How can I do this? Is there any opposite of concatenation, this time in php?

 

then

Link to comment
Share on other sites

This is solved. Admin please close.

 

Should anybody else have this issue, this is how I solved it:

 

http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-charac

 

Basically:

 

$txnreff = $_REQUEST["txnref"];

$txnref = preg_replace('/\s+?(\S+)?$/', '', substr($txnreff, 0, 7));

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

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

Guest
Reply to this topic...

×   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