Jump to content

[SOLVED] Custom Payment Module: redirect to order confirmation


roymilder

Recommended Posts

Hi,

 

I have a question regarding a custom Payment Module I've adapted due to incompability with Prestashop 1.5.

 

Payment provider Docdata has a Prestashop plugin available for PS < 1.5. This module isn't working with >1.5. so I've adapted it. The module is almost working and I can accept payments.

 

However there is some strange behaviour.

If I pay as a guest everything goes well. After the transaction is finished and the Payment Provider is redirecting me back to the website I see the order confirmation page and the payment is finalized.

 

But when I pay as a known customer (I've logged myself in) the module is not redirecting me to the order confirmation page, but to the order history page. The payment is fine though, everything is OK. But I see the order-history page instead of the order confirmation page.

 

The validation part of the payment module is generating the redirectlink with this code:

Tools::redirectLink(__PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id .'&id_module='. $this->id .'&id_order=' . $id_order . '&key=' . $customer->secure_key);

 

I believe it's calling the controllers/OrderConfirmationController.php. If I take a look at this code I see that it's generating a different redirectlink for a guest:

 

if (Cart::isGuestCartByCartId($this->id_cart))

{

$is_guest = true;

$redirectLink = 'index.php?controller=guest-tracking';

}

else

$redirectLink = 'index.php?controller=history';

 

And I see that it is generating a redirectlink with the history option if the customer is logged in.

 

A bit futher in the code it's calling the order-confirmation.tpl. This is the same for guests and customers:

 

$this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');

 

But in some strange way it's doing something different for customers and it's redirecting them to the order-history.

 

What's going wrong or am I doing something wrong myself?

 

Please advise, thanks!

 

Roy M.

Edited by roymilder (see edit history)
Link to comment
Share on other sites

With many thanks to scorpionsworld I worked out a solution.

 

There was a problem with validateOrder. It seems that the column payment has to be filled with the exact name as the module has. I filled it with a different name.

 

$this->validateOrder(intval($cart->id), _PS_OS_PAYMENT_, $total, $this->displayName, $message, array('transaction_id' => $cookie->pcid), false, false, $customer->secure_key);

 

After changing it everything worked like a charm!

 

Credits go to scorpionsworld.

Link to comment
Share on other sites

  • 5 weeks later...

Roy,

 

How did you manage to get this module to work? Have Docdata as well, installed it, but don't see it popping-up in the payment methods in the shopping cart. If it's not working I have to move to another PSP with valid plugins for > 1.5. So this is my last chance.

Link to comment
Share on other sites

Robbie,

 

If you don't see it popping up as a payment method then you probably haven't installed it correctly. The download as it is available on the Docdata site pop up right away. However it doesn't work as it comes in the current PS version. I have adjusted it quite heavy to work.

 

I could help you out a bit if you need, however you need some php and ps knowledge to get it working.

 

Let me know.

Link to comment
Share on other sites

Thanks Roy! We're client there for many years, but I don't gives you a good feeling if they haven't an up-to-date plugin, only one that works for 1.4 and it seems that they don't want to work on it either.

 

First want to test in with payment profile "standard". Have installed an configured it.

 

Get these errors when selecting Docdata in checkout:

 

TripleDeal Payment Service Module: error: payment_profile_invalid

TripleDeal Payment Service Module: no payment cluster id was received.TripleDeal Payment Service Module: error: msg_incorrect_price

TripleDeal Payment Service Module: no payment cluster id was received.

Link to comment
Share on other sites

Ok, I will do my best.

 

The module folder is located in modules/docdatapayments

You'll have to change several files. Hopefully I've commented all my changes in the files, otherwise it will be a bit of trial and error (but it should work, I have it working on my site).

 

I suggest to take a look at all files that are in this folder starting with docdatapayments.php. Learn which classes are used for which part of the payment process.

 

In docdatapayments.php I've adjusted the validatePayment function.

On line 203 I've added this code:

$message = $report[2].": ".$report[3];

 

Be aware, these variables depends on other changes which we will make later.

 

After line 208 I've changed $this->displayName in $report[2]

So the new code should look like this:

 


if ($type == 'success' && $report[0] == 'Y' && ($report[1] == 'Y' || $report[1] == 'N'))
  $this->validateOrder(intval($cart->id), _PS_OS_PAYMENT_, $total, $this->displayName, $message, array('transaction_id' => $cookie->pcid), false, false, $customer->secure_key);
else if ($type != 'canceled' && $report[0] == 'N')
  $this->validateOrder(intval($cart->id), _PS_OS_ERROR_, $total, $this->displayName, $this->l('Payment closed expired or closed cancelled'));
else if ($type != 'canceled')
  $this->validateOrder(intval($cart->id), _PS_OS_ERROR_, $total, $this->displayName, $this->l('Payment not paid'));

 

I complete removed the line that starts with : $smarty->assign() and replaced it with:

 

	$id_order = Order::getOrderByCartId(intval($cart->id));
Tools::redirectLink(__PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id .'&id_module='. $this->id .'&id_order=' . $id_order . '&key=' . $customer->secure_key);

 }

 

You'll have to change tripledeal.php:

 

Replace line 109: $data .= utf8_encode('&report_type=txt_simple2'); with: $data .= utf8_encode('&report_type=xml_all');

 

(this will give you an extended report type which is useful in the backoffice)

 

Then replace:

 


$results = trim($results);

//print_r($results);
// Verwacht stringresultaat 'YN' of 'YY' of 'NN' of 'NY' maar blijkt aangevuld met spaties
// Buggie code!

$results = preg_split("/\s/", $results);
print_r($results);
exit();
$considered_safe = substr($results[2],0,1);
$transaction_closed = substr($results[2],1,1);
// oorsprinkelijke code
// $considered_safe = $results[4];
// $transaction_closed = $results[10];

*/

 

with:

 


/*
 *NIEUWE CODE
 */
 $considered_safe = $results->status[0]->meta_considered_safe;
 if ($considered_safe == "true")
 {
	 $considered_safe = "Y";
 } else {
	 $considered_safe = "N";
 }

 $transaction_closed = $results->payments->payment->attributes()->state;
 if ($transaction_closed == "paid")
 {
  	  $transaction_closed = "Y";
 } else {
  	  $transaction_closed = "N";
 }

 

and add:

 

 $payment_method = $results->payments->payment->attributes()->{'method-readable'};
 $message = $results->payments->payment->reason;
return (array($considered_safe, $transaction_closed, $payment_method, $message));

 

Also duplicate the function postSend and name it postSend2

 

This function should contain this code:

 

  private function postSend2($url, $data)
 {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url."?".$data);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
curl_close($handle);

$xml = new SimpleXmlElement($response);
if($xml) {
	return $xml;
} else {
	return false;
}
 }

 

At last you should change the orderconfirmation controller.

In my last reply I explained this:

 

There was a problem with validateOrder. It seems that the column payment has to be filled with the exact name as the module has. I filled it with a different name.

 

$this->validateOrder(intval($cart->id), _PS_OS_PAYMENT_, $total, $this->displayName, $message, array('transaction_id' => $cookie->pcid), false, false, $customer->secure_key);

 

After changing it everything worked like a charm!

 

Hope this helps.

 

Good luck.

Link to comment
Share on other sites

Hi robbie,

 

It's not that easy: we've made several changes to the files for our own custom environment. I can't put the whole files on the site for download: sorry.

 

However if you take a litte bit more time in trial and error it should work, we have it working as well.

 

Perhaps you can place the error codes or something?

 

One last suggestion, in tripledeal.php after:

 

    $results = $this->postSend2(TRIPLEDEALPS_URL, $data);

 

place this code:

 

   /*
   *DEBUG
   */
   echo $results->status[0]->payment_cluster_process;
   echo "<br />";
   echo $results->payments->payment->attributes()->id;
   echo "<br />";
   var_dump($results);
   exit();

 

This should give you some extra debugging information.

 

Hope it helps.

 

Roy

Link to comment
Share on other sites

  • 3 years later...
  • 3 years later...
On 2/5/2013 at 11:38 AM, roymilder said:

 


	$id_order = Order::getOrderByCartId(intval($cart->id));
Tools::redirectLink(__PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id .'&id_module='. $this->id .'&id_order=' . $id_order . '&key=' . $customer->secure_key);

 }

Pls, dont use hardcodes =)


$Linkobj = new Link(); //if no link object declared before
Tools::redirect($Linkobj->getPageLink('order-confirmation') . '?id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...