Skip to content

Commit

Permalink
Issue thephpleague#112 Support Sage Pay Form email notifications and …
Browse files Browse the repository at this point in the history
…gift aid
  • Loading branch information
judgej committed Oct 7, 2018
1 parent f5b6bbf commit 11fe46b
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 23 deletions.
11 changes: 11 additions & 0 deletions src/ConstantsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ interface ConstantsInterface
const SERVICE_TOKEN = 'directtoken';
const SERVICE_DIRECT3D = 'direct3dcallback';

/**
* 0 = Do not send either customer or vendor emails
* 1 = Send customer and vendor emails if addresses are provided
* 2 = Send vendor email but NOT the customer email
* If you do not supply this field, 1 is assumed and emails
* are sent if addresses are provided.
*/
const SEND_EMAIL_NONE = '0';
const SEND_EMAIL_BOTH = '1';
const SEND_EMAIL_VENDOR = '2';

//
// Then the response constants.
//
Expand Down
22 changes: 22 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,28 @@ public function getRelatedTransactionId()
return $this->getParameter('relatedTransactionId');
}

/**
* @return int static::ALLOW_GIFT_AID_YES or static::ALLOW_GIFT_AID_NO
*/
public function getAllowGiftAid()
{
return $this->getParameter('allowGiftAid');
}

/**
* This flag allows the gift aid acceptance box to appear for this transaction
* on the payment page. This only appears if your vendor account is Gift Aid enabled.
*
* Values defined in static::ALLOW_GIFT_AID_* constant.
*
* @param bool|int $allowGiftAid value that casts to boolean
* @return $this
*/
public function setAllowGiftAid($value)
{
$this->setParameter('allowGiftAid', $value);
}

/**
* Return the Response object, initialised with the parsed response data.
* @param array $data The data parsed from the response gateway body.
Expand Down
123 changes: 122 additions & 1 deletion src/Message/Form/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,39 @@ public function getCryptData()
$data = $this->getTokenData($data);
}

// TODO: lots more fields in here.
// Some parameers specific to Sage Pay Form..

if ($this->getCustomerName() !== null) {
$data['CustomerName'] = $this->getCustomerName();
}

if ($this->getVendorEmail() !== null) {
$data['VendorEmail'] = $this->getVendorEmail();
}

if ($this->getEmailMessage() !== null) {
$data['EmailMessage'] = $this->getEmailMessage();
}

if ($this->getAllowGiftAid() !== null) {
$data['AllowGiftAid'] = (bool)$this->getAllowGiftAid()
? static::ALLOW_GIFT_AID_YES : static::ALLOW_GIFT_AID_NO;
}

if ($this->getWebsite() !== null) {
$data['Website'] = $this->getWebsite();
}

if ($sendEmail = $this->getSendEmail() !== null) {
if ($sendEmail != static::SEND_EMAIL_NONE
&& $sendEmail != static::SEND_EMAIL_BOTH
&& $sendEmail != static::SEND_EMAIL_VENDOR
) {
$sendEmail = static::SEND_EMAIL_BOTH;
}

$data['SendEmail'] = $this->getSendEmail();
}

// TxType: only PAYMENT, DEFERRED or AUTHENTICATE

Expand Down Expand Up @@ -125,6 +157,8 @@ public function getCryptData()

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

if ($data['BillingCountry'] === 'US' && empty($data['BillingState'])
|| $data['DeliveryCountry'] === 'US' && empty($data['DeliveryState'])
Expand Down Expand Up @@ -218,4 +252,91 @@ public function getFailureUrl()
{
return $this->getParameter('failureUrl');
}

/**
* @param string|null $value Customer's name will be included in the confirmation emails
* @return $this
*/
public function setCustomerName($value)
{
return $this->setParameter('customerName', $value);
}

/**
* @return string|null
*/
public function getCustomerName()
{
return $this->getParameter('customerName');
}

/**
* @param string|null $value An email will be sent to this address when each transaction completes
* @return $this
*/
public function setVendorEmail($value)
{
return $this->setParameter('vendorEmail', $value);
}

/**
* @return string|null
*/
public function getVendorEmail()
{
return $this->getParameter('vendorEmail');
}

/**
* @param string|null $value 0, 1, or 2, see
* @return $this
*/
public function setSendEmail($value)
{
return $this->setParameter('sendEmail', $value);
}

/**
* @return string|null
*/
public function getSendEmail()
{
return $this->getParameter('sendEmail');
}

/**
* This message can be formatted using HTML, up to 1000 bytes.
*
* @param string|null $value A message to the customer, inserted into successful emails
* @return $this
*/
public function setEmailMessage($value)
{
return $this->setParameter('EmailMessage', $value);
}

/**
* @return string|null
*/
public function getEmailMessage()
{
return $this->getParameter('EmailMessage');
}

/**
* @param string|null $value
* @return $this
*/
public function setWebsite($value)
{
return $this->setParameter('website', $value);
}

/**
* @return string|null
*/
public function getWebsite()
{
return $this->getParameter('website');
}
}
11 changes: 11 additions & 0 deletions src/Message/Form/CompleteAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,25 @@ public function getData()
*/
public function sendData($data)
{
// The Response in the current namespace conflicts with
// the Response in the namespace one level down, but only
// for PHP 5.6. This alias works around it.

return $this->response = new GenericResponse($this, $data);
}

/**
* @return string The crypt set as an override for the query parameter.
*/
public function getCrypt()
{
return $this->getParameter('cryptx');
}

/**
* @param string $value If set, then used in preference to the current query parameter.
* @return $this
*/
public function setCrypt($value)
{
return $this->setParameter('cryptx', $value);
Expand Down
22 changes: 0 additions & 22 deletions src/Message/ServerAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,6 @@ protected function createResponse($data)
return $this->response = new ServerAuthorizeResponse($this, $data);
}

/**
* @return int static::ALLOW_GIFT_AID_YES or static::ALLOW_GIFT_AID_NO
*/
public function getAllowGiftAid()
{
return $this->getParameter('allowGiftAid');
}

/**
* This flag allows the gift aid acceptance box to appear for this transaction
* on the payment page. This only appears if your vendor account is Gift Aid enabled.
*
* Values defined in static::ALLOW_GIFT_AID_* constant.
*
* @param bool|int $allowGiftAid value that casts to boolean
* @return $this
*/
public function setAllowGiftAid($value)
{
$this->setParameter('allowGiftAid', $value);
}

/**
* The Server API allows Giftaid to be selected by the user.
* This turns the feature on and off.
Expand Down

0 comments on commit 11fe46b

Please sign in to comment.