PaystackLite: Getting Started With Paystack Fluent APIs In Your Laravel Application
Published November 25, 2019 • 2 mins read
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.
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_EMAILfirstname.lastname@example.org
Paystack Fluent APIs
Instantiate PaystackLite Class
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.
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.
App Service Container
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.
// 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.
Join my weekly newsletter and never miss out on new tutorials, tips, and more.
You can also follow me on twitter @stephenjudeso
Litehost is my side project which is a shared hosting platform with PHP & Laravel developers in mind. It has Composer, Git & PHP CLI pre-installed on its servers. SSH access is also granted on request. Litehost is pretty affordable. Try it today.