dev-master
9999999-dev https://github.com/twohill/silverstripe-pxpayPayment Express controller
BSD-3-Clause
The Requires
by Al Twohill
silverstripe paymentexpress
Payment Express controller
A module that integrates your controller with Payment Express., (*1)
Using composer, (*2)
composer require twohill/silverstripe-pxpay
BSD 3-Clause "New" or "Revised" License. See License, (*3)
Configure your PxPayment details in a config yml file. You can specify different settings for dev
or live
modes.
A useful option for doing this is to use your sandbox credentials when in dev
mode., (*4)
--- Only: environment: 'live' --- Twohill\PXPay\PxPaymentController: PxPayURL: https://sec.paymentexpress.com/pxaccess/pxpay.aspx PxPayUserId: MyUserID PxPayKey: xxxxxx --- Only: environment: 'dev' --- Twohill\PXPay\PxPaymentController: PxPayURL: https://sec.paymentexpress.com/pxaccess/pxpay.aspx PxPayUserId: MyUserID_dev PxPayKey: xxxxxx
Return the PxPaymentController
as the result of a payment method, (*5)
class MyPageController extends PageController { private static $allowed_actions = [ 'thankyou', 'pay_order', 'unsuccessful', ]; public function thankyou(HTTPRequest $request) { $content = ''; if ($request->getSession()->get('OrderID')) { $order = Order::get()->byID($request->getSession()->get('OrderID')); if ($order) { $payment = $order->Payment(); if ($payment && $payment->TxnId) { if ($payment->Processed) { $sendEmail = false; } else { $payment->Processed = true; $payment->write(); } } else { $this->redirect($this->Link('pay-order/submit')); } $content = $this->ThankYouForPayingContent; // From MyPage $db } $request->getSession()->clear("OrderID"); return $this->customise(new ArrayData([ 'Content' => DBField::create_field('HTMLFragment', $content), 'Form' => '' ])); } return $this->redirect($this->Link()); } /** * Process the payment * * @param HTTPRequest $request * @return PxPaymentController * @throws ValidationException */ public function pay_order(HTTPRequest $request) { // Load the payment details somehow $payment = null; if ($request->getSession()->get('OrderID')) { $order = Order::get()->byID($request->getSession()->get('OrderID')); if ($order) { $payment = new PxPayment(); $payment->TxnType = "Purchase"; $payment->MerchantReference = $order->InvoiceNumber; $payment->TxnData1 = $order->CompanyName; $payment->TxnData2 = $order->Address; $payment->TxnData3 = $order->City; $payment->EmailAddress = $order->Contact()->Email; $payment->AmountInput = $order->Total; $payment->CurrencyInput = "NZD"; $payment->InvoiceID = $order->ID; $payment->write(); } } } return new PxPaymentController($this, $request, $payment, $this->Link("thankyou"), $this->Link("unsuccessful")); } /** * Action when payment is unsuccessful. */ public function unsuccessful(HTTPRequest $request) { if ($request->getSession()->get('OrderID')) { $order = Order::get()->byID($request->getSession()->get('OrderID')); if ($order) { return $this->customise([ 'Content' => DBField::create_field('HTMLFragment', $this->UnsuccessfulContent), 'Form' => '' ]); } } return $this->redirect($this->Link()); } }
Bugs are tracked in the issues section of this repository. Before submitting an issue please read over existing issues to ensure yours is unique., (*6)
If the issue does look like a new bug:, (*7)
Please report security issues to the module maintainers directly. Please don't file security issues in the bugtracker., (*8)
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers., (*9)
Payment Express controller
BSD-3-Clause
silverstripe paymentexpress