0
votes

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';
    }
}
1
Looking at the docs you probably want base_url('mollie_test/success') not redirect which as you might expect, immediately redirects.Jonnix
@Jonnix Really thanks alot for your solution. base_url worked. It was really a silly mistake by me. Worked now.disha

1 Answers

0
votes

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') ?>"