November, 25 2019
Earlier this week, I wrote an article on how to setup Paystack checkout form. Yeah I did but that's not all PaystackLite can offer.
In this article I will be walking you through how you can hit Paystack endpoints using PaystackLite. Let's get started.
Install the package with composer.
composer require stephenjude/paystack-lite
If you are using Laravel less than 5.4, add the line below to the providers array in your config/app.php file.
Stephenjude\PaystackLite\PaystackLiteServiceProvider::class,
Update your .env file and add your public key, secret key, customer default email and payment url.
PAYSTACK_PUBLIC_KEY=xxxxxxxxxxxxx
PAYSTACK_SECRET_KEY=xxxxxxxxxxxxx
PAYSTACK_PAYMENT_URL=https://api.paystack.co
PAYSTACK_CUSTOMER_DEFAULT_EMAIL=general@email.com
PaystackLite is wrapped around Xeviant Paystack package. So you can use all paystack fluent APIs provided in the package. There are three different ways to make use of this package.
<?php
use Stephenjude\PaystackLite\PaystackLite
$paystack = new PaystackLite;
// Returns a list of your customers
$data = $paystack->api()->customers()->list();
This is basically accessing the fluent APIs through an instance of PaystackLite class.
<?php
use Stephenjude\PaystackLite\Facades\PaystackLite;
// Returns a list of your transactions
$data = PaystackLite::api()->transactions()->list();
This is Laravel Facades doing the magic for us.
This is my most preferred method of using Paystack fluent APIs provided in this package. You
With this method you don't need to import or instantiate any class to make use of the PaystackLite class. You only need to call app('paystack') helper function followed by fluent methods as show above.
Here is an example on how to get a list of all the plans in your Paystack account.
<?php
// returns a list of your paystack plans
app('paystack')->api()->plans()->list();
Here is a list of endpoints supported in this package
All supported endpoints are covered here in details.
I believe you now have an understanding of how PaystackLite works. You can go through the documentation for more details and don't forget to star PaystackLite on Github. If you have any question drop it in the comment section below.
You can also follow me on twitter @stephenjude_
Be the first to hear about anything I publish, launch, or think is helpful for you. Subscribe here
Litehost is a web hosting platform for PHP & Laravel developers with Composer, Git, PHP & CLI pre-installed. Try it now