My 2¢
on
Omnipay
Jeremy Shipman
"Oh, and can it do online payments please?"
Actors
Merchant
Gateway
Provider
Developer
Bank
Customer
Secure Payments By:
On-Site vs Off-Site
On Site
Off Site
$
$
Gateway Features
Purchase
Tokenisation
Rebilling
Notify
Refund
Authorise & Capture
(delayed purchase)
Void
Look up
SilverStripe Payment Module
Introducing: Omnipay
PHP 5.3+
Standardisation:
learn one code base
Easy support for multiple gateways
Well thought out
Stateless...
- Gateway Configuration
- Request Building
- Response Parsing
Composer
use Omnipay\Omnipay;
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('abc123');
$formData = [
'number' => '4242424242424242',
'expiryMonth' => '6',
'expiryYear' => '2016',
'cvv' => '123'
];
$response = $gateway->purchase([
'amount' => '10.00',
'currency' => 'USD',
'card' => $formData
])->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
SilverStripe - Omnipay
Payment DataObject
Messages / Logging
YAML _config
Off-Site Payment Handling
Form Field Generation
Exception Handling
PaymentAdmin
Payable DataExtension
silverstripe-framework
omnipay (PHP library)
silverstripe-omnipay (SS module)
gateway API
How it fits together
your website / module
---
Name: payment
---
Payment:
allowed_gateways:
- 'PayPal_Express'
parameters:
PayPal_Express:
username: 'example.username.test'
password: 'txjjllae802325'
signature: 'wk32hkimhacsdfa'
_config/payment.yml
$amount = $payable->Amount;
$currency = "NZD";
$payment = Payment::create()
->init("PxPayGateway", $amount, $currency);
$payment->write();
$response = PurchaseService::create($payment)
->setReturnUrl($this->Link())
->purchase($form->getData());
$response->redirect();
MyController.php
if($payment->isCaptured()){
$payable->Status = "Paid";
$payable->write();
$this->redirect('success');
}
$gateways = GatewayInfo::get_supported_gateways();
List Gateways
$factory = new GatewayFieldsFactory($gateway);
$fields = $factory->getFields();
Form Fields
Recap
"I want online payments"
Merchant
Developer
"SilverStripe + Omnipay!"
Merchant
Developer
"Give me dev account"
Developer
Gateway
Provider
$ composer require burnbright/silverstripe-omnipay
$ composer require burnbright/omnipay-poli
$ composer require vendor/omnipay-gateway
> |
End
Future
Omnipay 2
Authorise & Capture
Improve Administration
Tokenisation / Saved Cards