baka/cashier

Phalcon Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

dev-master 2020-07-17 17:21 UTC

This package is auto-updated.

Last update: 2024-04-18 01:47:13 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

Introduction

Phalcon Cashier provides an expressive, fluent interface to Stripe's subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.

Test Setup

You will need to set the following details locally and on your Stripe account in order to test:

Local

Database Configuration

CREATE TABLE `companies` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(45) DEFAULT NULL,
  `profile_image` varchar(45) DEFAULT NULL,
  `website` varchar(45) DEFAULT NULL,
  `users_id` int(11) NOT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `is_deleted` int(11) DEFAULT NULL
);

CREATE TABLE `apps` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(45) DEFAULT NULL,
  `description` varchar(45) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `is_deleted` int(11) DEFAULT NULL
);

CREATE TABLE `subscriptions` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `name` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `stripe_id` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `stripe_plan` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `quantity` int(11) NOT NULL,
  `trial_ends_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `ends_at` timestamp NULL DEFAULT NULL
);


ALTER TABLE `subscriptions`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `subscriptions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;

/*To execute this commands a users table must be created*/

IF (EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE  TABLE_NAME = 'users'))
BEGIN
    ALTER TABLE `users` ADD `stripe_id` VARCHAR(200) NULL;
    ALTER TABLE `users` ADD `card_brand` VARCHAR(200) NULL;
    ALTER TABLE `users` ADD `card_last_four` VARCHAR(200) NULL;
    ALTER TABLE `users` ADD `trial_ends_at` timestamp NULL DEFAULT NULL;
    ALTER TABLE `users` ADD `active_subscription_id` VARCHAR(200) NULL DEFAULT NULL;
END

Add some parameter in config.php such as like below

'stripe' => [
    'model'      => 'App\Models\Users',
    'secretKey'  => null,
    'publishKey' => null
]

Model Setup

Add Billable Model to Users MODEL

use Phalcon\Cashier\Billable;

class User extends Authenticatable
{
    use Billable;
}

Stripe

Plans

* monthly-10-1 ($10)
* monthly-10-2 ($10)

Coupons

* coupon-1 ($5)

Official Documentation

You can how to using it at here. Also it is inspiring by Laravel so you can take look on the Laravel website.

Contributing

Thank you for considering contributing to the Cashier. You can read the contribution guide lines here.

License

Phalcon Cashier is open-sourced software licensed under the MIT license