Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 25 additions & 56 deletions src/Omnipay/WorldPayXML/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ class PurchaseRequest extends AbstractRequest

/**
* @var \Guzzle\Plugin\Cookie\CookiePlugin
*
* @access protected
*/
protected $cookiePlugin;

/**
* Get accept header
*
* @access public
* @return string
*/
public function getAcceptHeader()
Expand All @@ -42,9 +39,7 @@ public function getAcceptHeader()
* Set accept header
*
* @param string $value Accept header
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setAcceptHeader($value)
{
Expand All @@ -54,7 +49,6 @@ public function setAcceptHeader($value)
/**
* Get cookie plugin
*
* @access public
* @return \Guzzle\Plugin\Cookie\CookiePlugin
*/
public function getCookiePlugin()
Expand All @@ -65,7 +59,6 @@ public function getCookiePlugin()
/**
* Get installation
*
* @access public
* @return string
*/
public function getInstallation()
Expand All @@ -77,9 +70,7 @@ public function getInstallation()
* Set installation
*
* @param string $value Installation
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setInstallation($value)
{
Expand All @@ -89,7 +80,6 @@ public function setInstallation($value)
/**
* Get merchant
*
* @access public
* @return string
*/
public function getMerchant()
Expand All @@ -101,9 +91,7 @@ public function getMerchant()
* Set merchant
*
* @param string $value Merchant
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setMerchant($value)
{
Expand Down Expand Up @@ -134,7 +122,6 @@ public function setUsername($value)
/**
* Get pa response
*
* @access public
* @return string
*/
public function getPaResponse()
Expand All @@ -146,9 +133,7 @@ public function getPaResponse()
* Set pa response
*
* @param string $value Pa response
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setPaResponse($value)
{
Expand All @@ -158,7 +143,6 @@ public function setPaResponse($value)
/**
* Get password
*
* @access public
* @return string
*/
public function getPassword()
Expand All @@ -170,9 +154,7 @@ public function getPassword()
* Set password
*
* @param string $value Password
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setPassword($value)
{
Expand All @@ -182,7 +164,6 @@ public function setPassword($value)
/**
* Get redirect cookie
*
* @access public
* @return string
*/
public function getRedirectCookie()
Expand All @@ -194,9 +175,7 @@ public function getRedirectCookie()
* Set redirect cookie
*
* @param string $value Password
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setRedirectCookie($value)
{
Expand All @@ -206,7 +185,6 @@ public function setRedirectCookie($value)
/**
* Get redirect echo
*
* @access public
* @return string
*/
public function getRedirectEcho()
Expand All @@ -218,9 +196,7 @@ public function getRedirectEcho()
* Set redirect echo
*
* @param string $value Password
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setRedirectEcho($value)
{
Expand All @@ -230,7 +206,6 @@ public function setRedirectEcho($value)
/**
* Get session
*
* @access public
* @return string
*/
public function getSession()
Expand All @@ -242,9 +217,7 @@ public function getSession()
* Set session
*
* @param string $value Session
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setSession($value)
{
Expand All @@ -254,7 +227,6 @@ public function setSession($value)
/**
* Get term url
*
* @access public
* @return string
*/
public function getTermUrl()
Expand All @@ -266,9 +238,7 @@ public function getTermUrl()
* Set term url
*
* @param string $value Term url
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setTermUrl($value)
{
Expand All @@ -278,7 +248,6 @@ public function setTermUrl($value)
/**
* Get user agent header
*
* @access public
* @return string
*/
public function getUserAgentHeader()
Expand All @@ -290,9 +259,7 @@ public function getUserAgentHeader()
* Set user agent header
*
* @param string $value User agent header
*
* @access public
* @return void
* @return PurchaseRequest
*/
public function setUserAgentHeader($value)
{
Expand All @@ -319,7 +286,6 @@ public function getAppleToken()
/**
* Get data
*
* @access public
* @return \SimpleXMLElement
*/
public function getData()
Expand All @@ -338,7 +304,8 @@ public function getData()
$order->addAttribute('orderCode', $this->getTransactionId());
$order->addAttribute('installationId', $this->getInstallation());

$order->addChild('description', $this->getDescription());
$description = $this->getDescription() ? $this->getDescription() : 'Merchandise';
$order->addChild('description', $description);

$amount = $order->addChild('amount');
$amount->addAttribute('value', $this->getAmountInteger());
Expand Down Expand Up @@ -405,11 +372,13 @@ public function getData()
$address->addChild('street', $this->getCard()->getAddress1());
$address->addChild('postalCode', $this->getCard()->getPostcode());
$address->addChild('countryCode', $this->getCard()->getCountry());
}

$session = $payment->addChild('session');
$session->addAttribute('shopperIPAddress', $this->getClientIP());
$session->addAttribute('id', $this->getSession());
$session = $payment->addChild('session'); // Empty tag is valid but setting an empty ID attr isn't
if ($this->getClientIp() && $this->getSession()) {
$session->addAttribute('shopperIPAddress', $this->getClientIP());
$session->addAttribute('id', $this->getSession());
}
}

$paResponse = $this->getPaResponse();

Expand Down Expand Up @@ -446,8 +415,6 @@ public function getData()
* Send data
*
* @param \SimpleXMLElement $data Data
*
* @access public
* @return RedirectResponse
*/
public function sendData($data)
Expand Down Expand Up @@ -502,18 +469,20 @@ public function sendData($data)
->post($this->getEndpoint(), $headers, $xml)
->send();

return $this->response = new RedirectResponse(
$this,
$httpResponse->getBody()
);
if ($this->getCard()->getBrand() === 'apple') {
$this->response = new Response($this, $httpResponse->getBody());
} else {
$this->response = new RedirectResponse($this, $httpResponse->getBody());
}

return $this->response;
}

/**
* Get endpoint
*
* Returns endpoint depending on test mode
*
* @access protected
* @return string
*/
protected function getEndpoint()
Expand Down