Hi @bummzack
Hi@bummzack
SilverShop
What happened• Rebranded as “SilverShop” • 2.0 was released in July 2016 • Current version is 2.1 • Mark Guinn retired as a Maintainer
Core-features• Shopping-Cart • Categories, Products, Variations • Checkout, either Single- or Multi-Step • Guest-Checkout • User-Accounts and Address-Book • Supports a wide range of payment service providers via Omnipay
Features added via modules• Stock-Management • Discounts and Coupons • Various Shipping-Methods • Product-Search • Colored-Variations • AJAX functionality
Why use SilverShop?
Seriously though…
An example
SilverStripe & Omnipay
The Omnipay Library• Framework agnostic payment library • Provides a single API for many different payment service providers • authorize, capture, purchase, refund, void • 100% unit-tested
The Omnipay Architecture• Payment API via Gateways • Request/Response ≠ HTTP-Request/Response • Omnipay is stateless
A simple example 1/3composer require omnipay/paypal
A simple example 1/3composer require omnipay/paypal
# purchase.php require_once 'vendor/autoload.php'; use Omnipay\Omnipay; …
A simple example 1/3composer require omnipay/paypal
# purchase.php require_once 'vendor/autoload.php'; use Omnipay\Omnipay; $gateway = Omnipay::create('PayPal_Express'); …
A simple example 1/3composer require omnipay/paypal
# purchase.php require_once 'vendor/autoload.php'; use Omnipay\Omnipay; $gateway = Omnipay::create('PayPal_Express'); $gateway->initialize([ 'username' => 'username.example.com', 'password' => '0123456789', 'signature' => 'AbUnchOFRandOMChaActeRS.muCHSiGnaTURe11101', 'testmode' => true]); …
A simple example 2/3# … continued $purchaseRequest = $gateway->purchase([ 'amount' => '10.00', 'currency' => 'USD', 'returnUrl' => 'https://shop.example.com/completePurchase.php', 'cancelUrl' => 'https://shop.example.com/cancelPurchase.php']); …
A simple example 2/3# … continued $purchaseRequest = $gateway->purchase([ 'amount' => '10.00', 'currency' => 'USD', 'returnUrl' => 'https://shop.example.com/completePurchase.php', 'cancelUrl' => 'https://shop.example.com/cancelPurchase.php']);
$purchaseResponse = $purchaseRequest->send(); if ($purchaseResponse->isRedirect()) { $purchaseResponse->redirect(); } else { echo $purchaseResponse->getMessage(); }
A simple example 3/3# completePurchase.php $completePurchaseRequest = $gateway->completePurchase([ 'amount' => '10.00', 'currency' => 'USD', 'returnUrl' => 'https://shop.example.com/completePurchase.php', 'cancelUrl' => 'https://shop.example.com/cancelPurchase.php']);
$completePurchaseResponse = $completePurchaseRequest->send(); if ($completePurchaseResponse->isSuccessful()) { echo 'Payment complete!'; } else { echo $completePurchaseResponse->getMessage(); }
The silverstripe-omnipay module
Features• Provides a SilverStripe specific wrapper for omnipay • Adds a persistence-layer (Payment DataObject) • Provides URL endpoints for off-site payments • Can be configured using the config API.
The architecture• You create instances of Payment and use PaymentServices
that operate on these Payments. • Services are commonly created through a ServiceFactory • Payment Services map to the Omnipay API:
authorize, capture, purchase, refund, void
A simple example 1/3composer require silverstripe/silverstripe-omnipay composer require omnipay/paypal
A simple example 1/3composer require silverstripe/silverstripe-omnipay composer require omnipay/paypal
# mysite/_config/payment.yml ---Name: payment-config---GatewayInfo: PayPal_Express: parameters: username: 'username.example.com' password: '0123456789' signature: 'AbUnchOFRandOMChaActeRS.muCHSiGnaTURe11101' testMode: true
A simple example 2/3private static $allowed_actions = [ 'purchase', 'completed', 'cancelled'];
A simple example 2/3private static $allowed_actions = [ 'purchase', 'completed', 'cancelled']; public function purchase(){ $payment = Payment::create() ->init('PayPal_Express', 10, 'USD') ->setSuccessUrl($this->Link('completed')) ->setFailureUrl($this->Link('cancelled')); …
A simple example 2/3private static $allowed_actions = [ 'purchase', 'completed', 'cancelled']; public function purchase(){ $payment = Payment::create() ->init('PayPal_Express', 10, 'USD') ->setSuccessUrl($this->Link('completed')) ->setFailureUrl($this->Link('cancelled')); $service = ServiceFactory::create()->getService( $payment, ServiceFactory::INTENT_PURCHASE); …
A simple example 2/3private static $allowed_actions = [ 'purchase', 'completed', 'cancelled']; public function purchase(){ $payment = Payment::create() ->init('PayPal_Express', 10, 'USD') ->setSuccessUrl($this->Link('completed')) ->setFailureUrl($this->Link('cancelled')); $service = ServiceFactory::create()->getService( $payment, ServiceFactory::INTENT_PURCHASE); $serviceResponse = $service->initiate(); return $serviceResponse->redirectOrRespond(); }
A simple example 3/3
https://shop.example.com/paymentendpoint/<hash>/complete
https://shop.example.com/mypaymentpage/completed
silverstripe-omnipay-ui module
Thanks!
Questions?