The aim of this module is to make it easy for developers to eaisly integrate the ability to pay for things with their SilverStripe application. There are many gateway options to choose from, and integrating with additional gateways has a structured approach that should be understandable. A high quality, simple to use payment module will help to boost the SilverStripe ecosystem, as it allows applications to be profitable.
This module is a complete rewrite of the past Payment module. It is not backwards-compatible. In a nutshell, it provides a thin wrapping of the PHP Omnipay payments library. To understand more about omnipay, see: https://github.com/adrianmacneil/omnipay
Composer is currently the only supported way to set up this module:
composer require burnbright/silverstripe-omnipay
You can configure gateway settings in your
mysite/_config/payment.yml file. Here you can select a list of allowed gateways, and separately set the gateway-specific settings.
You can also choose to enable file logging by setting
file_logging to 1.
Payment: allowedgateways: - 'PayPalExpress' - 'PaymentExpressPxPay' - 'Manual' parameters: PayPalExpress: username: 'example.username.test' password: 'txjjllae802325' signature: 'wk32hkimhacsdfa' PaymentExpress_PxPost: username: 'EXAMPLEUSER'
Payment: filelogging: 1 allowedgateways:
Payment: parameters: PayPalExpress: username: 'liveexample.test' password: 'livepassawe23' signature: 'laivfe23235235' PaymentExpressPxPost: username: 'LIVEUSER'
The SilverStripe documentation explains more about yaml config files.
In your application, you may want to allow users to choose between a few different payment gateways. This can be useful for users if their first attempt is declined.
$gateways = GatewayInfo::get_supported_gateways();
GatewayFieldsFactory helper class enables you to produce a list of appropriately configured form fields for the given gateway.
$factory = new GatewayFieldsFactory($gateway);
$fields = $factory->getFields();
If the gateway is off-site, then no credit-card fields will be returned.
Fields have also been appropriately grouped, incase you only want to retrieve the credit card related fields, for example.
Required fields can be configured in the yaml config file, as this information is unfortunately not provided by omnipay:
Payment: allowedgateways: - 'PaymentExpressPxPost' parameters: PaymentExpressPxPost: username: 'EXAMPLEUSER' password: '235llgwxle4tol23l' requiredfields: - 'issueNumber' - 'startMonth' - 'startYear' ```
Using function chaining, we can create and configure a new payment object, and submit a request to the chosen gateway. The response object has a
redirect function built in that will either redirect the user to the external gateway site, or to the given return url.
->init($gateway = "PxPayGateway", $amount = 100, $currency = "NZD")
Of course you don't need to chain all of these functions, as you may want to redirect somewhere else, or do some further setup.
After payment has been made, the user will be redirected to the given return url (or cancel url, if they cancelled).