codeigniter mollie payment gateway integration issue

578 views Asked by At

I am trying to apply mollie payment gateway in codeIgniter using ref of https://github.com/mollie/mollie-api-php . But it is not working in it. I have already used this library in laravel which is working over there. when I tried to use in codeIgniter, it directly redirect me to redirectUrl and when I check in mollie payment dashboard, there is not payment. I can't understand what am I doing wrong. Can anyone help me? I have used this in composer.json and update the composer

"mollie/mollie-api-php": "^2.0"

In my controller file,

class Mollie_test extends CI_Controller {
     public function make_payment()
    {
        $mollie = new \Mollie\Api\MollieApiClient();
        $mollie->setApiKey("test_key");
        $payment = $mollie->payments->create([
            'amount' => [
                'currency' => 'EUR',
                'value' => '10.00'
            ],
            'description' => 'tesst',
            'redirectUrl' => redirect('mollie_test/success')
        ]);
    }

    public function success()
    {
        echo 'payment process completed';
    }
}
2

There are 2 answers

1
Sanjay Kumar On

This may help you

https://github.com/mollie/mollie-api-php

the $payment->getCheckoutUrl() object return to you checkout url , you need to redirect this url

0
marcogmonteiro On

Using the redirect will set a new header and actually redirect the user. In your case you need to use site_url.

So your code should look something like:

class Mollie_test extends CI_Controller {
     public function make_payment()
    {
        $mollie = new \Mollie\Api\MollieApiClient();
        $mollie->setApiKey("test_key");
        $payment = $mollie->payments->create([
            'amount' => [
                'currency' => 'EUR',
                'value' => '10.00'
            ],
            'description' => 'tesst',
            'redirectUrl' => site_url('mollie_test/success')
        ]);
    }

    public function success()
    {
        echo 'payment process completed';
    }
}

Many confuse site_url with base_url, base_url shouldn't be used in this case.

Site url will also add the index.php to your url in case you're using it. If you don't have index.php in your url you don't have to worry that will work too.

Base url should be used on assets where you never want the index.php present.

<img src="<?php echo base_url('foo/bar.jpg') ?>"