-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
use SilverStripe\Omnipay\Service\ServiceResponse; | ||
|
||
/** | ||
* Add specific response overwrites for WorldPay gateway responses. | ||
* This allows us to provide a templated response to a WorldPay | ||
* payment notification and auto redirect to the current site after | ||
* payment. | ||
* | ||
* If you need to accept payments via WorldPay and want to use the | ||
* custom payment response page, then you need to enable this extension | ||
* in your config.yml: | ||
* | ||
* SilverStripe\Omnipay\Service\PaymentService: | ||
* extensions: | ||
* - WorldPayResponseExtension | ||
* | ||
* If you would like to overwrite the default template (for example | ||
* to use your own styling, WPDISPLAY tags, etc) then add a | ||
* "WorldPayCallback.ss" file to the tempaltes directory in your | ||
* theme. | ||
* | ||
* @package silverstripe-omnipay | ||
* @subpackage extensions | ||
* @author Bummzack | ||
* @author Mo <[email protected]> | ||
*/ | ||
class WorldPayResponseExtension extends Extension | ||
{ | ||
public function updateServiceResponse($response) | ||
{ | ||
$payment = $response->getPayment(); | ||
|
||
// We only want to respond to the notification if we are using WorldPay | ||
if ($payment->Gateway !== 'WorldPay') { | ||
return; | ||
} | ||
|
||
// Ignore payments that aren't in the PendingPurchase state | ||
if ($payment->Status !== 'PendingPurchase') { | ||
return; | ||
} | ||
|
||
$omnipayResponse = $response->getOmnipayResponse(); | ||
|
||
if ($omnipayResponse !== null && !$response->isError()) { | ||
|
||
if ($omnipayResponse->isSuccessful()) { | ||
$return_url = Director::absoluteURL($payment->SuccessUrl, true); | ||
} else { | ||
$return_url = Director::absoluteURL($payment->FailureUrl, true); | ||
} | ||
|
||
$viewer = new SSViewer("WorldPayCallback"); | ||
$html = $viewer->process(ArrayData::create(array( | ||
"ReturnURL" => $return_url | ||
))); | ||
|
||
$response->setHttpResponse(new SS_HTTPResponse($html, 200)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Setting Up WorldPay payments | ||
|
||
In order to start taking payments with WorldPay you will need to | ||
create an account with [Worldpay](http://www.worldpay.com/). | ||
|
||
next you will need to install the Omnipay WorldPay libraries | ||
(ideally via composer): | ||
|
||
# composer require "omnipay/worldpay:~2.0" | ||
|
||
## Setup WorldPay on your install | ||
|
||
Once you have the WorldPay module installed, add the following | ||
to `mysite/_config/payment.yml` | ||
|
||
```` | ||
--- | ||
Name: payment | ||
--- | ||
Payment: | ||
allowed_gateways: | ||
- 'WorldPay' | ||
GatewayInfo: | ||
WorldPay: | ||
parameters: | ||
installationId: '1010618' | ||
callbackPassword: 'xyz' | ||
--- | ||
Except: | ||
environment: 'live' | ||
--- | ||
GatewayInfo: | ||
WorldPay: | ||
parameters: | ||
testMode: true | ||
--- | ||
Only: | ||
environment: 'live' | ||
--- | ||
GatewayInfo: | ||
WorldPay: | ||
parameters: | ||
callbackPassword: 'abc' | ||
```` | ||
|
||
The `installationId` will be provided by WorldPay when your account is | ||
setup or can be retrieved from the "Installations" screen of the [WorldPay Admin](https://secure.worldpay.com/sso/public/auth/login.html). | ||
|
||
The `callbackPassword` can be set in the WorldPay admin > Installations > Installation Adminiatration (using the 'Payment Response password' field). | ||
**Note** You can add different passwords for test and live environments. | ||
|
||
Additional supported settings can be found at the [omnipay-worldpay github page](https://github.com/thephpleague/omnipay-worldpay/blob/master/src/Gateway.php#L21). | ||
|
||
## Using a custom callback response | ||
|
||
If you want a custom callback response (so the user sees a styled page at | ||
the end of the payment process and is returned back to your site) you | ||
will need to enable the `WorldPayResponseExtension`. | ||
|
||
You can add the following to your `config.yml` to achieve this: | ||
|
||
```` | ||
SilverStripe\Omnipay\Service\PaymentService: | ||
extensions: | ||
- WorldPayResponseExtension | ||
```` | ||
|
||
If you want to customise the apperance of the response page, just copy | ||
the `WorldPayCallback.ss` template from this module and add it to your | ||
`templates` folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="refresh" content="2;url={$ReturnURL}" /> | ||
<title><%t WorldPayExtension.Processing "Processing" %></title> | ||
</head> | ||
|
||
<body> | ||
<div style="font-family:sans-serif;text-align:center;" class="payment-processing"> | ||
<h1><%t WorldPayExtension.Processing "Processing" %></h1> | ||
|
||
<p> | ||
<%t WorldPayExtension.RedirectingToStore "We are now redirecting you, if you are not redirected automatically then click the link below." %> | ||
</p> | ||
|
||
<p> | ||
<a href="{$ReturnURL}"><%t WorldPayExtension.ReturnToStore "Return To Merchant's Store" %></a> | ||
</p> | ||
|
||
<WPDISPLAY ITEM="banner"> | ||
</div> | ||
</body> | ||
</html> |