Post payment process for custom payment method
I'm developing a custom payment method, so far I managed to send the form to the gateway and everything works fine. When I conclude the payment I get a link to come back to the shop(contao) I've set the link to be :
Code:
$this->Environment->base.$this->addToUrl('step=complete').'?uid='.$objOrder->uniqid
But I dont know how should I get all the data that I got back so I can finish my order and get the payment confirmation in contao. Also when I link back first I get an error, Invalid request token!. I imagine that I'm not getting the right token when linking back to contao, and thus I can't get any data from the form that was sent back to contao.
Here is my Payment class:
Code:
class PaymentTelecash extends IsotopePayment{
protected $arrLanguages = array('en_us'=>'en_US', 'en_uk'=>'en_UK', 'fr'=>'fr_FR', 'de'=>'de_DE', 'it_IT'=>6);
protected $arrCurrencies = array('AUD'=>036, 'CAD'=>124, 'DKK'=>208, 'HKD'=>344, 'ISK'=>352, 'JPY'=>392, 'MXN'=>484, 'NZD'=>554, 'NOK'=>578, 'SGD'=>702, 'ZAR'=>710, 'SEK'=>752, 'CHF'=>756, 'THB'=>764, 'GBP'=>826, 'USD'=>840, 'TRY'=>949, 'EUR'=>978, 'PLN'=>985);
public function __get($strKey){
switch( $strKey ){
case 'available':
if (!array_key_exists($this->Isotope->Config->currency, $this->arrCurrencies)){
return false;
}
return parent::__get($strKey);
default:
return parent::__get($strKey);
}
}
public function statusOptions(){
return array('pending', 'processing', 'complete', 'on_hold');
}
protected function getDateTime(){
$dateTime = date("Y:m:d-H:i:s");
return $dateTime;
}
protected function createHash($chargetotal, $currency) {
$stringToHash = $this->telecash_storeID . $this->getDateTime() . $chargetotal . $currency . $this->telecash_secretkey;
$ascii = bin2hex($stringToHash);
return sha1($ascii);
}
public function processPayment(){
$objOrder = $this->Database->prepare("SELECT * FROM tl_iso_orders WHERE cart_id=?")->limit(1)->executeUncached($this->Isotope->Cart->id);
$intTotal = $this->Isotope->Cart->grandTotal * 100;
// Check basic order data
if ($this->Input->get('orderid') == $objOrder->id && $this->Input->get('cur') == $this->arrCurrencies[$this->Isotope->Config->currency] && $this->Input->get('amount') == $intTotal){
return true;
}
global $objPage;
}
public function checkoutForm(){
global $objPage;
$objOrder = $this->Database->prepare("SELECT * FROM tl_iso_orders WHERE cart_id=?")->limit(1)->executeUncached($this->Isotope->Cart->id);
$intTotal = $this->Isotope->Cart->grandTotal;
return '
<h2>' . $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0] . '</h2>
<p class="message">' . $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1] . '</p>
<form method="post" id="telecash_payment" action="https://test.ipg-online.com/connect/gateway/processing">
<input type="hidden" name="txntype" value="sale">
<input type="hidden" name="mode" value="fullpay"/>
<input type="hidden" name="language" value="'.(array_key_exists($GLOBALS['TL_LANGUAGE'], $this->arrLanguages) ? $this->arrLanguages[$GLOBALS['TL_LANGUAGE']] : 'de_DE').'"/>
<input type="hidden" name="timezone" value="CET"/>
<input type="hidden" name="txndatetime" value="'.$this->getDateTime().'"/>
<input type="hidden" name="hash" value="'.$this->createHash($intTotal,$this->arrCurrencies[$this->Isotope->Config->currency]).'"/>
<input type="hidden" name="storename" value="'.$this->telecash_storeID.'"/>
<input type="hidden" name="chargetotal" value="'.$intTotal.'"/>
<input type="hidden" name="currency" value="'.$this->arrCurrencies[$this->Isotope->Config->currency].'"/>
<input type="hidden" name="responseSuccessURL" value="'.$this->Environment->base.$this->addToUrl('step=complete').'?uid='.$objOrder->uniqid.'"/>
<input type="hidden" name="notify_url" value="' . $this->Environment->base . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id . '"/>
<input type="submit" class="process_submit" value="'.$GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2].'">
</form>
<script type="text/javascript">
<![CDATA[//><!--
window.addEvent( \'domready\' , function() {
$(\'telecash_payment\').submit();
});
//--><!]]>
</script>';
}
}
So is there any idea what am I doing wrong, or not doing?
Thanks!
Re: Post payment process for custom payment method
The return values will depend on the Payment Gateway. Most return either in POST or GET. The Cart will still be in session upon return, so it's not necessary to have the uid to locate the order. I haven't tried this on a 2.1x installation, so I don't know about the token error...
Re: Post payment process for custom payment method
Re the request token error - I think you'll need this in your form (Contao 2.10.x)
Code:
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '" />
Re: Post payment process for custom payment method
My main problem so far is that my payment gateway sends the POST data to the same url it is redirecting to. Where redirect url should be something like
Code:
$this->Environment->base.$this->addToUrl('step=complete').'?uid='.$objOrder->uniqid
but the post data should be sent to
Code:
$this->Environment->base . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id
because Contao doesn't allow POST from outside location.
And in the form for response url I have only one hidden field
Code:
<input type="hidden" name="responseFailURL">
or the success one
Code:
<input type="hidden" name="responseSuccessURL
Now I've tried to link payment gateway directly to postsale.php script and then use the proccessPostSale() method to redirect to the checkout, but when I try to access the postsale script I get this redirect error:
[attachment=0:1wmymh85]Screen shot 2012-01-21 at 4.25.47 PM.png[/attachment:1wmymh85]
Is there any official support for contao development that could put some light on this situation?
Re: Post payment process for custom payment method
What is your gateway sending back? Does it include everything you sent it (including the Request Token??)
Your redirect URL should not be the complete step, it should be the same step you are on, and it should be able to send back the same Request Token that you posted to it. That way you can check for incoming POST data in your checkout form and return false if it checks out, thus taking you to the complete step.
If your gateway can't send back the token I don't see how you would be able to do this in 2.1x without disabling the request tokens.