1. Go to this page and download the library: Download devtobi/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/ */
devtobi / cashier-paystack example snippets
return [
/**
* Public Key From Paystack Dashboard
*
*/
'publicKey' => getenv('PAYSTACK_PUBLIC_KEY'),
/**
* Secret Key From Paystack Dashboard
*
*/
'secretKey' => getenv('PAYSTACK_SECRET_KEY'),
/**
* Paystack Payment URL
*
*/
'paymentUrl' => getenv('PAYSTACK_PAYMENT_URL'),
/**
* Optional email address of the merchant
*
*/
'merchantEmail' => getenv('MERCHANT_EMAIL'),
/**
* User model for customers
*
*/
'model' => getenv('PAYSTACK_MODEL'),
];
use Wisdomanthoni\Cashier\Billable;
class User extends Authenticatable
{
use Billable;
}
use Wisdomanthoni\Cashier\Cashier;
Cashier::useCurrency('ngn', '₦');
Cashier::useCurrency('ghs', 'GH₵');
$user = User::find(1);
$plan_name = // Paystack plan name e.g default, main, yakata
$plan_code = // Paystack plan code e.g PLN_gx2wn530m0i3w3m
$auth_token = // Paystack card auth token for customer
// Accepts an card authorization authtoken for the customer
$user->newSubscription($plan_name, $plan_code)->create($auth_token);
// The customer's most recent authorization would be used to charge subscription
$user->newSubscription($plan_name, $plan_code)->create();
// Initialize a new charge for a subscription
$user->newSubscription($plan_name, $plan_code)->charge();
// 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_name = // Paystack plan name e.g default, main, yakata
$plan_code = // Paystack Paystack Code e.g PLN_gx2wn530m0i3w3m
if ($user->subscribedToPlan($plan_code, $plan_code)) {
//
}
if ($user->subscription('main')->cancelled()) {
//
}
if ($user->subscription('main')->onGracePeriod()) {
//
}
$user->subscription('main')->cancel();
if ($user->subscription('main')->onGracePeriod()) {
//
}
$invoices = $user->invoices();
// Include only pending invoices in the results...
$invoices = $user->invoicesOnlyPending();
// Include only paid invoices in the results...
$invoices = $user->invoicesOnlyPaid();