AbanteCart Community

AbanteCart Development => Extensions and Add-Ons => Payment Modules => Topic started by: seikan on June 11, 2014, 10:31:48 PM

Title: Validate my order before send it to payment gateway
Post by: seikan on June 11, 2014, 10:31:48 PM
I'm developing an extension to validate my order against fraudster and cancel the order before send it to payment gateway. Any clues which hooks to use?
Title: Re: Validate my order before send it to payment gateway
Post by: abolabo on June 12, 2014, 12:53:48 PM
I'm developing an extension to validate my order against fraudster and cancel the order before send it to payment gateway. Any clues which hooks to use?

you should to set order status "canceled" from hook. But you should to define in which place. i guess on checkout/success page...is it?

add function in your hook class something like this
Code: [Select]
public function onControllerPagesCheckoutSuccess_InitData() {

//ask remote server about payer
$result = .....

//update order status based on outcome
                $that->loadModel('checkout/order');
                if (!$result)) {
                        $message = 'Attention! Order #'.$order_id.' was flagged as fraudulent' . "\n\n" . $message;
                        $that->model_checkout_order->update($order_id, $order_status, $message, FALSE);
                        //send email to store owner
                        $mail = new AMail();
                        $mail->setSubject($message);
                        $mail->setTo($this->config->get('store_main_email'));
                        $mail->setText($message);
                        $mail->send();
                }
}
Title: Re: Validate my order before send it to payment gateway
Post by: seikan on June 19, 2014, 04:41:17 AM
Hi abolabo, thanks for your reply.

Unfortunately, I can't get it working. Can you point out what I done it wrongly?

I got my extension at /extensions/antifraudster/storefront/controller/responses/extension/antifraudster.php"

Quote
<?php
if (!defined('DIR_CORE')) {
   header('Location: static_pages/');
}

class ControllerResponsesExtensionAntiFraudster extends AController {

   public function main() {}

   public function onControllerPagesCheckoutSuccess_InitData() {
      $that->loadModel('checkout/order');

      $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

      if($order_info['payment_country'] == 'NG') {
         die('Fraud detected!');
      }
   }
}
?>
Title: Re: Validate my order before send it to payment gateway
Post by: abolabo on June 19, 2014, 05:25:17 AM
you should to add
Code: [Select]
$that = $this->baseObject;
and replace
Code: [Select]
$this->model_checkout_order->
to
Code: [Select]
$that->model_checkout_order->
Title: Re: Validate my order before send it to payment gateway
Post by: seikan on July 23, 2014, 05:09:30 AM
That's weird. I still cannot trigger the checking. Am I missing something?  :'(
Title: Re: Validate my order before send it to payment gateway
Post by: abolabo on July 23, 2014, 05:24:42 AM
Am I missing something?  :'(

yes. you missed $that = $this->baseObject;

$this->baseObject
is instance of controller class that you tried to hook. use it for calls of model etc