Download the PHP package initafricahq/cashier-paystack without Composer

On this page you can find all versions of the php package initafricahq/cashier-paystack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cashier-paystack

Laravel Cashier - Paystack Edition

Introduction

Cashier Paystack provides an expressive, fluent interface to Paystack's subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing.

Composer

First, add the Cashier package for Paystack to your dependencies:

composer require initafricahq/cashier-paystack

Configuration

You can publish the configuration file using this command:

A configuration-file named cashier-paystack.php with some sensible defaults will be placed in your config directory:

Database Migrations

Before using Cashier, we'll also need to prepare the database. You can simply publish the migratrion files and run the migrate command:

Billable Model

Next, add the Billable trait to your model definition. This trait provides various methods to allow you to perform common billing tasks, such as creating subscriptions, applying coupons, and updating credit card information:

Currency Configuration

The default Cashier currency is Nigeria Naira (NGN). You can change the default currency by calling the Cashier::useCurrency method from within the boot method of one of your service providers. The useCurrency method accepts two string parameters: the currency and the currency's symbol:

Subscriptions

Creating Subscriptions

To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of App\Model\User. Once you have retrieved the model instance, you may use the newSubscription method to create the model's subscription:

The first argument passed to the newSubscription method should be the name of the subscription. If your application only offers a single subscription, you might call this main or primary. The second argument is the specific Paystack Paystack code the user is subscribing to. This value should correspond to the Paystack's code identifier in Paystack.

The create method, which accepts a Paystack authorization token, will begin the subscription as well as update your database with the customer/user ID and other relevant billing information.

The charge method, initializes a transaction which returns a response containing an authorization url for payment and an access code.

Additional User Details If you would like to specify additional customer details, you may do so by passing them as the second argument to the create method:

To learn more about the additional fields supported by Paystack, check out paystack's documentation on customer creation or the corresponding Paystack documentation.

Checking Subscription Status

Once a user is subscribed to your application, you may easily check their subscription status using a variety of convenient methods. First, the subscribed method returns true if the user has an active subscription, even if the subscription is currently within its trial period:

The subscribed method also makes a great candidate for a route middleware, allowing you to filter access to routes and controllers based on the user's subscription status:

If you would like to determine if a user is still within their trial period, you may use the onTrial method. This method can be useful for displaying a warning to the user that they are still on their trial period:

The subscribedToPaystack method may be used to determine if the user is subscribed to a given Paystack based on a given Paystack Paystack code. In this example, we will determine if the user's main subscription is actively subscribed to the monthly Paystack:

Cancelled Subscription Status

To determine if the user was once an active subscriber, but has cancelled their subscription, you may use the cancelled method:

You may also determine if a user has cancelled their subscription, but are still on their "grace period" until the subscription fully expires. For example, if a user cancels a subscription on March 5th that was originally scheduled to expire on March 10th, the user is on their "grace period" until March 10th. Note that the subscribed method still returns true during this time:

Cancelling Subscriptions

To cancel a subscription, call the cancel method on the user's subscription:

When a subscription is cancelled, Cashier will automatically set the ends_at column in your database. This column is used to know when the subscribed method should begin returning false. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the subscribed method will continue to return true until March 5th.

You may determine if a user has cancelled their subscription but are still on their "grace period" using the onGracePeriod method:

If you wish to cancel a subscription immediately, call the cancelNow method on the user's subscription:

Resuming Subscriptions

If a user has cancelled their subscription and you wish to resume it, use the resume method. The user must still be on their grace period in order to resume a subscription:

If the user cancels a subscription and then resumes that subscription before the subscription has fully expired, they will not be billed immediately. Instead, their subscription will be re-activated, and they will be billed on the original billing cycle.

Subscription Trials

With Billing Up Front

If you would like to offer trial periods to your customers while still collecting payment method information up front, you should use the trialDays method when creating your subscriptions:

This method will set the trial period ending date on the subscription record within the database, as well as instruct Paystack to not begin billing the customer until after this date.

If the customer's subscription is not cancelled before the trial ending date they will be charged as soon as the trial expires, so you should be sure to notify your users of their trial ending date.

You may determine if the user is within their trial period using either the onTrial method of the user instance, or the onTrial method of the subscription instance. The two examples below are identical:

Without Billing Up Front

If you would like to offer trial periods without collecting the user's payment method information up front, you may set the trial_ends_at column on the user record to your desired trial ending date. This is typically done during user registration:

Be sure to add a date mutator for trial_ends_at to your model definition.

Cashier refers to this type of trial as a "generic trial", since it is not attached to any existing subscription. The onTrial method on the User instance will return true if the current date is not past the value of trial_ends_at:

You may also use the onGenericTrial method if you wish to know specifically that the user is within their "generic" trial period and has not created an actual subscription yet:

Once you are ready to create an actual subscription for the user, you may use the newSubscription method as usual:

Customers

Creating Customers

Occasionally, you may wish to create a Paystack customer without beginning a subscription. You may accomplish this using the createAsCustomer method:

Once the customer has been created in Paystack, you may begin a subscription at a later date.

Payment Methods

Retrieving Authenticated Payment Methods

The cards method on the billable model instance returns a collection of InitAfricaHQ\Cashier\Card instances:

Deleting Payment Methods

To delete a card, you should first retrieve the customer's authentications with the card method. Then, you may call the delete method on the instance you wish to delete:

To delete all card payment authentication for a customer

Handling Paystack Webhooks

Paystack can notify your application of a variety of events via webhooks. To handle Paystack webhooks, define a route that points to Cashier's webhook controller. If configured this is already set at /paystack. This controller will handle all incoming webhook requests and dispatch them to the proper controller method: You may however choose to override this with your own path by setting the PAYSTACK_PATH env variable or create an entire new route

Once you have registered your route, be sure to configure the webhook URL in your Paystack dashboard settings.

By default, this controller will automatically handle cancelling subscriptions that have too many failed charges (as defined by your paystack settings), charge success, transfer success or fail, invoice updates and subscription changes; however, as we'll soon discover, you can extend this controller to handle any webhook event you like.

Make sure you protect incoming requests with Cashier's included webhook signature verification middleware.

Webhooks & CSRF Protection

Since Paystack webhooks need to bypass Laravel's CSRF protection, be sure to list the URI as an exception in your VerifyCsrfToken middleware or list the route outside of the web middleware group:

Defining Webhook Event Handlers

If you have additional Paystack webhook events you would like to handle, extend the Webhook controller. Your method names should correspond to Cashier's expected convention, specifically, methods should be prefixed with handle and the "camel case" name of the Paystack webhook event you wish to handle.

Next, define a route to your Cashier controller within your routes/web.php file:

Single Charges

Simple Charge

When using Paystack, the charge method accepts the amount you would like to charge in the lowest denominator of the currency used by your application.

If you would like to make a "one off" charge against a subscribed customer's credit card, you may use the charge method on a billable model instance.

The charge method accepts an array as its second argument, allowing you to pass any options you wish to the underlying Paystack charge creation. Consult the Paystack documentation regarding the options available to you when creating charges:

The charge method will throw an exception if the charge fails. If the charge is successful, the full Paystack response will be returned from the method:

Charge With Invoice

Sometimes you may need to make a one-time charge but also generate an invoice for the charge so that you may offer a PDF receipt to your customer. The invoiceFor method lets you do just that. For example, let's invoice the customer ₦2000.00 for a "One Time Fee":

The invoice will be charged immediately against the user's credit card. The invoiceFor method also accepts an array as its third argument. This array contains the billing options for the invoice item. The fourth argument accepted by the method is also an array. This final argument accepts the billing options for the invoice itself:

To learn more about the additional fields supported by Paystack, check out paystack's documentation on customer creation or the corresponding Paystack documentation.

Refunding Charges If you need to refund a Paystack charge, you may use the refund method. This method accepts the Paystack charge ID as its only argument:

Invoices You may easily retrieve an array of a billable model's invoices using the invoices method:

When listing the invoices for the customer, you may use the invoice's helper methods to display the relevant invoice information. For example, you may wish to list every invoice in a table, allowing the user to easily download any of them:

Generating Invoice PDFs From within a route or controller, use the downloadInvoice method to generate a PDF download of the invoice. This method will automatically generate the proper HTTP response to send the download to the browser:


All versions of cashier-paystack with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
dompdf/dompdf Version ^2.0
guzzlehttp/guzzle Version ^7.8
illuminate/database Version ^10.0
illuminate/http Version ^10.30
illuminate/routing Version ^10.30
illuminate/support Version ^10.0
illuminate/view Version ^10.30
nesbot/carbon Version ^2.0
symfony/http-kernel Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package initafricahq/cashier-paystack contains the following files

Loading the files please wait ....