gingerol Posted July 10, 2009 Share Posted July 10, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 11, 2009 Author Share Posted July 11, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted July 11, 2009 Share Posted July 11, 2009 You can use the current time $uniqueid = time(); 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 11, 2009 Author Share Posted July 11, 2009 You can use the current time $uniqueid = time(); Thank you very much! I will try this now 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 11, 2009 Author Share Posted July 11, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted July 11, 2009 Share Posted July 11, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 11, 2009 Author Share Posted July 11, 2009 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; } 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted July 11, 2009 Share Posted July 11, 2009 Yes... I just realised you arn't using php. It's java. 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 11, 2009 Author Share Posted July 11, 2009 It's php. In the code snippets I earlier posted, I simply omitted the "php" headers 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 13, 2009 Author Share Posted July 13, 2009 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'? 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 15, 2009 Author Share Posted July 15, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
gingerol Posted July 15, 2009 Author Share Posted July 15, 2009 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)); 0 Quote Link to comment Share on other sites More sharing options...
benostik Posted October 15, 2009 Share Posted October 15, 2009 Gingerol Please can you help me with similar case but it's asp i need to integrate to my payment gateway please if you can mail me ben4mi@hotmail.com thnx in advance 0 Quote Link to comment Share on other sites More sharing options...
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.