PHP code example of myckhel / laravel-paystack
1. Go to this page and download the library: Download myckhel/laravel-paystack library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
myckhel / laravel-paystack example snippets
php artisan vendor:publish --provider="Binkode\Paystack\PaystackServiceProvider"
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" => ["paystack_route_disabled", "api"], // For injecting middleware to the package's routes
"prefix" => "api", // For injecting middleware to the package's routes
"hook_middleware" => ["validate_paystack_hook", "api"]
],
];
use Binkode\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 Binkode\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 Binkode\Paystack\Support\ApplePay;
ApplePay::createDomain($params);
ApplePay::listDomains($params);
ApplePay::removeDomain($params);
use Binkode\Paystack\Support\SubAccount;
SubAccount::create($params);
SubAccount::list($params);
SubAccount::fetch($subaccount, $params);
SubAccount::update($subaccount, $params);
use Binkode\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 Binkode\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 Binkode\Paystack\Support\Plan;
Plan::create($params);
Plan::list($params);
Plan::fetch($plan, $params);
Plan::update($plan, $params);
use Binkode\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 Binkode\Paystack\Support\Product;
Product::create($params);
Product::list($params);
Product::fetch($product, $params);
Product::update($product, $params);
use Binkode\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 Binkode\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 Binkode\Paystack\Support\Settlement;
Settlement::list($params);
Settlement::transactions($settlement, $params);
use Binkode\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 Binkode\Paystack\Support\Transfer;
Transfer::initiate($params);
Transfer::finalize($params);
Transfer::bulkCreate($params);
Transfer::list($params);
Transfer::fetch($transfer, $params);
Transfer::fetch($reference, $params);
use Binkode\Paystack\Support\TransferControl;
TransferControl::balance($params);
TransferControl::balanceLedger($params);
TransferControl::resendTransfersOTP($params);
TransferControl::disableTransfersOTP($params);
TransferControl::finalizeDisableOTP($params);
TransferControl::enableTransfersOTP($params);
use Binkode\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 Binkode\Paystack\Support\ControlPanel;
ControlPanel::fetchPaymentSessionTimeout($params);
ControlPanel::updatePaymentSessionTimeout($params);
use Binkode\Paystack\Support\Charge;
Charge::create($params);
Charge::submitPin($params);
Charge::submitOtp($params);
Charge::submitPhone($params);
Charge::submitBirthday($params);
Charge::submitAddress($params);
Charge::checkPending($reference, $params);
use Binkode\Paystack\Support\Dispute;
Dispute::list($params);
Dispute::fetch($dispute, $params);
Dispute::listTransaction($dispute, $params);
Dispute::update($dispute, $params);
Dispute::addEvidence($dispute, $params);
Dispute::getUploadURL($dispute, $params);
Dispute::resolve($dispute, $params);
Dispute::export($params);
use Binkode\Paystack\Support\Refund;
Refund::create($params);
Refund::list($params);
Refund::fetch($refund, $params);
use Binkode\Paystack\Support\Verification;
Verification::resolve($params);
Verification::validateAccount($params);
Verification::resolveCardBIN($bin, $params);
use Binkode\Paystack\Support\Miscellaneous;
Miscellaneous::listBanks($params);
Miscellaneous::listProviders($params);
Miscellaneous::listCountries($params);
Miscellaneous::listStates($params);
namespace App\Listeners;
use Binkode\Paystack\Events\Hook;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class PaystackWebHookListener
{
/**
* Handle the event.
*
* @param Binkode\Paystack\Events\Hook $event
* @return void
*/
public function handle(Hook $event)
{
Log::debug($event->event);
/* {
"event":"charge.success",
"data": {
"id":302961,
"domain":"live",
"status":"success",
"reference":"qTPrJoy9Bx",
"amount":10000,
"message":null,
"gateway_response":"Approved by Financial Institution",
"paid_at":"2016-09-30T21:10:19.000Z",
"created_at":"2016-09-30T21:09:56.000Z",
"channel":"card",
"currency":"NGN",
"ip_address":"41.242.49.37",
"metadata":0,
"log":{
"time_spent":16,
"attempts":1,
"authentication":"pin",
"errors":0,
"success":false,
"mobile":false,
"input":[],
"channel":null,
"history":[
{
"type":"input",
"message":"Filled these fields: card number, card expiry, card cvv",
"time":15
},
{
"type":"action",
"message":"Attempted to pay",
"time":15
},
{
"type":"auth",
"message":"Authentication Required: pin",
"time":16
}
]
},
"fees":null,
"customer":{
"id":68324,
"first_name":"BoJack",
"last_name":"Horseman",
"email":"[email protected] ",
"customer_code":"CUS_qo38as2hpsgk2r0",
"phone":null,
"metadata":null,
"risk_action":"default"
},
"authorization":{
"authorization_code":"AUTH_f5rnfq9p",
"bin":"539999",
"last4":"8877",
"exp_month":"08",
"exp_year":"2020",
"card_type":"mastercard DEBIT",
"bank":"Guaranty Trust Bank",
"country_code":"NG",
"brand":"mastercard",
"account_name": "BoJack Horseman"
},
"plan":{}
}
}
*/
}
}
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Binkode\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,
],
];
paystack.php
bash
php artisan make:listener PaystackWebHookListener --event=Binkode\Paystack\Events\Hook