bozboz / checkout
Installs: 1 566
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- illuminate/routing: 5.2.*
- illuminate/session: 5.2.*
- illuminate/support: 5.2.*
This package is auto-updated.
Last update: 2021-06-04 10:22:43 UTC
README
Define a series of interconnecting screens that plug together as part of a continuous process.
For examples of implementation look at these repos:
Setup
- Require the package in Composer, by running
composer require bozboz/checkout
- Add the service provider in app/config/app.php
Bozboz\Ecommerce\Checkout\Providers\CheckoutServiceProvider::class,
- Add the
Checkout
facade to the aliases array inin app/config/app.php
'Checkout' => Bozboz\Ecommerce\Checkout\Facades\Checkout::class,
Usage
- Register a new checkout process using the Checkout facade in
app/Http/routes.php
- Set a repository on the facade with the
using
method. The repository must implement theBozboz\Ecommerce\Checkout\CheckoutableRepository
interface and its purpose is to fetch the checkoutable instance. The instance must implement the Checkoutable interface. (The orders package has a default implementation to fetch the order instance from the session,Bozboz\Ecommerce\Orders\OrderRepository
). - On the returned object, call
add
to add screens. The add method takes 4 parameters:- The URL the screen will respond to
- The Screen class to use (resolved out the IoC container)
- An optional additional label to identify the screen, primarily used in the progress bar
- Route parameters (uses, as, before, etc.)
e.g.:
<?php Checkout::using('App\Ecommerce\Orders\OrderRepository')->register(['prefix' => 'checkout'], function($checkout) { $checkout->add('/', 'App\Screens\Start', 'Start'); $checkout->add('customer', 'App\Screens\CustomerDetails', 'Personal Info'); $checkout->add('address', 'App\Screens\AddressSelection', 'Addresses'); $checkout->add('delivery', 'App\Screens\ShippingSelection', 'Delivery'); $checkout->add('billing', 'App\Screens\IframeBilling', 'Payment'); $checkout->add('complete', 'App\Screens\OrderCompleted', 'Complete'); });
The above example will register the following URLs:
GET /checkout
POST /checkout
GET /checkout/customer
POST /checkout/customer
GET /checkout/address
POST /checkout/address
GET /checkout/delivery
POST /checkout/delivery
GET /checkout/billing
POST /checkout/billing
GET /checkout/complete
POST /checkout/complete
Screens
Screens must extend Bozboz\Ecommerce\Checkout\Screen
and must define a view() method.
Additionally, a canSkip
method is supported, which must return a boolean. If this method returns true
, the screen will be skipped in the process.
Processing the screen
To define a processing action (hit when the screen URL is POSTed to) the screen class must implement Bozboz\Ecommerce\Checkout\Processable
. This interface requires a process()
method be defined.
Providing this method does not throw an instance of Bozboz\Ecommerce\Checkout\ValidationException
, the checkout process will progress to the next screen upon completion.
Troubleshooting
When using test payments, if you get a 500 Internal Server Error upon clicking 'Take my money', try excluding the checkout/billing route from csrf protection.
In App\Http\Middleware\VerifyCsrfToken, add
protected $except = [ 'checkout/billing', ];