support

Create custome payment module for Hosted Payment Page

Started by vishwanath, October 04, 2016, 02:21:35 PM

Previous topic - Next topic

vishwanath

Hi All,

I am creating one custom payment module for a payment gateway. I have created a hidden form with all required parameter to submit to payment gateway. Form is submitting properly, user is doing payment with there card, after payment gateway return to url that i need to pass as SUCCESSURL and i am setting this as checkout/success as URL. In this url gateway add TRANASCTIONID and REFERENCEID that i need to save and if no TRANASCTIONID found then i need to make order fail of retirn to payment page.

My problem is how order is being created in admin with incomplete status. So how i make it in processing status sot that user can see there order in account. Also how i save TRANASCTIONID and REFERENCEID ???


My controller code is as follow :
class ControllerResponsesExtensionCustomHpp extends AController {

    public function main() {
        $fields = array();

        $this->load->model('checkout/order');
        $this->loadLanguage('custom_hpp/custom_hpp');


        $cancel_url = $this->request->get['rt'] != 'checkout/guest_step_3' ? $this->html->getSecureURL('checkout/payment') : $this->html->getSecureURL('checkout/guest_step_2');

        $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
        $products = '';
        foreach ($this->cart->getProducts() as $product) {
            $products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
        }

        $this->load->library('encryption');
        $encryption = new AEncryption($this->config->get('encryption_key'));

        $hpp_url = $this->config->get('custom_hpp_paymentURL');
        $fields = array(
            'auth' => $this->config->get('custom_hpp_authID'),
            'acid' => $this->config->get('custom_hpp_accountID'),
            'successurl' => $this->html->getSecureURL('checkout/success').'&',
            'product' => $products,
            'amount' => $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE),
            'currency' => 'USD',//$order_info['currency'],
            'Reference' => $this->session->data['order_id'],
            'FirstName' => $order_info['payment_firstname'],
            'LastName' => $order_info['payment_lastname'],
            'Address' => $order_info['payment_address_1'].''.$order_info['payment_address_2'],
            'City' => $order_info['email'],
            'State' => $order_info['payment_zone'],
            'Country' => $order_info['payment_iso_code_2'],
            'PostCode' => substr($order_info['payment_postcode'], 0, 9),
            'Phone' => $order_info['telephone'],
            'Email' => $order_info['email'],
        );

        $form = new AForm();
        $form->setForm(array('form_name' => 'checkout'));
        $data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form',
            'name' => 'checkout',
            'action' => $hpp_url));

        foreach ($fields as $key => $value) {
            $data['form'][$key] = $form->getFieldHtml(array('type' => 'hidden',
                'name' => $key,
                'value' => $value
            ));
        }
            if ($this->request->get['rt'] == 'checkout/guest_step_3'){
         $back = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true);
      } else{
         $back = $this->html->getSecureURL('checkout/payment', '&mode=edit', true);
      }
        $data['form']['back'] = $form->getFieldHtml(array('type' => 'button',
            'name' => 'back',
            'text' => $this->language->get('button_back'),
            'style' => 'button',
            'href' => $back));
        $data['form']['submit'] = $form->getFieldHtml(array('type' => 'submit',
            'name' => $this->language->get('button_confirm')
        ));
        $this->view->batchAssign($data);
      
        $this->processTemplate('responses/custom_hpp.tpl');
       
    }
   }

abolabo

Usually payment gateways send request server-server. For ex in Paypal case it calls IPN (notification).
To process this request you should to create new method callback that will change order status and write some payment data into database (column "payment_data" of table "orders"). Just serialize your data and use as you want later.

You can look into file https://github.com/abantecart/abantecart-src/blob/master/public_html/extensions/default_pp_standart/storefront/controller/responses/extension/default_pp_standart.php for details
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

vishwanath

Yes, i have also seen some default payment method is callback function order status save and change. But in my case payment gateway do not communicate server to server, it just add transaction id and reference id in success URL as follow /index.php?rt=checkout/success&?transactionID=1475497122587705444&referenceID=26.

And i have to get transactionID and referenceID from URL and then process order and status.

How can i handle this problem.

eCommerce Core

I think you need to store transactionID and referenceID in the order table and use them as needed.

You can use ac_order_data table or add new field to ac_orders
"If you're in the luckiest one per cent of humanity, you owe it to the rest of humanity to think about the other 99 per cent."
― Warren Buffett

vishwanath

I have solved this issue with creating one function callback and in this function we have handle the transaction and order process.

like as :

public function callback() {
        $transactionID = $this->request->get['?transactionID'];
        $referenceID = $this->request->get['referenceID'];
       
        $this->load->model('checkout/order');
        $order_info = $this->model_checkout_order->getOrder($referenceID);
        if (!$order_info) {
            return null;
        }

        $this->model_checkout_order->confirm($referenceID, $this->config->get('custom_hpp_order_status_id'));
        if($transactionID !="" && $referenceID !=""){
        $this->redirect($this->html->getSecureURL('checkout/success'));
        } else {
            $this->redirect($this->html->getSecureURL('checkout/payment'));
        }
    }

Forum Rules Code of conduct
AbanteCart.com 2010 -