Are you ready to take your app startup ideas to the next level? Look no further! In this article, we'll dive into the world of Laravel Paystack Subscription and explore how it can simplify your subscription billing services.

What is Laravel Paystack Subscription?

Laravel Paystack Subscription offers a simple, fluent interface to Paystack's subscription billing services. With this package, you can say goodbye to writing tedious subscription billing code. Instead, focus on building a robust app that users will love!

Installation and Configuration

To get started with Laravel Paystack Subscription, simply install the package via composer:

composer require digikraaft/laravel-paystack-subscription

Next, configure your Paystack keys in your .env file. You can retrieve these from your Paystack dashboard.

PAYSTACK_PUBLIC_KEY=your-paystack-public-key

PAYSTACK_SECRET=your-paystack-secret

Setting Up Your Billable Model

The Laravel Paystack Subscription package assumes that your billable model will be the default App\User class that ships with Laravel. However, you can specify a different model in your .env file or in the published config file of the package:

SUBSCRIPTION_MODEL = App\User

Configuring Your User Table and Webhook Path

In your configuration file, set the user table and webhook path as follows:

user_table => 'users'

webhook_path => env('PAYSTACK_WEBHOOK_PATH', 'paystack')

Publishing the Configuration File and Migrations

To publish the configuration file and migrations, run the following commands:

php artisan vendor:publish --provider="Digikraaft\PaystackSubscription\PaystackSubscriptionServiceProvider" --tag="config"

php artisan vendor:publish --provider="Digikraaft\PaystackSubscription\PaystackSubscriptionServiceProvider" --tag="migrations"

php artisan migrate

Using the Package in Your App Startup Ideas

Now that you've set up your configuration and migrations, it's time to use the package in your app startup ideas! Start by adding the Billable trait to your model definition:

use Digikraaft\PaystackSubscription\Billable;

class User extends Authenticatable

{

use Billable;

}

Retrieving a Customer

To retrieve a customer by their Paystack ID, use the findBillable method:

$paystackCustomer = PaystackSubscription::findBillable($paystackId);

Creating a Paystack Customer

To create a Paystack customer without starting a subscription immediately, use the createAsPaystackCustomer method:

$paystackCustomer = $user->createAsPaystackCustomer();

Updating a Paystack Customer

To update a Paystack customer with additional information, use the updatePaystackCustomer method:

$paystackCustomer = $user->updatePaystackCustomer($options);

Creating a Subscription

To create a subscription, first retrieve an instance of your billable model. Then, use the newSubscription method to create the model's subscription:

$user = User::find(1);

$user->newSubscription('default', 'PLN_paystackplan_code')->create($transactionId);

With Laravel Paystack Subscription, you can focus on building a robust app that users will love! Whether you're looking for inspiration for your app startup ideas or need help with subscription billing services, this package is here to simplify your development process.