A simple CodeIgniter 3.x library for accepting payments using Paystack https://paystack.com
-
Download the
Paystack_lib.php
file and put it inside yourapplication/libraries
folder. -
Get the Public and Secret keys (both test and live) from your Paystack dashboard. Click Here.
-
There are two method you can use to store your API Keys, the configuration file method (simpler) OR the database storage method (highly recommended).
Config File Method:
If you choose to use the configuration file method, download this fileconfig/paystack.php
, and paste your API keys there:$config['test_public_key'] = 'PASTE_YOUR_TEST_PUBLIC_KEY_HERE'; $config['test_secret_key'] = 'PASTE_YOUR_TEST_SECRET_KEY_HERE'; $config['live_public_key'] = 'PASTE_YOUR_LIVE_PUBLIC_KEY_HERE'; $config['live_secret_key'] = 'PASTE_YOUR_LIVE_SECRET_KEY_HERE';
Make sure that the file is saved in your
application/config/
folder.Database Storage (recommended):
Depending on how your database is structured, you can save the API keys in a table, and then fetch the details from that table. -
In your controller that holds the page where you want the payment to be triggered, load the paystack library like so:
$this->load->library('paystack_lib');
Then add the email address, amount and callback url in the fields that will be sent to paystack's api, like so:
$this->paystack_lib->add_field('email', 'THE CUSTOMER EMAIL ADDRESS'); $this->paystack_lib->add_field('amount', 'TOTAL AMOUNT TO BE PAID'); // This amount MUST be multiplied by 100. $this->paystack_lib->add_field('callback_url', 'YOUR RETURN URL');
Then, you can render the paystack form like so:
$this->paystack_lib->ps_auto_form();
-
When the payment process is triggered, you should see a page like so:
And then automatically redirect to Paystacks website to make payment, like so:
- You need to verify the transaction to determine a failed or successful transaction. See
application/controllers/Sample_controller.php
for example.