Download the PHP package bgultekin/cashier-fastspring without Composer
On this page you can find all versions of the php package bgultekin/cashier-fastspring. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bgultekin/cashier-fastspring
More information about bgultekin/cashier-fastspring
Files in bgultekin/cashier-fastspring
Package cashier-fastspring
Short Description Cashier Fastspring is a cashier-like laravel package which provides an interface to Fastspring subscription and payment services.
License MIT
Informations about the package cashier-fastspring
Cashier Fastspring
Table of contents
- Introduction
- Installation
- Configuration
- Migrations
- Billable Model
- API Keys
- Creating Plans
- Quick Start
- Usage
- Subscriptions
- Creating Subscriptions
- Checking Subscription Status
- Changing Plans
- Subscription Periods
- Subscription Trials
- Cancelling Subscriptions
- Resuming Subscriptions
- Updating Credit Cards
- Webhooks
- Single Charges
- Invoices
- Subscriptions
- Contributing
- Credits
- Licence
Introduction
Cashier Fastspring is a cashier-like laravel package which provides interface to Fastspring subscription and payment services. This package handles webhooks and provides a simple API for Fastspring. Before using this package, looking at Fastspring documentation is strongly recommended.
Installation
Add bgultekin/cashier-fastspring
package to your dependencies.
After requiring package, add service provider of this package to providers in config/app.php
.
Configuration
Migrations
Cashier Fastspring package comes with database migrations. After requiring the package, you can publish it with following command.
After publishing them, you can find migration files in your database/migrations
folder. Remember that you can modify them according to your needs.
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 and checking subscriptions, getting orders etc.
API Keys
You should add Fastspring configuration to config/services.php
file.
Webhook Route
Fastspring can notify your application of a variety of events via webhooks. To handle webhooks, define a route and also set it in Fastspring settings.
Webhooks & CSRF Protection
Fastspring webhook requests need to bypass CSRF protection. That's why be sure to list your webhook URI as an exception in your VerifyCsrfToken
middleware.
Creating Plans
This package does not cover creating plans at Fastspring side or storing created plans. You should create your subscription plans at Fastspring's Dashboard.
Quick Start
Cashier Fastspring comes with built-in listeners which you can find in src/Events
for quickstart. These listeners help you to sync subscriptions and invoices with your database.
Remember that you can create and use your listeners and database structure according to your needs. In order to customize, you can check Usage.
In Cashier Fastspring, every webhook request fires related events. You can register listeners to webhook events in app/providers/EventServiceProvider.php
. You can see more at Webhooks.
You should create a session for subscription payment page. You can do it with newSubscription
method as below.
You can provide session id $session->id
to Fastspring's Popup Storefronts or Web Storefronts.
Note: newSubscription
method does not create a subscription model. After a successful payment, you can use browser script to inform your app and create related models.
Usage
Cashier Fastspring comes with ready-to-use Subscription
, Subscription Period
, Invoice
models and webhook handler. You can find detailed explanation below. Remember that you can easily replace these models and logic with yours.
Subscriptions
Cashier Fastspring provides a local
type of subscription which lets you to create subscriptions without interacting with Fastspring. This may help you to create plans without payment info required. If a subscription has no fastspring_id
, it is typed as local. You can check type using type()
, isLocal()
, isFastspring()
methods.
Creating Subscriptions
To create a subscription, you can use newSubscription
method of the Billable
model. After creating session, you can provide session id $session->id
to Fastspring's Popup Storefronts or Web Storefronts.
You can also provide coupon or quantity. As a hint, coupons also can be set on Fastspring's payment pages.
If the Billable
model is not created as Fastspring customer yet newSubscription
model creates it automatically and saves fastspring_id
. If you want to do this manually you can use createAsFastspringCustomer
method.
If details of a Billable
model is updated, you can also update them at Fastspring side with updateAsFastspringCustomer
method.
Checking Subscription Status
At Fastspring side, there are 5 states for subscriptions: active
, overdue
, canceled
, deactivated
, trial
. The only state you should give up to serve your customer is deactivated
state. Others are just informative states. Cashier Fastspring package keeps synchronized state of subscriptions with webhooks.
You can check if you should still serve to the Billable
model by using subscribed
method.
You can retrieve related subscription model by using subscription
method and use methods of Subscription
methods to check its status.
You can use the subscribedToPlan
method to check if the user is subscribed to a given plan.
Changing Plans
You can change current plan of a Billable
model by using swap
method as below. Before using this, it is recommended to look at Prorating when Upgrading or Downgrading Subscription Plans.
The swap
method communicates with Fastspring and updates the subscription model according to response. If you plan to swap plan without prorating, plan doesn't change immediately. In that case, future plan and swap date are saved to swap_to
and swap_at
columns. End of the current subscription period, Fastspring sends you webhook request about subscription change. That's why if you think to use prorating, remember to set webhooks right.
Subscription Trials
You can handle trial days of your plans at Fastspring Dashboard.
Cancelling Subscriptions
To cancel a subscription, call the cancel
method on the subscription model.
If you want to cancel a subscription immediately, you can use cancelNow
method.
Both methods update the subscription model according to response of Fastspring. The cancel
method saves cancellation time to the swap_at
column.
Resuming Subscriptions
To resume a subscription, you can use resume
method on the subscription model. The user must be still on grace period. Otherwise, this method throws a LogicException
.
This method updates the subscription model's state
and set swap_to
, swap_at
columns null
according to response.
Subscription Period
Cashier Fastspring package has also built-in subscription period model and related methods in order to help you to manage payment periods of subscription. This may help you to keep usage of particular resources of users between payment periods.
You can call activePeriodOrCreate
method of Subscription
model and retrieve current SubscriptionPeriod
model which involves id
, start_date
, end_date
information. If the current active period is not created yet, this method fetches it from Fastspring API and creates. If the subscription is a local subscription, it also creates a new period according to the last subscription period (if there is none, it assumes today is the start day of the subscription period).
Updating Credit Cards
Fastspring does not provide any API to update credit card or any other payment information directly. You should redirect your customers to the their account management panel at Fastspring side. You can generate account management panel URL by using accountManagementURI
method of the Billable
model.
Webhooks
Cashier Fastspring package provides an easy way to handle webhooks. It fires related events for each webhook request and provides request payload data as a parameter. It also handles message security if you set FASTSPRING_HMAC_SECRET
. You can find sample listeners in src/Listeners
folder.
Beside webhook specific events, there are also category and any events. For instance, if you want to listen all webhook requests, you can register your listener to Bgultekin\CashierFastspring\Events\Any
event. Also, if you want to listen all subscription related webhook requests, you can use Bgultekin\CashierFastspring\Events\SubscriptionAny
event.
You can see relation between package events and webhook requests at the table below.
Webhook Request | Fired Cashier Fastspring Events |
---|---|
account.created | Bgultekin\CashierFastspring\Events\AccountCreated , Bgultekin\CashierFastspring\Events\AccountAny , Bgultekin\CashierFastspring\Events\Any |
fulfillment.failed | Bgultekin\CashierFastspring\Events\FulfillmentFailed , Bgultekin\CashierFastspring\Events\FulfillmentAny , Bgultekin\CashierFastspring\Events\Any |
mailingListEntry.removed | Bgultekin\CashierFastspring\Events\MailingListEntryRemoved , Bgultekin\CashierFastspring\Events\MailingListEntryAny , Bgultekin\CashierFastspring\Events\Any |
mailingListEntry.updated | Bgultekin\CashierFastspring\Events\MailingListEntryUpdated , Bgultekin\CashierFastspring\Events\MailingListEntryAny , Bgultekin\CashierFastspring\Events\Any |
order.approval.pending | Bgultekin\CashierFastspring\Events\OrderApprovalPending , Bgultekin\CashierFastspring\Events\OrderAny , Bgultekin\CashierFastspring\Events\Any |
order.canceled | Bgultekin\CashierFastspring\Events\OrderCanceled , Bgultekin\CashierFastspring\Events\OrderAny , Bgultekin\CashierFastspring\Events\Any |
order.payment.pending | Bgultekin\CashierFastspring\Events\OrderPaymentPending , Bgultekin\CashierFastspring\Events\OrderAny , Bgultekin\CashierFastspring\Events\Any |
order.completed | Bgultekin\CashierFastspring\Events\OrderCompleted , Bgultekin\CashierFastspring\Events\OrderAny , Bgultekin\CashierFastspring\Events\Any |
order.failed | Bgultekin\CashierFastspring\Events\OrderFailed , Bgultekin\CashierFastspring\Events\OrderAny , Bgultekin\CashierFastspring\Events\Any |
payoutEntry.created | Bgultekin\CashierFastspring\Events\PayoutEntryCreated , Bgultekin\CashierFastspring\Events\PayoutEntryAny , Bgultekin\CashierFastspring\Events\Any |
return.created | Bgultekin\CashierFastspring\Events\ReturnCreated , Bgultekin\CashierFastspring\Events\ReturnAny , Bgultekin\CashierFastspring\Events\Any |
subscription.activated | Bgultekin\CashierFastspring\Events\SubscriptionActivated , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.canceled | Bgultekin\CashierFastspring\Events\SubscriptionCanceled , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.charge.completed | Bgultekin\CashierFastspring\Events\SubscriptionChargeCompleted , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.charge.failed | Bgultekin\CashierFastspring\Events\SubscriptionChargeFailed , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.deactivated | Bgultekin\CashierFastspring\Events\SubscriptionDeactivated , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.payment.overdue | Bgultekin\CashierFastspring\Events\SubscriptionPaymentOverdue , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.payment.reminder | Bgultekin\CashierFastspring\Events\SubscriptionPaymentReminder , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.trial.reminder | Bgultekin\CashierFastspring\Events\SubscriptionTrialReminder , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
subscription.updated | Bgultekin\CashierFastspring\Events\SubscriptionUpdated , Bgultekin\CashierFastspring\Events\SubscriptionAny , Bgultekin\CashierFastspring\Events\Any |
To listen an event, you can register listeners in app/providers/EventServiceProvider.php
.
Single Charges
Not implemented yet. If you need it you can contribute to the package. Please check Contributing.
Invoices
In Fastspring, invoices are generated by Fastspring. You don't need to generate official or unofficial invoices. If you are using default webhook listeners, your invoices will be sync to your database. You can get invoices URL with the Invoice
model or over the Billable
trait.
Contributing
Thank you for considering contributing to the Cashier Fastspring. You can read the contribution guide lines issues to improve this package.
Credits
Cashier Fastspring package is developed by Bilal Gultekin over Taylor Otwell's Cashier package. You can see all contributors here.
License
Cashier Fastspring is open-sourced software licensed under the MIT license.
All versions of cashier-fastspring with dependencies
illuminate/database Version ~5.6
illuminate/support Version ~5.6
nesbot/carbon Version ~1.0
symfony/http-kernel Version ~2.7|~3.0|~4.0
guzzlehttp/guzzle Version ^6.0