Skip to content

Commit 11fe46b

Browse files
committed
Issue #112 Support Sage Pay Form email notifications and gift aid
1 parent f5b6bbf commit 11fe46b

File tree

5 files changed

+166
-23
lines changed

5 files changed

+166
-23
lines changed

src/ConstantsInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ interface ConstantsInterface
116116
const SERVICE_TOKEN = 'directtoken';
117117
const SERVICE_DIRECT3D = 'direct3dcallback';
118118

119+
/**
120+
* 0 = Do not send either customer or vendor emails
121+
* 1 = Send customer and vendor emails if addresses are provided
122+
* 2 = Send vendor email but NOT the customer email
123+
* If you do not supply this field, 1 is assumed and emails
124+
* are sent if addresses are provided.
125+
*/
126+
const SEND_EMAIL_NONE = '0';
127+
const SEND_EMAIL_BOTH = '1';
128+
const SEND_EMAIL_VENDOR = '2';
129+
119130
//
120131
// Then the response constants.
121132
//

src/Message/AbstractRequest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,28 @@ public function getRelatedTransactionId()
422422
return $this->getParameter('relatedTransactionId');
423423
}
424424

425+
/**
426+
* @return int static::ALLOW_GIFT_AID_YES or static::ALLOW_GIFT_AID_NO
427+
*/
428+
public function getAllowGiftAid()
429+
{
430+
return $this->getParameter('allowGiftAid');
431+
}
432+
433+
/**
434+
* This flag allows the gift aid acceptance box to appear for this transaction
435+
* on the payment page. This only appears if your vendor account is Gift Aid enabled.
436+
*
437+
* Values defined in static::ALLOW_GIFT_AID_* constant.
438+
*
439+
* @param bool|int $allowGiftAid value that casts to boolean
440+
* @return $this
441+
*/
442+
public function setAllowGiftAid($value)
443+
{
444+
$this->setParameter('allowGiftAid', $value);
445+
}
446+
425447
/**
426448
* Return the Response object, initialised with the parsed response data.
427449
* @param array $data The data parsed from the response gateway body.

src/Message/Form/AuthorizeRequest.php

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,39 @@ public function getCryptData()
9797
$data = $this->getTokenData($data);
9898
}
9999

100-
// TODO: lots more fields in here.
100+
// Some parameers specific to Sage Pay Form..
101+
102+
if ($this->getCustomerName() !== null) {
103+
$data['CustomerName'] = $this->getCustomerName();
104+
}
105+
106+
if ($this->getVendorEmail() !== null) {
107+
$data['VendorEmail'] = $this->getVendorEmail();
108+
}
109+
110+
if ($this->getEmailMessage() !== null) {
111+
$data['EmailMessage'] = $this->getEmailMessage();
112+
}
113+
114+
if ($this->getAllowGiftAid() !== null) {
115+
$data['AllowGiftAid'] = (bool)$this->getAllowGiftAid()
116+
? static::ALLOW_GIFT_AID_YES : static::ALLOW_GIFT_AID_NO;
117+
}
118+
119+
if ($this->getWebsite() !== null) {
120+
$data['Website'] = $this->getWebsite();
121+
}
122+
123+
if ($sendEmail = $this->getSendEmail() !== null) {
124+
if ($sendEmail != static::SEND_EMAIL_NONE
125+
&& $sendEmail != static::SEND_EMAIL_BOTH
126+
&& $sendEmail != static::SEND_EMAIL_VENDOR
127+
) {
128+
$sendEmail = static::SEND_EMAIL_BOTH;
129+
}
130+
131+
$data['SendEmail'] = $this->getSendEmail();
132+
}
101133

102134
// TxType: only PAYMENT, DEFERRED or AUTHENTICATE
103135

@@ -125,6 +157,8 @@ public function getCryptData()
125157

126158
// Two conditional checks on the "state" fields.
127159
// We don't check if it is a valid two-character state code.
160+
// Maybe this can be moved to the construction of the addresses
161+
// in AbstractRequest.
128162

129163
if ($data['BillingCountry'] === 'US' && empty($data['BillingState'])
130164
|| $data['DeliveryCountry'] === 'US' && empty($data['DeliveryState'])
@@ -218,4 +252,91 @@ public function getFailureUrl()
218252
{
219253
return $this->getParameter('failureUrl');
220254
}
255+
256+
/**
257+
* @param string|null $value Customer's name will be included in the confirmation emails
258+
* @return $this
259+
*/
260+
public function setCustomerName($value)
261+
{
262+
return $this->setParameter('customerName', $value);
263+
}
264+
265+
/**
266+
* @return string|null
267+
*/
268+
public function getCustomerName()
269+
{
270+
return $this->getParameter('customerName');
271+
}
272+
273+
/**
274+
* @param string|null $value An email will be sent to this address when each transaction completes
275+
* @return $this
276+
*/
277+
public function setVendorEmail($value)
278+
{
279+
return $this->setParameter('vendorEmail', $value);
280+
}
281+
282+
/**
283+
* @return string|null
284+
*/
285+
public function getVendorEmail()
286+
{
287+
return $this->getParameter('vendorEmail');
288+
}
289+
290+
/**
291+
* @param string|null $value 0, 1, or 2, see
292+
* @return $this
293+
*/
294+
public function setSendEmail($value)
295+
{
296+
return $this->setParameter('sendEmail', $value);
297+
}
298+
299+
/**
300+
* @return string|null
301+
*/
302+
public function getSendEmail()
303+
{
304+
return $this->getParameter('sendEmail');
305+
}
306+
307+
/**
308+
* This message can be formatted using HTML, up to 1000 bytes.
309+
*
310+
* @param string|null $value A message to the customer, inserted into successful emails
311+
* @return $this
312+
*/
313+
public function setEmailMessage($value)
314+
{
315+
return $this->setParameter('EmailMessage', $value);
316+
}
317+
318+
/**
319+
* @return string|null
320+
*/
321+
public function getEmailMessage()
322+
{
323+
return $this->getParameter('EmailMessage');
324+
}
325+
326+
/**
327+
* @param string|null $value
328+
* @return $this
329+
*/
330+
public function setWebsite($value)
331+
{
332+
return $this->setParameter('website', $value);
333+
}
334+
335+
/**
336+
* @return string|null
337+
*/
338+
public function getWebsite()
339+
{
340+
return $this->getParameter('website');
341+
}
221342
}

src/Message/Form/CompleteAuthorizeRequest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,25 @@ public function getData()
5050
*/
5151
public function sendData($data)
5252
{
53+
// The Response in the current namespace conflicts with
54+
// the Response in the namespace one level down, but only
55+
// for PHP 5.6. This alias works around it.
56+
5357
return $this->response = new GenericResponse($this, $data);
5458
}
5559

60+
/**
61+
* @return string The crypt set as an override for the query parameter.
62+
*/
5663
public function getCrypt()
5764
{
5865
return $this->getParameter('cryptx');
5966
}
6067

68+
/**
69+
* @param string $value If set, then used in preference to the current query parameter.
70+
* @return $this
71+
*/
6172
public function setCrypt($value)
6273
{
6374
return $this->setParameter('cryptx', $value);

src/Message/ServerAuthorizeRequest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ protected function createResponse($data)
6262
return $this->response = new ServerAuthorizeResponse($this, $data);
6363
}
6464

65-
/**
66-
* @return int static::ALLOW_GIFT_AID_YES or static::ALLOW_GIFT_AID_NO
67-
*/
68-
public function getAllowGiftAid()
69-
{
70-
return $this->getParameter('allowGiftAid');
71-
}
72-
73-
/**
74-
* This flag allows the gift aid acceptance box to appear for this transaction
75-
* on the payment page. This only appears if your vendor account is Gift Aid enabled.
76-
*
77-
* Values defined in static::ALLOW_GIFT_AID_* constant.
78-
*
79-
* @param bool|int $allowGiftAid value that casts to boolean
80-
* @return $this
81-
*/
82-
public function setAllowGiftAid($value)
83-
{
84-
$this->setParameter('allowGiftAid', $value);
85-
}
86-
8765
/**
8866
* The Server API allows Giftaid to be selected by the user.
8967
* This turns the feature on and off.

0 commit comments

Comments
 (0)