Phalcon Cashier have not implement so that to use it just install library at https://github.com/duythien/cashier .It provides a simple API for handling common tasks associated with subscriptions. In this tip we will take an in-depth look at working with subscriptions and coupons.

Install Phalcon cashier

First you need install Phalcon Cashier via composer, to do that just following command below:

After that you need created table and some fields in your database

Model setup

Provider Keys in your config

Add some parameter in config.php such as like below:

After configuration library, you will need to create them using the Stripe administration console. Once created, you'll need to integrate the necessary logic into your web application's subscription work-flow. Let is start by entering the administration console and creating a coupon.

Creating a Stripe Plan and Coupon

To create a coupon for your users, go to website stripe at https://dashboard.stripe.com The form to add a plan can be found in the sidebar under Subscriptions -> Plan and then click the new link on the right. The form will then open the following modal window: The form Coupon: the sidebar under Subscriptions -> Coupon Which elements:

After creating your coupon, you can then e-mail the ID Code to your user and allow them to apply the discount.

Use it

To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of App\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 Stripe plan the user is subscribing to. This value should correspond to the plan's identifier in Stripe.

The create method will automatically create the subscription, as well as update your database with the customer ID and other relevant billing information.You can also take a look example real:

Adding a Coupon to a New Subscription

All you have to do is utilize Cashier's withCoupon() method when creating the subscription. Here is an example:

As you can see from this tip working with subscription and coupons is really simple with Phalcon and Stripe, right?
[null, null, {"document_url": "https://phalcontip.com/discussion/70/handling-subscriptions-with-stripe-and-phalcon-cashier", "unformatted_src": "https://i.imgur.com/mskNbeQ.png", "src": "https://i.imgur.com/mskNbeQ.png", "formatted_filename": "mskNbeQ"}, null, {"document_url": "https://phalcontip.com/discussion/70/handling-subscriptions-with-stripe-and-phalcon-cashier", "unformatted_src": "https://i.imgur.com/DozXnRy.png", "src": "https://i.imgur.com/DozXnRy.png", "formatted_filename": "DozXnRy", "alt_text": "Phalcon cashier"}, null, {"document_url": "https://phalcontip.com/discussion/70/handling-subscriptions-with-stripe-and-phalcon-cashier", "unformatted_src": "https://i.imgur.com/z2zZ6gQ.png", "src": "https://i.imgur.com/z2zZ6gQ.png", "formatted_filename": "z zZ gQ", "alt_text": "Cinque Terre"}, null]