1. Go to this page and download the library: Download veeqtoh/cashier-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/ */
use Veeqtoh\Cashier\Billable;
class User extends Authenticatable
{
use Billable;
}
use Veeqtoh\Cashier\Cashier;
Cashier::useCurrency('ngn', '₦');
Cashier::useCurrency('ghs', 'GH₵');
$user = User::find(1);
$plan_code = // Paystack plan code e.g PLN_gx2wn530m0i3w3m
$plan_name = // Paystack plan name e.g default, main, yakata
$auth_token = // Paystack card auth token for customer
//Example usages.
// 1. Accepts an card authorization authtoken for the customer.
$response = $user->newSubscription($plan_code, $plan_name)->create($auth_token);
// 2. The customer's most recent authorization would be used to charge subscription.
$response = $user->newSubscription($plan_code, $plan_name)->create();
// 3. Initialize a new charge for a subscription.
$response = $user->newSubscription($plan_code, $plan_name)->charge();
return redirect($response['data']['authorization_url']);
// Paystack plan name e.g default, main, yakata.
if ($user->subscribed('main')) {
//
}
public function handle($request, Closure $next)
{
if ($request->user() && ! $request->user()->subscribed('main')) {
// This user is not a paying customer...
return redirect('billing');
}
return $next($request);
}
if ($user->subscription('main')->onTrial()) {
//
}
$plan_code = // Paystack Paystack Code e.g PLN_gx2wn530m0i3w3m
$plan_name = // Paystack plan name e.g default, main, yakata
if ($user->subscribedToPlan($plan_code, $plan_name)) {
//
}
if ($user->subscription('main')->cancelled()) {
//
}
if ($user->subscription('main')->onGracePeriod()) {
//
}
$user->subscription('main')->cancel();
if ($user->subscription('main')->onGracePeriod()) {
//
}
namespace App\Listeners;
use Veeqtoh\Cashier\Events\WebhookReceived;
class PaystackEventListener
{
/**
* Handle received Paystack webhooks.
*/
public function handle(WebhookReceived $event): void
{
if ($event->payload['event'] === 'invoice.payment_failed') {
// Handle the incoming event...
}
}
}
namespace App\Http\Controllers;
use Veeqtoh\Cashier\Http\Controllers\WebhookController as CashierController;
class WebhookController extends CashierController
{
/**
* Handle invoice payment succeeded.
*
* @param array $payload
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handleInvoiceUpdate($payload)
{
// Handle The Event
}
}
use App\Http\Controllers\WebhookController
Route::post('paystack/webhook', 'WebhookController@handleWebhook')->name('webhook');
// Paystack Accepts Charges In Kobo for Naira...
$paystackCharge = $user->charge(10000);
$user->charge(100, ['more_option' => $value]);
try {
// Paystack Accepts Charges In Kobo for Naira...
$response = $user->charge(10000);
} catch (Exception $e) {
//
}
// Paystack Accepts Charges In Kobo for Naira...
$user->invoiceFor('One Time Fee', 200000);
$invoices = $user->invoices();
// Include only pending invoices in the results...
$invoices = $user->invoicesOnlyPending();
// Include only paid invoices in the results...
$invoices = $user->invoicesOnlyPaid();