2

To start off, please forgive me if i sound like an idiot as i have limited coding capabilities. Having said that, i've been having trouble setting up a custom payment gateway.

The payment gateway requires that i specify a redirection URL for each transaction status: success, fail and cancelled.

The issue is that i have no idea what URL to specify for successful transactions so that the order is successfully processed and recorded into the database.

I've basically just adapted from one of the existing merchant files and came up with the following:

class Merchant_enets extends Merchant_driver
{
    const PROCESS_URL = 'https://www.enets.sg/enets2/enps.do';

    public function default_settings()
    {
        return array(
            'user_id' => '',
            'test_mode' => FALSE,
        );
    }

    public function purchase()
    {
        $request = $this->_build_purchase();
        $this->post_redirect($this->_process_url(), $request);
    }

    private function _build_purchase()
    {
        $request = array();
        $request['mid'] = $this->setting('user_id');
        $request['amount'] = $this->param('amount');
        $request['txnRef'] = $this->param('transaction_id');
        $request['umapiType'] = 'lite';
        return $request;
    }

    public function purchase_return()
    {
        $result = $this->CI->input->get_post('result');
        if (empty($result))
        {
            return new Merchant_response(Merchant_response::FAILED, lang('merchant_invalid_response'));
        }

        // validate response
        $request = new SimpleXMLElement('');
        $request->Response = $result;

        $response = $this->post_request(self::PROCESS_URL, $request->asXML());
        $xml = simplexml_load_string($response);

        if ((string)$xml->Success == '1')
        {
            if ((string)$xml->status == 'succ')
            {
                return new Merchant_response(Merchant_response::AUTHORIZED, (string)$xml->ResponseText, (string)$xml->txnRef);
            }
        }

        return new Merchant_response(Merchant_response::FAILED, (string)$xml->ResponseText, (string)$xml->txnRef);
    }   

    protected function _process_url()
    {
        return $this->setting('test_mode') ? self::PROCESS_URL_TEST : self::PROCESS_URL;
    }
}

Please help!

I'm using EE 2.7 and Store 1.6.5

2

You need to specify the return and cancel URLs on a per-request basis. In Store v1 you can get these URLs with:

$this->param('return_url'); // use this for success and error
$this->param('cancel_url'); // use this for cancel

You can see how this is done in other gateways such as PayPal Express:

https://github.com/expressodev/ci-merchant/blob/master/libraries/merchant/merchant_paypal_express.php

  • Hi Adrian, thanks for the reply! The payment gateway doesn't accept the URLs as a parameter posted from the form. They are asking for an absolute URL, something like www.mystore.com/products/success. So i have no idea which URL to provide them – Trevor Ghiam Mar 12 '14 at 7:19
  • You should double check that, because I've implemented dozens of gateways before and only one did not allow a custom return URL. If not, do they allow you to specify custom GET/POST parameters? In that case you could hack it to return the correct ACT and H parameters required by Store. – Adrian Macneil Mar 12 '14 at 7:28
  • Thanks again Adrian. Yeah the gateway accepts POST parameters so how do i go about hacking it to return the correct ACT and H parameters? (I'm not quite sure what these are as well) Do you have a reference source? – Trevor Ghiam Mar 12 '14 at 8:04
  • I mean can you ask the gateway to send custom POST parameters back to your site for the return URL? If you look at $this->param('return_url') you will see ACT and H parameters. EE requires the ACT parameter to load the correct action, and Store uses the H parameter to lookup the transaction. You can send these to your index.php file as either GET or POST parameters and they should work fine. – Adrian Macneil Mar 12 '14 at 21:48
  • Thanks Adrian! Took me a while to understand what you were saying but i figured it out with the help of another post you replied to (expressionengine.stackexchange.com/questions/10737/…). Thanks again for taking the time out to answer our questions! – Trevor Ghiam Mar 23 '14 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.