Use Paystack Apis in your laravel project.
There are other libraries but this was created to solve the issues such as flexibility and ability to call paystack apis in laravel Job scope.
composer require myckhel/laravel-paystack
The package will automatically register a service provider.
You need to publish the configuration file:
php artisan vendor:publish --provider="Myckhel\Paystack\PaystackServiceProvider"
This is the default content of the config file paystack.php
:
<?php
return [
"public_key" => env("PAYSTACK_PUBLIC_KEY"),
"secret_key" => env("PAYSTACK_SECRET_KEY"),
"url" => env("PAYSTACK_URL", 'https://api.paystack.co'),
"merchant_email" => env("PAYSTACK_MERCHANT_EMAIL"),
"route" => [
"middleware" => ['api'], // For injecting middleware to the package's routes
"prefix" => 'api', // For injecting middleware to the package's routes
],
];
Update Your Projects .env
with their credentials:
PAYSTACK_PUBLIC_KEY=XXXXXXXXXXXXXXXXXXXX
PAYSTACK_SECRET_KEY=XXXXXXXXXXXXXXXXXXXX
PAYSTACK_URL=https://api.paystack.co
PAYSTACK_MERCHANT_EMAIL=username@email.extension
use Myckhel\Paystack\Support\Transaction;
Transaction::list($params);
Transaction::initialize($params);
Transaction::verify($reference, $params);
Transaction::fetch($transaction, $params);
Transaction::charge_authorization($params);
Transaction::check_authorization($params);
Transaction::viewTimeline($id_or_reference, $params);
Transaction::totals($params);
Transaction::export($params);
Transaction::partial_debit($params);
use Myckhel\Paystack\Support\Split;
Split::create($params);
Split::list($params);
Split::fetch($split, $params);
Split::update($split, $params);
Split::add($split, $params);
Split::remove($split, $params);
use Myckhel\Paystack\Support\ApplePay;
ApplePay::createDomain($params);
ApplePay::listDomains($params);
ApplePay::removeDomain($params);
use Myckhel\Paystack\Support\SubAccount;
SubAccount::create($params);
SubAccount::list($params);
SubAccount::fetch($subaccount, $params);
SubAccount::update($subaccount, $params);
use Myckhel\Paystack\Support\Customer;
Customer::create($params);
Customer::list($params);
Customer::fetch($customer, $params);
Customer::update($customer, $params);
Customer::identification($customer, $params);
Customer::set_risk_action($customer, $params);
Customer::deactivate_authorization($params);
use Myckhel\Paystack\Support\DedicatedVirtualAccount;
DedicatedVirtualAccount::create($params);
DedicatedVirtualAccount::list($params);
DedicatedVirtualAccount::fetch($dedicated_account, $params);
DedicatedVirtualAccount::remove($dedicated_account, $params);
DedicatedVirtualAccount::split($params);
DedicatedVirtualAccount::removeSplit($params);
DedicatedVirtualAccount::providers($params);
use Myckhel\Paystack\Support\Plan;
Plan::create($params);
Plan::list($params);
Plan::fetch($plan, $params);
Plan::update($plan, $params);
use Myckhel\Paystack\Support\Subscription;
Subscription::create($params);
Subscription::list($params);
Subscription::fetch($plan, $params);
Subscription::enable($params);
Subscription::disable($params);
Subscription::link($code, $params);
Subscription::sendUpdateSubscription($code, $params);
use Myckhel\Paystack\Support\Product;
Product::create($params);
Product::list($params);
Product::fetch($product, $params);
Product::update($product, $params);
use Myckhel\Paystack\Support\Page;
Page::create($params);
Page::list($params);
Page::fetch($page, $params);
Page::update($page, $params);
Page::checkSlug($slug, $params);
Page::addProduct($page, $params);
use Myckhel\Paystack\Support\Invoice;
Invoice::create($params);
Invoice::list($params);
Invoice::fetch($invoice, $params);
Invoice::update($invoice, $params);
Invoice::verify($code, $params);
Invoice::notify($code, $params);
Invoice::totals($params);
Invoice::finalize($code, $params);
Invoice::archive($code, $params);
use Myckhel\Paystack\Support\Settlement;
Settlement::list($params);
Settlement::transactions($settlement, $params);
use Myckhel\Paystack\Support\Recipient;
Recipient::create($params);
Recipient::bulkCreate($params);
Recipient::list($params);
Recipient::fetch($recipient, $params);
Recipient::update($recipient, $params);
Recipient::remove($recipient, $params);
use Myckhel\Paystack\Support\Transfer;
Transfer::initiate($params);
Transfer::finalize($params);
Transfer::bulkCreate($params);
Transfer::list($params);
Transfer::fetch($transfer, $params);
Transfer::fetch($reference, $params);
use Myckhel\Paystack\Support\TransferControl;
TransferControl::balance($params);
TransferControl::balanceLedger($params);
TransferControl::resendTransfersOTP($params);
TransferControl::disableTransfersOTP($params);
TransferControl::finalizeDisableOTP($params);
TransferControl::enableTransfersOTP($params);
use Myckhel\Paystack\Support\BulkCharge;
BulkCharge::initiate($params);
BulkCharge::list($params);
BulkCharge::fetch($bulkcharge, $params);
BulkCharge::fetchChargesBatch($bulkcharge, $params);
BulkCharge::pauseChargesBatch($bulkcharge, $params);
BulkCharge::resumeChargesBatch($bulkcharge, $params);
use Myckhel\Paystack\Support\ControlPanel;
ControlPanel::fetchPaymentSessionTimeout($params);
ControlPanel::updatePaymentSessionTimeout($params);
Laravel paystack provides you a predefined endpoint that listens to and validates incoming paystack's webhook events.
It emits Myckhel\Paystack\Events\Hook
on every incoming hooks which could be listened to.
Check official page to read more about paystack webhook
laravel-paystack exposes hooks
api endpoint
use the enddpoints url to for the paystack webhook url during the setup.
| POST | /hooks | | Myckhel\Paystack\Http\Controllers\HookController@hook | api |
You may start listening to incoming paystack webhooks after setup by registering the event in your laravel project's EventServiceProvider
file.
php artisan make:listener PaystackWebHookListener --event=Myckhel\Paystack\Events\Hook
<?php
namespace App\Listeners;
use Myckhel\Paystack\Events\Hook;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class PaystackWebHookListener
{
/**
* Handle the event.
*
* @param Myckhel\Paystack\Events\Hook $event
* @return void
*/
public function handle(Hook $event)
{
Log::debug($event->event);
/* {
}
*/
}
}
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Myckhel\Paystack\Events\Hook;
use App\Listeners\PaystackWebHookListener;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
...
Hook::class => [
PaystackWebHookListener::class,
],
];
POST hooks ......................................................... Myckhel\Paystack\Http\Controllers\HookController@hook
GET|HEAD subaccount .............................................. Myckhel\Paystack\Http\Controllers\SubAccountController@list
PUT subaccount/{subaccount} ............................... Myckhel\Paystack\Http\Controllers\SubAccountController@update
GET|HEAD transaction ............................................ Myckhel\Paystack\Http\Controllers\TransactionController@list
POST transaction/charge_authorization ....... Myckhel\Paystack\Http\Controllers\TransactionController@charge_authorization
POST transaction/check_authorization ......... Myckhel\Paystack\Http\Controllers\TransactionController@check_authorization
GET|HEAD transaction/export ................................... Myckhel\Paystack\Http\Controllers\TransactionController@export
POST transaction/initialize ........................... Myckhel\Paystack\Http\Controllers\TransactionController@initialize
POST transaction/partial_debit ..................... Myckhel\Paystack\Http\Controllers\TransactionController@partial_debit
GET|HEAD transaction/timeline/{id_or_reference} ......... Myckhel\Paystack\Http\Controllers\TransactionController@viewTimeline
GET|HEAD transaction/totals ................................... Myckhel\Paystack\Http\Controllers\TransactionController@totals
GET|HEAD transaction/verify/{reference} ....................... Myckhel\Paystack\Http\Controllers\TransactionController@verify
GET|HEAD transaction/{transaction} ............................. Myckhel\Paystack\Http\Controllers\TransactionController@fetch
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email myckhel1@hotmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.