From 50ccc2e0bbc13984fd0c643fe33a068d61adbc67 Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Fri, 4 Dec 2015 11:22:11 +0000 Subject: [PATCH 1/8] Addition of classes for all Worldpay interactions --- .idea/vagrant.xml | 7 + src/Omnipay/WorldPayXML/Gateway.php | 40 +++ .../WorldPayXML/Message/AbstractRequest.php | 268 ++++++++++++++++++ .../Message/AuthorisationRequest.php | 34 +++ .../Message/BackOfficeCodeRequest.php | 34 +++ .../WorldPayXML/Message/CancelRequest.php | 25 ++ .../WorldPayXML/Message/CaptureRequest.php | 58 ++++ .../Message/IncreaseAuthorisationRequest.php | 27 ++ .../WorldPayXML/Message/InquiryRequest.php | 24 ++ .../WorldPayXML/Message/ModifyRequest.php | 24 ++ .../WorldPayXML/Message/ModifyResponse.php | 58 ++++ src/Omnipay/WorldPayXML/Message/Observer.php | 22 ++ .../WorldPayXML/Message/PurchaseRequest.php | 221 ++------------- .../WorldPayXML/Message/RefundRequest.php | 32 +++ src/Omnipay/WorldPayXML/Message/Response.php | 38 ++- .../WorldPayXML/Message/VoidRequest.php | 34 +++ 16 files changed, 739 insertions(+), 207 deletions(-) create mode 100644 .idea/vagrant.xml create mode 100644 src/Omnipay/WorldPayXML/Message/AbstractRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/CancelRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/CaptureRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/InquiryRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/ModifyRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/ModifyResponse.php create mode 100644 src/Omnipay/WorldPayXML/Message/Observer.php create mode 100644 src/Omnipay/WorldPayXML/Message/RefundRequest.php create mode 100644 src/Omnipay/WorldPayXML/Message/VoidRequest.php diff --git a/.idea/vagrant.xml b/.idea/vagrant.xml new file mode 100644 index 0000000..a5aa786 --- /dev/null +++ b/.idea/vagrant.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Gateway.php b/src/Omnipay/WorldPayXML/Gateway.php index 62e7d2b..c34cc7d 100755 --- a/src/Omnipay/WorldPayXML/Gateway.php +++ b/src/Omnipay/WorldPayXML/Gateway.php @@ -293,4 +293,44 @@ public function purchase(array $parameters = array()) $parameters ); } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\WorldPayXML\Message\RefundRequest', $parameters); + } + + public function cancel(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\CancelRequest', $parameters); + } + + public function authorise(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\AuthorisationRequest', $parameters); + } + + public function backOfficeCode(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\BackOfficeCodeRequest', $parameters); + } + + public function capture(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\CaptureRequest', $parameters); + } + + public function inquiry(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\InquiryRequest', $parameters); + } + + public function increaseAuthorisation(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest', $parameters); + } + + public function void(array $parameters = []) + { + return $this->createRequest('Omnipay\WorldPayXML\Message\VoidRequest', $parameters); + } } diff --git a/src/Omnipay/WorldPayXML/Message/AbstractRequest.php b/src/Omnipay/WorldPayXML/Message/AbstractRequest.php new file mode 100644 index 0000000..aafb89c --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/AbstractRequest.php @@ -0,0 +1,268 @@ +getParameter('merchant'); + } + + /** + * Set merchant + * + * @param string $value Merchant + * + * @access public + * @return void + */ + public function setMerchant($value) + { + return $this->setParameter('merchant', $value); + } + + /** + * Get password + * + * @access public + * @return string + */ + public function getPassword() + { + return $this->getParameter('password'); + } + + /** + * Set password + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setPassword($value) + { + return $this->setParameter('password', $value); + } + + /** + * Get redirect cookie + * + * @access public + * @return string + */ + public function getRedirectCookie() + { + return $this->getParameter('redirect_cookie'); + } + + /** + * Set redirect cookie + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setRedirectCookie($value) + { + return $this->setParameter('redirect_cookie', $value); + } + + protected function getBase() + { + $data = new \SimpleXMLElement(''); + $data->addAttribute('version', self::VERSION); + $data->addAttribute('merchantCode', $this->getMerchant()); + + return $data; + } + + /** + * Get installation + * + * @access public + * @return string + */ + public function getInstallation() + { + return $this->getParameter('installation'); + } + + /** + * Set installation + * + * @param string $value Installation + * + * @access public + * @return void + */ + public function setInstallation($value) + { + return $this->setParameter('installation', $value); + } + + /** + * Send data + * + * @param \SimpleXMLElement $data Data + * + * @access public + * @return RedirectResponse + */ + public function sendData($data) + { + $implementation = new \DOMImplementation(); + + $dtd = $implementation->createDocumentType( + 'paymentService', + '-//WorldPay//DTD WorldPay PaymentService v1//EN', + 'http://dtd.worldpay.com/paymentService_v1.dtd' + ); + + $document = $implementation->createDocument(null, '', $dtd); + $document->encoding = 'utf-8'; + + $node = $document->importNode(dom_import_simplexml($data), true); + $document->appendChild($node); + + $authorisation = base64_encode( + $this->getMerchant() . ':' . $this->getPassword() + ); + + $headers = array( + 'Authorization' => 'Basic ' . $authorisation, + 'Content-Type' => 'text/xml; charset=utf-8' + ); + + $cookieJar = new ArrayCookieJar(); + + $redirectCookie = $this->getRedirectCookie(); + + if (!empty($redirectCookie)) { + $url = parse_url($this->getEndpoint()); + + $cookieJar->add( + new Cookie( + array( + 'domain' => $url['host'], + 'name' => 'machine', + 'path' => '/', + 'value' => $redirectCookie + ) + ) + ); + } + + $this->cookiePlugin = new CookiePlugin($cookieJar); + + $this->httpClient->addSubscriber($this->cookiePlugin); + + $xml = $document->saveXML(); + + $this->notify( + [ + 'request' => preg_replace( + '#\([0-9]{3,4})\<\/cvc\>#', + '***', + preg_replace( + '#\([0-9]{10,})\<\/cardNumber\>#', + '**** **** **** ****', + $xml + ) + ) + ] + ); + + $httpResponse = $this->httpClient + ->post($this->getEndpoint(), $headers, $xml) + ->send(); + + $this->notify(['response' => (string)$httpResponse->getBody()]); + + if ($this instanceof \Omnipay\WorldPayXML\Message\ModifyRequest && !($this instanceOf \Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest)) { + return $this->response = new ModifyResponse( + $this, + $httpResponse->getBody() + ); + } + + return $this->response = Response::make( + $this, + $httpResponse->getBody() + ); + } + + /** + * Get endpoint + * + * Returns endpoint depending on test mode + * + * @access protected + * @return string + */ + protected function getEndpoint() + { + if ($this->getTestMode()) { + return self::EP_HOST_TEST . self::EP_PATH; + } + + return self::EP_HOST_LIVE . self::EP_PATH; + } + + public function attach(Observer $observer) { + $this->observers[] = $observer; + } + + public function detach(Observer $observer) { + $this->observers = array_filter( + $this->observers, + function ($a) use ($observer) { + return (!($a === $observer)); + } + ); + } + + public function notify($data) { + foreach($this->observers as $observer) { + $observer->update($this, $data); + } + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + abstract public function getTransactionType(); +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php b/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php new file mode 100644 index 0000000..f098eac --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php @@ -0,0 +1,34 @@ +setParameter('authorisation', $value); + } + + public function getAuthorisation() + { + return $this->getParameter('authorisation'); + } + + public function getData() + { + $data = $this->getBase(); + $authorise = $data->modify->orderModification->addChild('authorise'); + $authorise->addAttribute('authorisationCode', $this->getAuthorisation()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::AUTHORISATION_CODE_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php b/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php new file mode 100644 index 0000000..17a2c61 --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php @@ -0,0 +1,34 @@ +setParameter('backOfficeCode', $value); + } + + public function getBackOfficeCode() + { + return $this->getParameter('backOfficeCode'); + } + + public function getData() + { + $data = $this->getBase(); + $addBackOfficeCode = $data->modify->orderModification->addChild('addBackOfficeCode'); + $addBackOfficeCode->addAttribute('backOfficeCode', $this->getBackOfficeCode()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::BACK_OFFICE_CODE_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/CancelRequest.php b/src/Omnipay/WorldPayXML/Message/CancelRequest.php new file mode 100644 index 0000000..e3ab976 --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/CancelRequest.php @@ -0,0 +1,25 @@ +getBase(); + $data->modify->orderModification->addChild('cancel'); + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::CANCEL_REQUEST; + } +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/CaptureRequest.php b/src/Omnipay/WorldPayXML/Message/CaptureRequest.php new file mode 100644 index 0000000..85a05da --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/CaptureRequest.php @@ -0,0 +1,58 @@ +setParameter('captureDayOfMonth', $value); + } + + public function getCaptureDayOfMonth() { + return $this->getParameter('captureDayOfMonth'); + } + + public function setCaptureMonth($value) { + return $this->setParameter('captureMonth', $value); + } + + public function getCaptureMonth() { + return $this->getParameter('captureMonth'); + } + + public function setCaptureYear($value) { + return $this->setParameter('captureYear', $value); + } + + public function getCaptureYear() { + return $this->getParameter('captureYear'); + } + + public function getData() + { + $data = $this->getBase(); + $capture = $data->modify->orderModification->addChild('capture'); + $date = $capture->addChild('date'); + $date->addAttribute('dayOfMonth', $this->getCaptureDayOfMonth()); + $date->addAttribute('month', $this->getCaptureMonth()); + $date->addAttribute('year', $this->getCaptureYear()); + $amount = $capture->addChild('amount'); + $amount->addAttribute('value', $this->getAmountInteger()); + $amount->addAttribute('currencyCode', $this->getCurrency()); + $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); + $amount->addAttribute('debitCreditIndicator', $this->getDebitCreditIndicator()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::CAPTURE_REQUEST; + } +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php b/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php new file mode 100644 index 0000000..593af7f --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php @@ -0,0 +1,27 @@ +getBase(); + $authorise = $data->modify->orderModification->addChild('increaseAuthorisation'); + $amount = $authorise->addChild('amount'); + $amount->addAttribute('value', $this->getAmountInteger()); + $amount->addAttribute('currencyCode', $this->getCurrency()); + $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::INCREASE_AUTHORISATION_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/InquiryRequest.php b/src/Omnipay/WorldPayXML/Message/InquiryRequest.php new file mode 100644 index 0000000..6cb3e10 --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/InquiryRequest.php @@ -0,0 +1,24 @@ +getBase(); + $inquiry = $data->addChild('inquiry'); + $orderInquiry = $inquiry->addChild('orderInquiry'); + $orderInquiry->addAttribute('orderCode', $this->getTransactionId()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::INQUIRY_REQUEST; + } +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/ModifyRequest.php b/src/Omnipay/WorldPayXML/Message/ModifyRequest.php new file mode 100644 index 0000000..b43b4b7 --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/ModifyRequest.php @@ -0,0 +1,24 @@ +setParameter('debitCreditIndicator', $value); + } + + public function getDebitCreditIndicator() { + return $this->getParameter('debitCreditIndicator'); + } + + protected function getBase() { + $data = parent::getBase(); + $modify = $data->addChild('modify'); + $orderModification = $modify->addChild('orderModification'); + $orderModification->addAttribute('orderCode', $this->getTransactionId()); + + return $data; + } +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/ModifyResponse.php b/src/Omnipay/WorldPayXML/Message/ModifyResponse.php new file mode 100644 index 0000000..c22c7ad --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/ModifyResponse.php @@ -0,0 +1,58 @@ +request = $request; + + if (empty($data)) { + throw new InvalidResponseException(); + } + + $responseDom = new DOMDocument; + $responseDom->loadXML($data); + + $this->data = simplexml_import_dom( + $responseDom->documentElement->firstChild + ); + } + + /** + * Get is successful + * + * @access public + * @return boolean + */ + public function isSuccessful() + { + if (isset($this->data->ok)) { + return true; + } + + return false; + } + + public function getMessage() + { + if ($this->isSuccessful()) { + return 'SUCCESS'; + } + + return (string)$this->data->error; + } +} \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/Observer.php b/src/Omnipay/WorldPayXML/Message/Observer.php new file mode 100644 index 0000000..ec956c5 --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/Observer.php @@ -0,0 +1,22 @@ +cookiePlugin; } - /** - * Get installation - * - * @access public - * @return string - */ - public function getInstallation() - { - return $this->getParameter('installation'); - } - - /** - * Set installation - * - * @param string $value Installation - * - * @access public - * @return void - */ - public function setInstallation($value) - { - return $this->setParameter('installation', $value); - } - - /** - * Get merchant - * - * @access public - * @return string - */ - public function getMerchant() - { - return $this->getParameter('merchant'); - } - - /** - * Set merchant - * - * @param string $value Merchant - * - * @access public - * @return void - */ - public function setMerchant($value) - { - return $this->setParameter('merchant', $value); - } - /** * Get pa response * @@ -134,54 +75,6 @@ public function setPaResponse($value) return $this->setParameter('pa_response', $value); } - /** - * Get password - * - * @access public - * @return string - */ - public function getPassword() - { - return $this->getParameter('password'); - } - - /** - * Set password - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setPassword($value) - { - return $this->setParameter('password', $value); - } - - /** - * Get redirect cookie - * - * @access public - * @return string - */ - public function getRedirectCookie() - { - return $this->getParameter('redirect_cookie'); - } - - /** - * Set redirect cookie - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setRedirectCookie($value) - { - return $this->setParameter('redirect_cookie', $value); - } - /** * Get redirect echo * @@ -289,13 +182,14 @@ public function getData() $this->validate('amount', 'card'); $this->getCard()->validate(); - $data = new \SimpleXMLElement(''); - $data->addAttribute('version', self::VERSION); - $data->addAttribute('merchantCode', $this->getMerchant()); + $data = $this->getBase(); $order = $data->addChild('submit')->addChild('order'); $order->addAttribute('orderCode', $this->getTransactionId()); - $order->addAttribute('installationId', $this->getInstallation()); + $installationId = $this->getInstallation(); + if (!empty($installationId)) { + $order->addAttribute('installationId', $installationId); + } $order->addChild('description', $this->getDescription()); @@ -346,9 +240,14 @@ public function getData() $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()); + $clientIp = $this->getClientIP(); + $sessionId = $this->getSession(); + + if (!empty($clientIp) && !empty($sessionId)) { + $session = $payment->addChild('session'); + $session->addAttribute('shopperIPAddress', $clientIp); + $session->addAttribute('id', $sessionId); + } $paResponse = $this->getPaResponse(); @@ -368,6 +267,16 @@ public function getData() ); } + $shippingAddress = $order->addChild('shippingAddress'); + $address = $shippingAddress->addChild('address'); + $address->addChild('firstName', $this->getCard()->getShippingFirstName()); + $address->addChild('lastName', $this->getCard()->getShippingLastName()); + $address->addChild('street', $this->getCard()->getShippingAddress1()); + $address->addChild('postalCode', $this->getCard()->getShippingPostcode()); + $address->addChild('city', $this->getCard()->getShippingCity()); + $address->addChild('countryCode', $this->getCard()->getShippingCountry()); + $address->addChild('telephoneNumber', $this->getCard()->getshippingPhone()); + $browser = $shopper->addChild('browser'); $browser->addChild('acceptHeader', $this->getAcceptHeader()); $browser->addChild('userAgentHeader', $this->getUserAgentHeader()); @@ -382,87 +291,11 @@ public function getData() } /** - * Send data - * - * @param \SimpleXMLElement $data Data - * - * @access public - * @return RedirectResponse + * Return a value to indicate the transaction type. + * @return integer */ - public function sendData($data) + public function getTransactionType() { - $implementation = new \DOMImplementation(); - - $dtd = $implementation->createDocumentType( - 'paymentService', - '-//WorldPay//DTD WorldPay PaymentService v1//EN', - 'http://dtd.worldpay.com/paymentService_v1.dtd' - ); - - $document = $implementation->createDocument(null, '', $dtd); - $document->encoding = 'utf-8'; - - $node = $document->importNode(dom_import_simplexml($data), true); - $document->appendChild($node); - - $authorisation = base64_encode( - $this->getMerchant() . ':' . $this->getPassword() - ); - - $headers = array( - 'Authorization' => 'Basic ' . $authorisation, - 'Content-Type' => 'text/xml; charset=utf-8' - ); - - $cookieJar = new ArrayCookieJar(); - - $redirectCookie = $this->getRedirectCookie(); - - if (!empty($redirectCookie)) { - $url = parse_url($this->getEndpoint()); - - $cookieJar->add( - new Cookie( - array( - 'domain' => $url['host'], - 'name' => 'machine', - 'path' => '/', - 'value' => $redirectCookie - ) - ) - ); - } - - $this->cookiePlugin = new CookiePlugin($cookieJar); - - $this->httpClient->addSubscriber($this->cookiePlugin); - - $xml = $document->saveXML(); - - $httpResponse = $this->httpClient - ->post($this->getEndpoint(), $headers, $xml) - ->send(); - - return $this->response = new RedirectResponse( - $this, - $httpResponse->getBody() - ); - } - - /** - * Get endpoint - * - * Returns endpoint depending on test mode - * - * @access protected - * @return string - */ - protected function getEndpoint() - { - if ($this->getTestMode()) { - return self::EP_HOST_TEST . self::EP_PATH; - } - - return self::EP_HOST_LIVE . self::EP_PATH; + return static::PAYMENT_REQUEST; } } diff --git a/src/Omnipay/WorldPayXML/Message/RefundRequest.php b/src/Omnipay/WorldPayXML/Message/RefundRequest.php new file mode 100644 index 0000000..0c628ec --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/RefundRequest.php @@ -0,0 +1,32 @@ +getBase(); + $refund = $data->modify->orderModification->addChild('refund'); + $amount = $refund->addChild('amount'); + $amount->addAttribute('value', $this->getAmountInteger()); + $amount->addAttribute('currencyCode', $this->getCurrency()); + $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); + $amount->addAttribute('debitCreditIndicator', $this->getDebitCreditIndicator()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::REFUND_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/Response.php b/src/Omnipay/WorldPayXML/Message/Response.php index 0cfb834..eb0bb52 100755 --- a/src/Omnipay/WorldPayXML/Message/Response.php +++ b/src/Omnipay/WorldPayXML/Message/Response.php @@ -12,6 +12,25 @@ */ class Response extends AbstractResponse { + + public static function make(RequestInterface $request, $data) { + if (empty($data)) { + throw new InvalidResponseException(); + } + + $responseDom = new DOMDocument; + $responseDom->loadXML($data); + + $xmlData = simplexml_import_dom( + $responseDom->documentElement->firstChild->firstChild + ); + + if ($xmlData->requestInfo) { + return new RedirectResponse($request, $xmlData); + } else { + return new Response($request, $xmlData); + } + } /** * Constructor * @@ -24,16 +43,7 @@ public function __construct(RequestInterface $request, $data) { $this->request = $request; - if (empty($data)) { - throw new InvalidResponseException(); - } - - $responseDom = new DOMDocument; - $responseDom->loadXML($data); - - $this->data = simplexml_import_dom( - $responseDom->documentElement->firstChild->firstChild - ); + $this->data = $data; } /** @@ -123,10 +133,12 @@ public function getMessage() */ public function getTransactionReference() { - $attributes = $this->data->attributes(); + if ($this->data instanceof \SimpleXMLElement) { + $attributes = $this->data->attributes(); - if (isset($attributes['orderCode'])) { - return $attributes['orderCode']; + if (isset($attributes['orderCode'])) { + return $attributes['orderCode']; + } } } diff --git a/src/Omnipay/WorldPayXML/Message/VoidRequest.php b/src/Omnipay/WorldPayXML/Message/VoidRequest.php new file mode 100644 index 0000000..987086a --- /dev/null +++ b/src/Omnipay/WorldPayXML/Message/VoidRequest.php @@ -0,0 +1,34 @@ +getBase(); + $void = $data->modify->orderModification->addChild('cancelOrRefund'); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::VOID_REQUEST; + } +} From 2f8d5805123e3836e5f11e246af52addaee8e401 Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Wed, 9 Dec 2015 12:13:13 +0000 Subject: [PATCH 2/8] Addition of Modification and Inquiry commands --- .idea/vagrant.xml | 7 - src/Omnipay/WorldPayXML/Gateway.php | 101 ++- .../WorldPayXML/Message/AbstractRequest.php | 605 ++++++++++-------- .../Message/AuthorisationRequest.php | 73 ++- .../Message/BackOfficeCodeRequest.php | 74 ++- .../WorldPayXML/Message/CancelRequest.php | 48 +- .../WorldPayXML/Message/CaptureRequest.php | 88 +-- .../Message/IncreaseAuthorisationRequest.php | 53 +- .../WorldPayXML/Message/InquiryRequest.php | 51 +- .../WorldPayXML/Message/ModifyRequest.php | 60 +- .../WorldPayXML/Message/ModifyResponse.php | 128 ++-- src/Omnipay/WorldPayXML/Message/Observer.php | 21 +- .../WorldPayXML/Message/PurchaseRequest.php | 30 +- .../WorldPayXML/Message/RedirectResponse.php | 12 +- .../WorldPayXML/Message/RefundRequest.php | 10 +- src/Omnipay/WorldPayXML/Message/Response.php | 61 +- .../WorldPayXML/Message/VoidRequest.php | 7 +- tests/Omnipay/WorldPayXML/GatewayTest.php | 189 +++++- .../WorldPayXML/Message/ResponseTest.php | 187 +++++- .../WorldPayXML/Mock/AuthorisationSuccess.txt | 11 + .../Mock/BackOfficeCodeSuccess.txt | 11 + .../WorldPayXML/Mock/CancelSuccess.txt | 11 + .../WorldPayXML/Mock/CaptureFailure.txt | 11 + .../WorldPayXML/Mock/CaptureSuccess.txt | 11 + .../Mock/IncreaseAuthorisationFailure.txt | 11 + .../Mock/IncreaseAuthorisationSuccess.txt | 11 + .../WorldPayXML/Mock/InquiryFailure.txt | 11 + .../WorldPayXML/Mock/InquirySuccess.txt | 11 + .../WorldPayXML/Mock/PurchaseReferral.txt | 11 + .../WorldPayXML/Mock/RefundFailure.txt | 11 + .../WorldPayXML/Mock/RefundSuccess.txt | 11 + .../Omnipay/WorldPayXML/Mock/VoidSuccess.txt | 11 + 32 files changed, 1374 insertions(+), 574 deletions(-) delete mode 100644 .idea/vagrant.xml create mode 100755 tests/Omnipay/WorldPayXML/Mock/AuthorisationSuccess.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/BackOfficeCodeSuccess.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/CancelSuccess.txt create mode 100644 tests/Omnipay/WorldPayXML/Mock/CaptureFailure.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/CaptureSuccess.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationFailure.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationSuccess.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/InquiryFailure.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/InquirySuccess.txt create mode 100644 tests/Omnipay/WorldPayXML/Mock/PurchaseReferral.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/RefundFailure.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/RefundSuccess.txt create mode 100755 tests/Omnipay/WorldPayXML/Mock/VoidSuccess.txt diff --git a/.idea/vagrant.xml b/.idea/vagrant.xml deleted file mode 100644 index a5aa786..0000000 --- a/.idea/vagrant.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Gateway.php b/src/Omnipay/WorldPayXML/Gateway.php index c34cc7d..a2c36a0 100755 --- a/src/Omnipay/WorldPayXML/Gateway.php +++ b/src/Omnipay/WorldPayXML/Gateway.php @@ -7,7 +7,8 @@ /** * WorldPay XML Class * - * @link http://www.worldpay.com/support/bg/xml/kb/dxml_inv.pdf + * @link http://support.worldpay.com/support/kb/bg/pdf/bgxmldirect.pdf + * http://support.worldpay.com/support/kb/gg/pdf/omoi.pdf */ class Gateway extends AbstractGateway { @@ -30,12 +31,12 @@ public function getName() */ public function getDefaultParameters() { - return array( + return [ 'installation' => '', - 'merchant' => '', - 'password' => '', - 'testMode' => false, - ); + 'merchant' => '', + 'password' => '', + 'testMode' => false, + ]; } /** @@ -59,7 +60,7 @@ public function getAcceptHeader() */ public function setAcceptHeader($value) { - return $this->setParameter('acceptHeader', $value); + $this->setParameter('acceptHeader', $value); } /** @@ -83,7 +84,7 @@ public function getInstallation() */ public function setInstallation($value) { - return $this->setParameter('installation', $value); + $this->setParameter('installation', $value); } /** @@ -107,7 +108,7 @@ public function getMerchant() */ public function setMerchant($value) { - return $this->setParameter('merchant', $value); + $this->setParameter('merchant', $value); } /** @@ -131,7 +132,7 @@ public function getPaResponse() */ public function setPaResponse($value) { - return $this->setParameter('pa_response', $value); + $this->setParameter('pa_response', $value); } /** @@ -155,7 +156,7 @@ public function getPassword() */ public function setPassword($value) { - return $this->setParameter('password', $value); + $this->setParameter('password', $value); } /** @@ -179,7 +180,7 @@ public function getRedirectCookie() */ public function setRedirectCookie($value) { - return $this->setParameter('redirect_cookie', $value); + $this->setParameter('redirect_cookie', $value); } /** @@ -203,7 +204,7 @@ public function getRedirectEcho() */ public function setRedirectEcho($value) { - return $this->setParameter('redirect_echo', $value); + $this->setParameter('redirect_echo', $value); } /** @@ -227,7 +228,7 @@ public function getSession() */ public function setSession($value) { - return $this->setParameter('session', $value); + $this->setParameter('session', $value); } /** @@ -251,7 +252,7 @@ public function getUserAgentHeader() */ public function setUserAgentHeader($value) { - return $this->setParameter('userAgentHeader', $value); + $this->setParameter('userAgentHeader', $value); } /** @@ -275,7 +276,7 @@ public function getUserIP() */ public function setUserIP($value) { - return $this->setParameter('userIP', $value); + $this->setParameter('userIP', $value); } /** @@ -286,7 +287,7 @@ public function setUserIP($value) * @access public * @return \Omnipay\WorldPayXML\Message\PurchaseRequest */ - public function purchase(array $parameters = array()) + public function purchase(array $parameters = []) { return $this->createRequest( '\Omnipay\WorldPayXML\Message\PurchaseRequest', @@ -294,41 +295,105 @@ public function purchase(array $parameters = array()) ); } - public function refund(array $parameters = array()) + /** + * Refund + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\RefundRequest + */ + public function refund(array $parameters = []) { return $this->createRequest('\Omnipay\WorldPayXML\Message\RefundRequest', $parameters); } + /** + * Cancel + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\CancelRequest + */ public function cancel(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\CancelRequest', $parameters); } + /** + * Authorise + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\AuthorisationRequest + */ public function authorise(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\AuthorisationRequest', $parameters); } + /** + * Backoffice Code + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\BackOfficeCodeRequest + */ public function backOfficeCode(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\BackOfficeCodeRequest', $parameters); } + /** + * Capture + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\CaptureRequest + */ public function capture(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\CaptureRequest', $parameters); } + /** + * Inquiry + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\InquiryRequest + */ public function inquiry(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\InquiryRequest', $parameters); } + /** + * Increase Authorisation + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest + */ public function increaseAuthorisation(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest', $parameters); } + /** + * Void + * + * @param array $parameters Parameters + * + * @access public + * @return \Omnipay\WorldPayXML\Message\VoidRequest + */ public function void(array $parameters = []) { return $this->createRequest('Omnipay\WorldPayXML\Message\VoidRequest', $parameters); diff --git a/src/Omnipay/WorldPayXML/Message/AbstractRequest.php b/src/Omnipay/WorldPayXML/Message/AbstractRequest.php index aafb89c..f2d0cd1 100644 --- a/src/Omnipay/WorldPayXML/Message/AbstractRequest.php +++ b/src/Omnipay/WorldPayXML/Message/AbstractRequest.php @@ -1,268 +1,351 @@ getParameter('merchant'); - } - - /** - * Set merchant - * - * @param string $value Merchant - * - * @access public - * @return void - */ - public function setMerchant($value) - { - return $this->setParameter('merchant', $value); - } - - /** - * Get password - * - * @access public - * @return string - */ - public function getPassword() - { - return $this->getParameter('password'); - } - - /** - * Set password - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setPassword($value) - { - return $this->setParameter('password', $value); - } - - /** - * Get redirect cookie - * - * @access public - * @return string - */ - public function getRedirectCookie() - { - return $this->getParameter('redirect_cookie'); - } - - /** - * Set redirect cookie - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setRedirectCookie($value) - { - return $this->setParameter('redirect_cookie', $value); - } - - protected function getBase() - { - $data = new \SimpleXMLElement(''); - $data->addAttribute('version', self::VERSION); - $data->addAttribute('merchantCode', $this->getMerchant()); - - return $data; - } - - /** - * Get installation - * - * @access public - * @return string - */ - public function getInstallation() - { - return $this->getParameter('installation'); - } - - /** - * Set installation - * - * @param string $value Installation - * - * @access public - * @return void - */ - public function setInstallation($value) - { - return $this->setParameter('installation', $value); - } - - /** - * Send data - * - * @param \SimpleXMLElement $data Data - * - * @access public - * @return RedirectResponse - */ - public function sendData($data) - { - $implementation = new \DOMImplementation(); - - $dtd = $implementation->createDocumentType( - 'paymentService', - '-//WorldPay//DTD WorldPay PaymentService v1//EN', - 'http://dtd.worldpay.com/paymentService_v1.dtd' - ); - - $document = $implementation->createDocument(null, '', $dtd); - $document->encoding = 'utf-8'; - - $node = $document->importNode(dom_import_simplexml($data), true); - $document->appendChild($node); - - $authorisation = base64_encode( - $this->getMerchant() . ':' . $this->getPassword() - ); - - $headers = array( - 'Authorization' => 'Basic ' . $authorisation, - 'Content-Type' => 'text/xml; charset=utf-8' - ); - - $cookieJar = new ArrayCookieJar(); - - $redirectCookie = $this->getRedirectCookie(); - - if (!empty($redirectCookie)) { - $url = parse_url($this->getEndpoint()); - - $cookieJar->add( - new Cookie( - array( - 'domain' => $url['host'], - 'name' => 'machine', - 'path' => '/', - 'value' => $redirectCookie - ) - ) - ); - } - - $this->cookiePlugin = new CookiePlugin($cookieJar); - - $this->httpClient->addSubscriber($this->cookiePlugin); - - $xml = $document->saveXML(); - - $this->notify( - [ - 'request' => preg_replace( - '#\([0-9]{3,4})\<\/cvc\>#', - '***', - preg_replace( - '#\([0-9]{10,})\<\/cardNumber\>#', - '**** **** **** ****', - $xml - ) - ) - ] - ); - - $httpResponse = $this->httpClient - ->post($this->getEndpoint(), $headers, $xml) - ->send(); - - $this->notify(['response' => (string)$httpResponse->getBody()]); - - if ($this instanceof \Omnipay\WorldPayXML\Message\ModifyRequest && !($this instanceOf \Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest)) { - return $this->response = new ModifyResponse( - $this, - $httpResponse->getBody() - ); - } - - return $this->response = Response::make( - $this, - $httpResponse->getBody() - ); - } - - /** - * Get endpoint - * - * Returns endpoint depending on test mode - * - * @access protected - * @return string - */ - protected function getEndpoint() - { - if ($this->getTestMode()) { - return self::EP_HOST_TEST . self::EP_PATH; - } - - return self::EP_HOST_LIVE . self::EP_PATH; - } - - public function attach(Observer $observer) { - $this->observers[] = $observer; - } - - public function detach(Observer $observer) { - $this->observers = array_filter( - $this->observers, - function ($a) use ($observer) { - return (!($a === $observer)); - } - ); - } - - public function notify($data) { - foreach($this->observers as $observer) { - $observer->update($this, $data); - } - } - - /** - * Return a value to indicate the transaction type. - * @return integer - */ - abstract public function getTransactionType(); -} \ No newline at end of file +/** + * Class AbstractRequest + * @package Omnipay\WorldPayXML\Message + */ +abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest +{ + /** + * The base URL for the live service. + */ + const EP_HOST_LIVE = 'https://secure.worldpay.com'; + + /** + * The base URL for the sandbox service. + */ + const EP_HOST_TEST = 'https://secure-test.worldpay.com'; + + /** + * The service URI + */ + const EP_PATH = '/jsp/merchant/xml/paymentService.jsp'; + + /** + * The curent Worldpay XML APi version. + */ + const VERSION = '1.4'; + + /** + * Constants used to indicate the type of request being made. + */ + + /** + * Payment request + */ + const PAYMENT_REQUEST = 1; + + /** + * Payment modification + */ + const PAYMENT_MODIFY = 2; + + /** + * Cancel request + */ + const CANCEL_REQUEST = 3; + + /** + * Capture request + */ + const CAPTURE_REQUEST = 4; + + /** + * Refund request + */ + const REFUND_REQUEST = 5; + + /** + * Backoffice code request + */ + const BACK_OFFICE_CODE_REQUEST = 6; + + /** + * Authorisation code request + */ + const AUTHORISATION_CODE_REQUEST = 7; + + /** + * Inquiry request + */ + const INQUIRY_REQUEST = 8; + + /** + * Increase Authorisation request + */ + const INCREASE_AUTHORISATION_REQUEST = 9; + + /** + * Void (Cancel or Refund dependant on current payment status) request. + */ + const VOID_REQUEST = 10; + + /** + * Observers. Used to report requests and responses to. + * + * @var array + */ + private $observers = []; + + /** + * Get merchant + * + * @access public + * @return string + */ + public function getMerchant() + { + return $this->getParameter('merchant'); + } + + /** + * Set merchant + * + * @param string $value Merchant + * + * @access public + * @return void + */ + public function setMerchant($value) + { + $this->setParameter('merchant', $value); + } + + /** + * Get password + * + * @access public + * @return string + */ + public function getPassword() + { + return $this->getParameter('password'); + } + + /** + * Set password + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setPassword($value) + { + $this->setParameter('password', $value); + } + + /** + * Get redirect cookie + * + * @access public + * @return string + */ + public function getRedirectCookie() + { + return $this->getParameter('redirect_cookie'); + } + + /** + * Set redirect cookie + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setRedirectCookie($value) + { + $this->setParameter('redirect_cookie', $value); + } + + /** + * Set up the base SimpleXMLElelment for the request with items common to all requests. + * + * @return \SimpleXMLElement + */ + protected function getBase() + { + $data = new \SimpleXMLElement(''); + $data->addAttribute('version', self::VERSION); + $data->addAttribute('merchantCode', $this->getMerchant()); + + return $data; + } + + /** + * Get installation + * + * @access public + * @return string + */ + public function getInstallation() + { + return $this->getParameter('installation'); + } + + /** + * Set installation + * + * @param string $value Installation + * + * @access public + * @return void + */ + public function setInstallation($value) + { + $this->setParameter('installation', $value); + } + + /** + * Send data + * + * @param \SimpleXMLElement $data Data + * + * @access public + * @return \Omnipay\Common\Message\ResponseInterface + */ + public function sendData($data) + { + $implementation = new \DOMImplementation(); + + $dtd = $implementation->createDocumentType( + 'paymentService', + '-//WorldPay//DTD WorldPay PaymentService v1//EN', + 'http://dtd.worldpay.com/paymentService_v1.dtd' + ); + + $document = $implementation->createDocument(null, '', $dtd); + $document->encoding = 'utf-8'; + + $node = $document->importNode(dom_import_simplexml($data), true); + $document->appendChild($node); + + $authorisation = base64_encode( + $this->getMerchant() . ':' . $this->getPassword() + ); + + $headers = [ + 'Authorization' => 'Basic ' . $authorisation, + 'Content-Type' => 'text/xml; charset=utf-8', + ]; + + $cookieJar = new ArrayCookieJar(); + + $redirectCookie = $this->getRedirectCookie(); + + if (!empty($redirectCookie)) { + $url = parse_url($this->getEndpoint()); + + $cookieJar->add( + new Cookie( + [ + 'domain' => $url['host'], + 'name' => 'machine', + 'path' => '/', + 'value' => $redirectCookie, + ] + ) + ); + } + + $this->cookiePlugin = new CookiePlugin($cookieJar); + + $this->httpClient->addSubscriber($this->cookiePlugin); + + $xml = $document->saveXML(); + + $this->notify( + [ + 'request' => preg_replace( + '#\([0-9]{3,4})\<\/cvc\>#', + '***', + preg_replace( + '#\([0-9]{10,})\<\/cardNumber\>#', + '**** **** **** ****', + $xml + ) + ), + ] + ); + + $httpResponse = $this->httpClient + ->post($this->getEndpoint(), $headers, $xml) + ->send(); + + $this->notify(['response' => (string)$httpResponse->getBody()]); + + return $this->response = Response::make( + $this, + $httpResponse->getBody() + ); + } + + /** + * Get endpoint + * + * Returns endpoint depending on test mode + * + * @access protected + * @return string + */ + protected function getEndpoint() + { + if ($this->getTestMode()) { + return self::EP_HOST_TEST . self::EP_PATH; + } + + return self::EP_HOST_LIVE . self::EP_PATH; + } + + /** + * Attach an observer. + * + * @param Observer $observer + */ + public function attach(Observer $observer) + { + $this->observers[] = $observer; + } + + /** + * Detach an attached observer. + * + * @param Observer $observer + */ + public function detach(Observer $observer) + { + $this->observers = array_filter( + $this->observers, + function ($a) use ($observer) { + return (!($a === $observer)); + } + ); + } + + /** + * Notify all observers. + * + * @param $data + */ + public function notify($data) + { + foreach ($this->observers as $observer) { + $observer->update($this, $data); + } + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + abstract public function getTransactionType(); +} diff --git a/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php b/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php index f098eac..39138aa 100644 --- a/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php +++ b/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php @@ -1,34 +1,59 @@ setParameter('authorisation', $value); - } + /** + * Set the authorisation code parameter. + * + * @param string $value Value to set the parameter to + * + * @return $this + */ + public function setAuthorisation($value) + { + return $this->setParameter('authorisation', $value); + } - public function getAuthorisation() - { - return $this->getParameter('authorisation'); - } + /** + * Get the authorisation code. + * + * @return string + */ + public function getAuthorisation() + { + return $this->getParameter('authorisation'); + } - public function getData() - { - $data = $this->getBase(); - $authorise = $data->modify->orderModification->addChild('authorise'); - $authorise->addAttribute('authorisationCode', $this->getAuthorisation()); + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $authorise = $data->modify->orderModification->addChild('authorise'); + $authorise->addAttribute('authorisationCode', $this->getAuthorisation()); - return $data; - } + return $data; + } - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::AUTHORISATION_CODE_REQUEST; - } + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::AUTHORISATION_CODE_REQUEST; + } } diff --git a/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php b/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php index 17a2c61..dfe5600 100644 --- a/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php +++ b/src/Omnipay/WorldPayXML/Message/BackOfficeCodeRequest.php @@ -1,34 +1,58 @@ setParameter('backOfficeCode', $value); - } + /** + * Set the backoffice code parameter. + * + * @param string $value The value to set the backoffice code to + * + * @return $this + */ + public function setBackOfficeCode($value) + { + return $this->setParameter('backOfficeCode', $value); + } - public function getBackOfficeCode() - { - return $this->getParameter('backOfficeCode'); - } + /** + * Get the backoffice code + * + * @return string + */ + public function getBackOfficeCode() + { + return $this->getParameter('backOfficeCode'); + } - public function getData() - { - $data = $this->getBase(); - $addBackOfficeCode = $data->modify->orderModification->addChild('addBackOfficeCode'); - $addBackOfficeCode->addAttribute('backOfficeCode', $this->getBackOfficeCode()); + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $addBackOfficeCode = $data->modify->orderModification->addChild('addBackOfficeCode'); + $addBackOfficeCode->addAttribute('backOfficeCode', $this->getBackOfficeCode()); - return $data; - } + return $data; + } - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::BACK_OFFICE_CODE_REQUEST; - } + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::BACK_OFFICE_CODE_REQUEST; + } } diff --git a/src/Omnipay/WorldPayXML/Message/CancelRequest.php b/src/Omnipay/WorldPayXML/Message/CancelRequest.php index e3ab976..49eaf1f 100644 --- a/src/Omnipay/WorldPayXML/Message/CancelRequest.php +++ b/src/Omnipay/WorldPayXML/Message/CancelRequest.php @@ -1,25 +1,37 @@ getBase(); - $data->modify->orderModification->addChild('cancel'); - return $data; - } +/** + * Class CancelRequest + * @package Omnipay\WorldPayXML\Message + */ +class CancelRequest extends ModifyRequest implements RequestInterface +{ + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $data->modify->orderModification->addChild('cancel'); + return $data; + } - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::CANCEL_REQUEST; - } -} \ No newline at end of file + /** + * Return a value to indicate the transaction type. + * + * @return integer + */ + public function getTransactionType() + { + return static::CANCEL_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/CaptureRequest.php b/src/Omnipay/WorldPayXML/Message/CaptureRequest.php index 85a05da..a80624f 100644 --- a/src/Omnipay/WorldPayXML/Message/CaptureRequest.php +++ b/src/Omnipay/WorldPayXML/Message/CaptureRequest.php @@ -1,58 +1,40 @@ setParameter('captureDayOfMonth', $value); - } - - public function getCaptureDayOfMonth() { - return $this->getParameter('captureDayOfMonth'); - } - - public function setCaptureMonth($value) { - return $this->setParameter('captureMonth', $value); - } - - public function getCaptureMonth() { - return $this->getParameter('captureMonth'); - } - - public function setCaptureYear($value) { - return $this->setParameter('captureYear', $value); - } - - public function getCaptureYear() { - return $this->getParameter('captureYear'); - } - - public function getData() - { - $data = $this->getBase(); - $capture = $data->modify->orderModification->addChild('capture'); - $date = $capture->addChild('date'); - $date->addAttribute('dayOfMonth', $this->getCaptureDayOfMonth()); - $date->addAttribute('month', $this->getCaptureMonth()); - $date->addAttribute('year', $this->getCaptureYear()); - $amount = $capture->addChild('amount'); - $amount->addAttribute('value', $this->getAmountInteger()); - $amount->addAttribute('currencyCode', $this->getCurrency()); - $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); - $amount->addAttribute('debitCreditIndicator', $this->getDebitCreditIndicator()); - - return $data; - } - - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::CAPTURE_REQUEST; - } +/** + * Class CaptureRequest + * @package Omnipay\WorldPayXML\Message + */ +class CaptureRequest extends ModifyRequest +{ + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $capture = $data->modify->orderModification->addChild('capture'); + $amount = $capture->addChild('amount'); + $amount->addAttribute('value', $this->getAmountInteger()); + $amount->addAttribute('currencyCode', $this->getCurrency()); + $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); + $amount->addAttribute('debitCreditIndicator', $this->getDebitCreditIndicator()); + + return $data; + } + + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::CAPTURE_REQUEST; + } } \ No newline at end of file diff --git a/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php b/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php index 593af7f..8ad956c 100644 --- a/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php +++ b/src/Omnipay/WorldPayXML/Message/IncreaseAuthorisationRequest.php @@ -1,27 +1,38 @@ getBase(); - $authorise = $data->modify->orderModification->addChild('increaseAuthorisation'); - $amount = $authorise->addChild('amount'); - $amount->addAttribute('value', $this->getAmountInteger()); - $amount->addAttribute('currencyCode', $this->getCurrency()); - $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); +/** + * Class IncreaseAuthorisationRequest + * @package Omnipay\WorldPayXML\Message + */ +class IncreaseAuthorisationRequest extends ModifyRequest +{ + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $authorise = $data->modify->orderModification->addChild('increaseAuthorisation'); + $amount = $authorise->addChild('amount'); + $amount->addAttribute('value', $this->getAmountInteger()); + $amount->addAttribute('currencyCode', $this->getCurrency()); + $amount->addAttribute('exponent', $this->getCurrencyDecimalPlaces()); - return $data; - } + return $data; + } - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::INCREASE_AUTHORISATION_REQUEST; - } + /** + * Return a value to indicate the transaction type. + * @return integer + */ + public function getTransactionType() + { + return static::INCREASE_AUTHORISATION_REQUEST; + } } diff --git a/src/Omnipay/WorldPayXML/Message/InquiryRequest.php b/src/Omnipay/WorldPayXML/Message/InquiryRequest.php index 6cb3e10..aebc401 100644 --- a/src/Omnipay/WorldPayXML/Message/InquiryRequest.php +++ b/src/Omnipay/WorldPayXML/Message/InquiryRequest.php @@ -1,24 +1,37 @@ getBase(); - $inquiry = $data->addChild('inquiry'); - $orderInquiry = $inquiry->addChild('orderInquiry'); - $orderInquiry->addAttribute('orderCode', $this->getTransactionId()); +/** + * Class InquiryRequest + * @package Omnipay\WorldPayXML\Message + */ +class InquiryRequest extends AbstractRequest +{ + /** + * Get the data for the request. + * + * @return \SimpleXMLElement + */ + public function getData() + { + $data = $this->getBase(); + $inquiry = $data->addChild('inquiry'); + $orderInquiry = $inquiry->addChild('orderInquiry'); + $orderInquiry->addAttribute('orderCode', $this->getTransactionId()); - return $data; - } + return $data; + } - /** - * Return a value to indicate the transaction type. - * @return integer - */ - public function getTransactionType() - { - return static::INQUIRY_REQUEST; - } -} \ No newline at end of file + /** + * Return a value to indicate the transaction type. + * + * @return integer + */ + public function getTransactionType() + { + return static::INQUIRY_REQUEST; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/ModifyRequest.php b/src/Omnipay/WorldPayXML/Message/ModifyRequest.php index b43b4b7..ad2b806 100644 --- a/src/Omnipay/WorldPayXML/Message/ModifyRequest.php +++ b/src/Omnipay/WorldPayXML/Message/ModifyRequest.php @@ -1,24 +1,52 @@ setParameter('debitCreditIndicator', $value); - } + /** + * Set the debit/credit parameter. + * + * @param string $value Either 'debit' or 'credit'. + * + * @return $this + */ + public function setDebitCreditIndicator($value) + { + return $this->setParameter('debitCreditIndicator', $value); + } - public function getDebitCreditIndicator() { - return $this->getParameter('debitCreditIndicator'); - } + /** + * Get the debit/credit parameter. + * + * @return string + */ + public function getDebitCreditIndicator() + { + return $this->getParameter('debitCreditIndicator'); + } - protected function getBase() { - $data = parent::getBase(); - $modify = $data->addChild('modify'); - $orderModification = $modify->addChild('orderModification'); - $orderModification->addAttribute('orderCode', $this->getTransactionId()); + /** + * Extends the base XML from the Abstract request class method to include common elements for all modififcation + * requests. + * + * @return \SimpleXMLElement + */ + protected function getBase() + { + $data = parent::getBase(); + $modify = $data->addChild('modify'); + $orderModification = $modify->addChild('orderModification'); + $orderModification->addAttribute('orderCode', $this->getTransactionId()); - return $data; - } -} \ No newline at end of file + return $data; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/ModifyResponse.php b/src/Omnipay/WorldPayXML/Message/ModifyResponse.php index c22c7ad..3dcaa55 100644 --- a/src/Omnipay/WorldPayXML/Message/ModifyResponse.php +++ b/src/Omnipay/WorldPayXML/Message/ModifyResponse.php @@ -1,58 +1,82 @@ request = $request; - - if (empty($data)) { - throw new InvalidResponseException(); - } - - $responseDom = new DOMDocument; - $responseDom->loadXML($data); - - $this->data = simplexml_import_dom( - $responseDom->documentElement->firstChild - ); - } - - /** - * Get is successful - * - * @access public - * @return boolean - */ - public function isSuccessful() - { - if (isset($this->data->ok)) { - return true; - } - - return false; - } - - public function getMessage() - { - if ($this->isSuccessful()) { - return 'SUCCESS'; - } - - return (string)$this->data->error; - } -} \ No newline at end of file +/** + * Class ModifyResponse + * @package Omnipay\WorldPayXML\Message + */ +class ModifyResponse extends Response +{ + /** + * Constructor + * + * @param RequestInterface $request Request + * @param string $data Data + * + * @access public + */ + public function __construct(RequestInterface $request, $data) + { + $this->request = $request; + + $this->data = $data; + } + + /** + * Get is successful + * + * @access public + * @return boolean + */ + public function isSuccessful() + { + if (isset($this->data->ok)) { + return true; + } + + return false; + } + + /** + * Get the message from the response. + * + * @return string + */ + public function getMessage() + { + if ($this->isSuccessful()) { + return 'SUCCESS'; + } + + return (string)$this->data->error; + } + + /** + * Get transaction reference + * + * @access public + * @return string + */ + public function getTransactionReference() + { + if ($this->data->ok instanceof \SimpleXMLElement) { + foreach ($this->data->ok->children() as $child) { + if ($child instanceof \SimpleXMLElement) { + $attributes = $child->attributes(); + + if (isset($attributes['orderCode'])) { + return $attributes['orderCode']; + } + } + } + } + + return null; + } +} diff --git a/src/Omnipay/WorldPayXML/Message/Observer.php b/src/Omnipay/WorldPayXML/Message/Observer.php index ec956c5..866d558 100644 --- a/src/Omnipay/WorldPayXML/Message/Observer.php +++ b/src/Omnipay/WorldPayXML/Message/Observer.php @@ -8,15 +8,16 @@ * Interface Observer * @package Omnipay\WorldPayXML\Message */ -interface Observer { +interface Observer +{ - /** - * Method to be implemented by observers. - * - * @param AbstractRequest $observable The observable instance. - * @param array $data Extra data to be returned from the observable. - * - * @return mixed - */ - public function update(AbstractRequest $observable, array $data); + /** + * Method to be implemented by observers. + * + * @param AbstractRequest $observable The observable instance. + * @param array $data Extra data to be returned from the observable. + * + * @return mixed + */ + public function update(AbstractRequest $observable, array $data); } diff --git a/src/Omnipay/WorldPayXML/Message/PurchaseRequest.php b/src/Omnipay/WorldPayXML/Message/PurchaseRequest.php index 772e147..c6733e4 100755 --- a/src/Omnipay/WorldPayXML/Message/PurchaseRequest.php +++ b/src/Omnipay/WorldPayXML/Message/PurchaseRequest.php @@ -1,5 +1,7 @@ addChild('paymentDetails'); - $codes = array( - CreditCard::BRAND_AMEX => 'AMEX-SSL', - CreditCard::BRAND_DANKORT => 'DANKORT-SSL', + $codes = [ + CreditCard::BRAND_AMEX => 'AMEX-SSL', + CreditCard::BRAND_DANKORT => 'DANKORT-SSL', CreditCard::BRAND_DINERS_CLUB => 'DINERS-SSL', - CreditCard::BRAND_DISCOVER => 'DISCOVER-SSL', - CreditCard::BRAND_JCB => 'JCB-SSL', - CreditCard::BRAND_LASER => 'LASER-SSL', - CreditCard::BRAND_MAESTRO => 'MAESTRO-SSL', - CreditCard::BRAND_MASTERCARD => 'ECMC-SSL', - CreditCard::BRAND_SWITCH => 'MAESTRO-SSL', - CreditCard::BRAND_VISA => 'VISA-SSL' - ); + CreditCard::BRAND_DISCOVER => 'DISCOVER-SSL', + CreditCard::BRAND_JCB => 'JCB-SSL', + CreditCard::BRAND_LASER => 'LASER-SSL', + CreditCard::BRAND_MAESTRO => 'MAESTRO-SSL', + CreditCard::BRAND_MASTERCARD => 'ECMC-SSL', + CreditCard::BRAND_SWITCH => 'MAESTRO-SSL', + CreditCard::BRAND_VISA => 'VISA-SSL', + ]; $card = $payment->addChild($codes[$this->getCard()->getBrand()]); $card->addChild('cardNumber', $this->getCard()->getNumber()); @@ -223,8 +225,8 @@ public function getData() $card->addChild('cardHolderName', $this->getCard()->getName()); if ( - $this->getCard()->getBrand() == CreditCard::BRAND_MAESTRO - || $this->getCard()->getBrand() == CreditCard::BRAND_SWITCH + $this->getCard()->getBrand() == CreditCard::BRAND_MAESTRO + || $this->getCard()->getBrand() == CreditCard::BRAND_SWITCH ) { $start = $card->addChild('startDate')->addChild('date'); $start->addAttribute('month', $this->getCard()->getStartDate('m')); diff --git a/src/Omnipay/WorldPayXML/Message/RedirectResponse.php b/src/Omnipay/WorldPayXML/Message/RedirectResponse.php index 2d98c38..26aaba5 100755 --- a/src/Omnipay/WorldPayXML/Message/RedirectResponse.php +++ b/src/Omnipay/WorldPayXML/Message/RedirectResponse.php @@ -1,5 +1,7 @@ $this->data->requestInfo->request3DSecure->paRequest, - 'TermUrl' => $this->request->getTermUrl() - ); + return [ + 'PaReq' => $this->data->requestInfo->request3DSecure->paRequest, + 'TermUrl' => $this->request->getTermUrl(), + ]; } /** diff --git a/src/Omnipay/WorldPayXML/Message/RefundRequest.php b/src/Omnipay/WorldPayXML/Message/RefundRequest.php index 0c628ec..900a51a 100644 --- a/src/Omnipay/WorldPayXML/Message/RefundRequest.php +++ b/src/Omnipay/WorldPayXML/Message/RefundRequest.php @@ -1,12 +1,15 @@ addAttribute('exponent', $this->getCurrencyDecimalPlaces()); $amount->addAttribute('debitCreditIndicator', $this->getDebitCreditIndicator()); - return $data; + return $data; } /** * Return a value to indicate the transaction type. + * * @return integer */ public function getTransactionType() diff --git a/src/Omnipay/WorldPayXML/Message/Response.php b/src/Omnipay/WorldPayXML/Message/Response.php index eb0bb52..b269a02 100755 --- a/src/Omnipay/WorldPayXML/Message/Response.php +++ b/src/Omnipay/WorldPayXML/Message/Response.php @@ -1,5 +1,7 @@ loadXML($data); - $xmlData = simplexml_import_dom( - $responseDom->documentElement->firstChild->firstChild - ); + if ($request instanceof \Omnipay\WorldPayXML\Message\ModifyRequest && + !($request instanceof \Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest) + ) { + $xmlData = simplexml_import_dom( + $responseDom->documentElement->firstChild + ); + + return new ModifyResponse( + $request, + $xmlData + ); + } else { + $xmlData = simplexml_import_dom( + $responseDom->documentElement->firstChild->firstChild + ); + } if ($xmlData->requestInfo) { return new RedirectResponse($request, $xmlData); @@ -31,6 +55,7 @@ public static function make(RequestInterface $request, $data) { return new Response($request, $xmlData); } } + /** * Constructor * @@ -41,6 +66,10 @@ public static function make(RequestInterface $request, $data) { */ public function __construct(RequestInterface $request, $data) { + if (empty($data)) { + throw new InvalidResponseException(); + } + $this->request = $request; $this->data = $data; @@ -54,13 +83,13 @@ public function __construct(RequestInterface $request, $data) */ public function getMessage() { - $codes = array( - 0 => 'AUTHORISED', - 2 => 'REFERRED', - 3 => 'INVALID ACCEPTOR', - 4 => 'HOLD CARD', - 5 => 'REFUSED', - 8 => 'APPROVE AFTER IDENTIFICATION', + $codes = [ + 0 => 'AUTHORISED', + 2 => 'REFERRED', + 3 => 'INVALID ACCEPTOR', + 4 => 'HOLD CARD', + 5 => 'REFUSED', + 8 => 'APPROVE AFTER IDENTIFICATION', 12 => 'INVALID TRANSACTION', 13 => 'INVALID AMOUNT', 14 => 'INVALID ACCOUNT', @@ -99,8 +128,8 @@ public function getMessage() 91 => 'CREDITCARD ISSUER TEMPORARILY NOT REACHABLE', 92 => 'CREDITCARD TYPE NOT PROCESSED BY ACQUIRER', 94 => 'DUPLICATE REQUEST ERROR', - 97 => 'SECURITY BREACH' - ); + 97 => 'SECURITY BREACH', + ]; $message = 'PENDING'; @@ -140,6 +169,8 @@ public function getTransactionReference() return $attributes['orderCode']; } } + + return null; } /** diff --git a/src/Omnipay/WorldPayXML/Message/VoidRequest.php b/src/Omnipay/WorldPayXML/Message/VoidRequest.php index 987086a..1b08c05 100644 --- a/src/Omnipay/WorldPayXML/Message/VoidRequest.php +++ b/src/Omnipay/WorldPayXML/Message/VoidRequest.php @@ -8,7 +8,8 @@ /** * Omnipay WorldPay XML Refund or Cancel Request */ -class VoidRequest extends ModifyRequest { +class VoidRequest extends ModifyRequest +{ /** * Retrieve the data for the request. @@ -18,9 +19,9 @@ class VoidRequest extends ModifyRequest { public function getData() { $data = $this->getBase(); - $void = $data->modify->orderModification->addChild('cancelOrRefund'); + $data->modify->orderModification->addChild('cancelOrRefund'); - return $data; + return $data; } /** diff --git a/tests/Omnipay/WorldPayXML/GatewayTest.php b/tests/Omnipay/WorldPayXML/GatewayTest.php index 95980f1..e1a713d 100755 --- a/tests/Omnipay/WorldPayXML/GatewayTest.php +++ b/tests/Omnipay/WorldPayXML/GatewayTest.php @@ -7,6 +7,12 @@ class GatewayTest extends GatewayTestCase { + /** + * The WorldPayXML gateway + * @var \Omnipay\WorldPayXML\Gateway + */ + public $gateway; + public function setUp() { parent::setUp(); @@ -15,8 +21,32 @@ public function setUp() $this->getHttpClient(), $this->getHttpRequest() ); + } - $this->options = array( + public function testGetName() + { + $this->assertEquals('WorldPayXML', $this->gateway->getName()); + } + + public function testGetShortName() + { + $this->assertEquals('WorldPayXML', $this->gateway->getShortName()); + } + + public function testGetDefaultParameters() + { + $defaultParameters = $this->gateway->getDefaultParameters(); + + $this->assertInternalType('array', $defaultParameters); + $this->assertArrayHasKey('installation', $defaultParameters); + $this->assertArrayHasKey('merchant', $defaultParameters); + $this->assertArrayHasKey('password', $defaultParameters); + $this->assertArrayHasKey('testMode', $defaultParameters); + } + + public function testPurchaseSuccess() + { + $options = array( 'amount' => '10.00', 'card' => new CreditCard( array( @@ -30,13 +60,10 @@ public function setUp() ), 'transactionId' => 'T0211010', ); - } - public function testPurchaseSuccess() - { $this->setMockHttpResponse('PurchaseSuccess.txt'); - $response = $this->gateway->purchase($this->options)->send(); + $response = $this->gateway->purchase($options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('T0211010', $response->getTransactionReference()); @@ -44,11 +71,161 @@ public function testPurchaseSuccess() public function testPurchaseError() { + $options = array( + 'amount' => '10.00', + 'card' => new CreditCard( + array( + 'firstName' => 'Example', + 'lastName' => 'User', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => '2016', + 'cvv' => '123', + ) + ), + 'transactionId' => 'T0211010', + ); + $this->setMockHttpResponse('PurchaseFailure.txt'); - $response = $this->gateway->purchase($this->options)->send(); + $response = $this->gateway->purchase($options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertSame('CARD EXPIRED', $response->getMessage()); } + + public function testAuthorisationSuccess() + { + $this->setMockHttpResponse('AuthorisationSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'authorisationCode' => 'abc123', + ]; + + $response = $this->gateway->authorise($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testBackOfficeCodeSuccess() + { + $this->setMockHttpResponse('BackOfficeCodeSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'backOfficeCode' => 'abc123', + ]; + + $response = $this->gateway->backOfficeCode($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testCancelSuccess() + { + $this->setMockHttpResponse('CancelSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + ]; + + $response = $this->gateway->cancel($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testCaptureSuccess() + { + $this->setMockHttpResponse('CaptureSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'currencyCode' => 'EUR', + 'debitCreditIndicator' => 'credit', + ]; + + $response = $this->gateway->capture($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testIncreasAuthorisationSuccess() + { + $this->setMockHttpResponse('IncreaseAuthorisationSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'currencyCode' => 'EUR', + 'debitCreditIndicator' => 'credit', + ]; + + $response = $this->gateway->increaseAuthorisation($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testIncreaseAuthorisationFailure() + { + $this->setMockHttpResponse('IncreaseAuthorisationFailure.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'currencyCode' => 'EUR', + 'debitCreditIndicator' => 'credit', + ]; + + $response = $this->gateway->increaseAuthorisation($options)->send(); + + $this->assertFalse($response->isSuccessful()); + } + + public function testInquirySuccess() + { + $this->setMockHttpResponse('InquirySuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + ]; + + $response = $this->gateway->inquiry($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testInquiryFailure() + { + $this->setMockHttpResponse('InquiryFailure.txt'); + + $options = [ + 'orderCode' => 'T0211010', + ]; + + $response = $this->gateway->inquiry($options)->send(); + + $this->assertFalse($response->isSuccessful()); + } + + public function testVoidSuccess() + { + $this->setMockHttpResponse('VoidSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + ]; + + $response = $this->gateway->void($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } } diff --git a/tests/Omnipay/WorldPayXML/Message/ResponseTest.php b/tests/Omnipay/WorldPayXML/Message/ResponseTest.php index 3e98db8..cab8d98 100755 --- a/tests/Omnipay/WorldPayXML/Message/ResponseTest.php +++ b/tests/Omnipay/WorldPayXML/Message/ResponseTest.php @@ -3,21 +3,186 @@ namespace Omnipay\WorldPayXML\Message; use Omnipay\Tests\TestCase; +use Mockery; class ResponseTest extends TestCase { /** - * @expectedException Omnipay\Common\Exception\InvalidResponseException + * @expectedException \Omnipay\Common\Exception\InvalidResponseException */ public function testConstructEmpty() { - $response = new Response($this->getMockRequest(), ''); + $response = Response::make($this->getMockRequest(), ''); + } + + public function testAuthorisationSuccess() + { + $authorisationRequest = Mockery::mock('Omnipay\WorldPayXML\Message\AuthorisationRequest'); + $httpResponse = $this->getMockHttpResponse('AuthorisationSuccess.txt'); + $response = Response::make( + $authorisationRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testBackOfficeCodeSuccess() + { + $backOfficeCodeRequest = Mockery::mock('Omnipay\WorldPayXML\Message\BackOfficeCodeRequest'); + $httpResponse = $this->getMockHttpResponse('BackOfficeCodeSuccess.txt'); + $response = Response::make( + $backOfficeCodeRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testCancelSuccess() + { + $cancelRequest = Mockery::mock('Omnipay\WorldPayXML\Message\CancelRequest'); + $httpResponse = $this->getMockHttpResponse('CancelSuccess.txt'); + $response = Response::make( + $cancelRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testCaptureSuccess() + { + $captureRequest = Mockery::mock('Omnipay\WorldPayXML\Message\CaptureRequest'); + $httpResponse = $this->getMockHttpResponse('CaptureSuccess.txt'); + $response = Response::make( + $captureRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testCaptureFailure() + { + $captureRequest = Mockery::mock('Omnipay\WorldPayXML\Message\CaptureRequest'); + $httpResponse = $this->getMockHttpResponse('CaptureFailure.txt'); + $response = Response::make( + $captureRequest, + $httpResponse->getBody() + ); + + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('Attribute "debitCreditIndicator" with value "xxxx" must have a value from the list "debit credit ".', $response->getMessage()); + } + + public function testInquirySuccess() + { + $inquiryRequest = Mockery::mock('Omnipay\WorldPayXML\Message\InquiryRequest'); + $httpResponse = $this->getMockHttpResponse('InquirySuccess.txt'); + $response = Response::make( + $inquiryRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('AUTHORISED', $response->getMessage()); + } + + public function testInquiryFailure() + { + $inquiryRequest = Mockery::mock('Omnipay\WorldPayXML\Message\InquiryRequest'); + $httpResponse = $this->getMockHttpResponse('InquiryFailure.txt'); + $response = Response::make( + $inquiryRequest, + $httpResponse->getBody() + ); + + $this->assertFalse($response->isSuccessful()); + } + + public function testRefundSuccess() + { + $refundRequest = Mockery::mock('Omnipay\WorldPayXML\Message\RefundRequest'); + $httpResponse = $this->getMockHttpResponse('RefundSuccess.txt'); + $response = Response::make( + $refundRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testRefundFailure() + { + $refundRequest = Mockery::mock('Omnipay\WorldPayXML\Message\RefundRequest'); + $httpResponse = $this->getMockHttpResponse('RefundFailure.txt'); + $response = Response::make( + $refundRequest, + $httpResponse->getBody() + ); + + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('Attribute "debitCreditIndicator" with value "xxxx" must have a value from the list "debit credit ".', $response->getMessage()); + } + + public function testVoidSuccess() + { + $voidRequest = Mockery::mock('Omnipay\WorldPayXML\Message\VoidRequest'); + $httpResponse = $this->getMockHttpResponse('RefundSuccess.txt'); + $response = Response::make( + $voidRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('SUCCESS', $response->getMessage()); + } + + public function testIncreaseAuthorisationSuccess() + { + $increaseAuthorisationRequest = Mockery::mock('Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest'); + $httpResponse = $this->getMockHttpResponse('IncreaseAuthorisationSuccess.txt'); + $response = Response::make( + $increaseAuthorisationRequest, + $httpResponse->getBody() + ); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('AUTHORISED', $response->getMessage()); + } + + public function testIncreaseAuthorisationFail() + { + $increaseAuthorisationRequest = Mockery::mock('Omnipay\WorldPayXML\Message\IncreaseAuthorisationRequest'); + $httpResponse = $this->getMockHttpResponse('IncreaseAuthorisationFailure.txt'); + $response = Response::make( + $increaseAuthorisationRequest, + $httpResponse->getBody() + ); + + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('ERROR: Could not find order', $response->getMessage()); } public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); - $response = new Response( + $response = Response::make( $this->getMockRequest(), $httpResponse->getBody() ); @@ -31,7 +196,7 @@ public function testPurchaseSuccess() public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); - $response = new Response( + $response = Response::make( $this->getMockRequest(), $httpResponse->getBody() ); @@ -41,4 +206,18 @@ public function testPurchaseFailure() $this->assertEquals('T0211234', $response->getTransactionReference()); $this->assertSame('CARD EXPIRED', $response->getMessage()); } + + public function testPurchaseReferral() + { + $httpResponse = $this->getMockHttpResponse('PurchaseReferral.txt'); + $response = Response::make( + $this->getMockRequest(), + $httpResponse->getBody() + ); + + $this->assertFalse($response->isSuccessful()); + $this->assertTrue($response->isRedirect()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + $this->assertEquals('PENDING', $response->getMessage()); + } } diff --git a/tests/Omnipay/WorldPayXML/Mock/AuthorisationSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/AuthorisationSuccess.txt new file mode 100755 index 0000000..4700538 --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/AuthorisationSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/BackOfficeCodeSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/BackOfficeCodeSuccess.txt new file mode 100755 index 0000000..9e09012 --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/BackOfficeCodeSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/CancelSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/CancelSuccess.txt new file mode 100755 index 0000000..1553ebd --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/CancelSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/CaptureFailure.txt b/tests/Omnipay/WorldPayXML/Mock/CaptureFailure.txt new file mode 100644 index 0000000..fc58e4b --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/CaptureFailure.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + diff --git a/tests/Omnipay/WorldPayXML/Mock/CaptureSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/CaptureSuccess.txt new file mode 100755 index 0000000..f28f1bd --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/CaptureSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationFailure.txt b/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationFailure.txt new file mode 100755 index 0000000..691d7ea --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationFailure.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 649 + + + + diff --git a/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationSuccess.txt new file mode 100755 index 0000000..86b0c18 --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/IncreaseAuthorisationSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + +VISA-SSL AUTHORISED 4444********1111 \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/InquiryFailure.txt b/tests/Omnipay/WorldPayXML/Mock/InquiryFailure.txt new file mode 100755 index 0000000..042e856 --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/InquiryFailure.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 649 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/InquirySuccess.txt b/tests/Omnipay/WorldPayXML/Mock/InquirySuccess.txt new file mode 100755 index 0000000..dd4e7af --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/InquirySuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + +VISA-SSL AUTHORISED 4444********1111 \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/PurchaseReferral.txt b/tests/Omnipay/WorldPayXML/Mock/PurchaseReferral.txt new file mode 100644 index 0000000..62124c1 --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/PurchaseReferral.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + +eJxVUm1vgjAQ/ivEzxu1UBDNWYMj2UzGZjb3AxpolERebMtw+/W7Koi79MPdc69P72B1Lo/Ot1S6qKvlhLrTibPisDsoKZNPmbVKckil1mIvnSLHCMbmHr6IhUE04bCNP+SJQ1+BYwHXAzKYmKqyg6gMB5Gd1ps3TkcB0mNQSrVJ7l1WHse4qx8aoXVXq5xTz2dBOIuA3CCoRCn5rq6P2giDvZ1XkwO5oJDVbWXUD4+8EMhgQKuO/GBMsyCk6zrXjLluVpdArB/IyGDbWk1jvXOR8/Q3nqbJ12+6i710H9/LEoiNgFwYyb0pDag3ZQ6dLShbMAbkgoMo7SD8eb11qPfgI94j0NhG8dWwVJHmHQK4FCWrbKAzWCDPTV1JjMAF3HTIpc74u8qlchJUVdFYhjiExYGMpJ5e7JIygz8dzoJ5yOZYn/kRC3y7qYvD9ijw72hIr02sAcSmkv4SSH8tqP27oj+BIsbE111068086332802 \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/RefundFailure.txt b/tests/Omnipay/WorldPayXML/Mock/RefundFailure.txt new file mode 100755 index 0000000..fc58e4b --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/RefundFailure.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + diff --git a/tests/Omnipay/WorldPayXML/Mock/RefundSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/RefundSuccess.txt new file mode 100755 index 0000000..cf7b07b --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/RefundSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file diff --git a/tests/Omnipay/WorldPayXML/Mock/VoidSuccess.txt b/tests/Omnipay/WorldPayXML/Mock/VoidSuccess.txt new file mode 100755 index 0000000..63a845b --- /dev/null +++ b/tests/Omnipay/WorldPayXML/Mock/VoidSuccess.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Connection: close +Server: VPS-3.033.00 +Date: Sat, 23 Feb 2013 05:17:32 GMT +Content-type: text/xml +Content-length: 758 + + + + \ No newline at end of file From a21ab0120e90d346f3f5dfb36d7963eda570edda Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Wed, 9 Dec 2015 12:20:03 +0000 Subject: [PATCH 3/8] Adding AbstractRequest and AuthorisationRequest --- .../WorldPayXML/Message/AbstractRequest.php | 189 ++++++++++++++++++ .../Message/AuthorisationRequest.php | 25 +++ 2 files changed, 214 insertions(+) create mode 100644 omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php create mode 100644 omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php diff --git a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php new file mode 100644 index 0000000..27c5dcd --- /dev/null +++ b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php @@ -0,0 +1,189 @@ +getParameter('merchant'); + } + + /** + * Set merchant + * + * @param string $value Merchant + * + * @access public + * @return void + */ + public function setMerchant($value) + { + return $this->setParameter('merchant', $value); + } + + /** + * Get password + * + * @access public + * @return string + */ + public function getPassword() + { + return $this->getParameter('password'); + } + + /** + * Set password + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setPassword($value) + { + return $this->setParameter('password', $value); + } + + /** + * Get redirect cookie + * + * @access public + * @return string + */ + public function getRedirectCookie() + { + return $this->getParameter('redirect_cookie'); + } + + /** + * Set redirect cookie + * + * @param string $value Password + * + * @access public + * @return void + */ + public function setRedirectCookie($value) + { + return $this->setParameter('redirect_cookie', $value); + } + + protected function getBase() + { + $data = new \SimpleXMLElement(''); + $data->addAttribute('version', self::VERSION); + $data->addAttribute('merchantCode', $this->getMerchant()); + + return $data; + } + /** + * Send data + * + * @param \SimpleXMLElement $data Data + * + * @access public + * @return RedirectResponse + */ + public function sendData($data) + { + $implementation = new \DOMImplementation(); + + $dtd = $implementation->createDocumentType( + 'paymentService', + '-//WorldPay//DTD WorldPay PaymentService v1//EN', + 'http://dtd.worldpay.com/paymentService_v1.dtd' + ); + + $document = $implementation->createDocument(null, '', $dtd); + $document->encoding = 'utf-8'; + + $node = $document->importNode(dom_import_simplexml($data), true); + $document->appendChild($node); + + $authorisation = base64_encode( + $this->getMerchant() . ':' . $this->getPassword() + ); + + $headers = array( + 'Authorization' => 'Basic ' . $authorisation, + 'Content-Type' => 'text/xml; charset=utf-8' + ); + + $cookieJar = new ArrayCookieJar(); + + $redirectCookie = $this->getRedirectCookie(); + + if (!empty($redirectCookie)) { + $url = parse_url($this->getEndpoint()); + + $cookieJar->add( + new Cookie( + array( + 'domain' => $url['host'], + 'name' => 'machine', + 'path' => '/', + 'value' => $redirectCookie + ) + ) + ); + } + + $this->cookiePlugin = new CookiePlugin($cookieJar); + + $this->httpClient->addSubscriber($this->cookiePlugin); + + $xml = $document->saveXML(); + + $httpResponse = $this->httpClient + ->post($this->getEndpoint(), $headers, $xml) + ->send(); + + if ($this instanceof \Omnipay\WorldPayXML\Message\ModifyRequest) { + return $this->response = new ModifyResponse( + $this, + $httpResponse->getBody() + ); + } + + return $this->response = new RedirectResponse( + $this, + $httpResponse->getBody() + ); + } + + /** + * Get endpoint + * + * Returns endpoint depending on test mode + * + * @access protected + * @return string + */ + protected function getEndpoint() + { + if ($this->getTestMode()) { + return self::EP_HOST_TEST . self::EP_PATH; + } + + return self::EP_HOST_LIVE . self::EP_PATH; + } +} \ No newline at end of file diff --git a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php new file mode 100644 index 0000000..d2d3645 --- /dev/null +++ b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php @@ -0,0 +1,25 @@ +setParameter('authorisation', $value); + } + + public function getAuthorisation() + { + return $this->getParameter('authorisation'); + } + + public function getData() + { + $data = $this->getBase(); + $authorise = $data->modify->orderModification->addChild('authorise'); + $authorise->addAttribute('authorisationCode', $this->getAuthorisation()); + + return $data; + } +} From 54b5b761571e74e97d8e0c3d5001030e1c8e5112 Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Wed, 9 Dec 2015 12:55:39 +0000 Subject: [PATCH 4/8] Correcting returns of gateway setters and including missing gateway tests --- .../WorldPayXML/Message/AbstractRequest.php | 189 ------------------ .../Message/AuthorisationRequest.php | 25 --- src/Omnipay/WorldPayXML/Gateway.php | 36 ++-- tests/Omnipay/WorldPayXML/GatewayTest.php | 49 +++++ 4 files changed, 67 insertions(+), 232 deletions(-) delete mode 100644 omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php delete mode 100644 omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php diff --git a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php deleted file mode 100644 index 27c5dcd..0000000 --- a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AbstractRequest.php +++ /dev/null @@ -1,189 +0,0 @@ -getParameter('merchant'); - } - - /** - * Set merchant - * - * @param string $value Merchant - * - * @access public - * @return void - */ - public function setMerchant($value) - { - return $this->setParameter('merchant', $value); - } - - /** - * Get password - * - * @access public - * @return string - */ - public function getPassword() - { - return $this->getParameter('password'); - } - - /** - * Set password - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setPassword($value) - { - return $this->setParameter('password', $value); - } - - /** - * Get redirect cookie - * - * @access public - * @return string - */ - public function getRedirectCookie() - { - return $this->getParameter('redirect_cookie'); - } - - /** - * Set redirect cookie - * - * @param string $value Password - * - * @access public - * @return void - */ - public function setRedirectCookie($value) - { - return $this->setParameter('redirect_cookie', $value); - } - - protected function getBase() - { - $data = new \SimpleXMLElement(''); - $data->addAttribute('version', self::VERSION); - $data->addAttribute('merchantCode', $this->getMerchant()); - - return $data; - } - /** - * Send data - * - * @param \SimpleXMLElement $data Data - * - * @access public - * @return RedirectResponse - */ - public function sendData($data) - { - $implementation = new \DOMImplementation(); - - $dtd = $implementation->createDocumentType( - 'paymentService', - '-//WorldPay//DTD WorldPay PaymentService v1//EN', - 'http://dtd.worldpay.com/paymentService_v1.dtd' - ); - - $document = $implementation->createDocument(null, '', $dtd); - $document->encoding = 'utf-8'; - - $node = $document->importNode(dom_import_simplexml($data), true); - $document->appendChild($node); - - $authorisation = base64_encode( - $this->getMerchant() . ':' . $this->getPassword() - ); - - $headers = array( - 'Authorization' => 'Basic ' . $authorisation, - 'Content-Type' => 'text/xml; charset=utf-8' - ); - - $cookieJar = new ArrayCookieJar(); - - $redirectCookie = $this->getRedirectCookie(); - - if (!empty($redirectCookie)) { - $url = parse_url($this->getEndpoint()); - - $cookieJar->add( - new Cookie( - array( - 'domain' => $url['host'], - 'name' => 'machine', - 'path' => '/', - 'value' => $redirectCookie - ) - ) - ); - } - - $this->cookiePlugin = new CookiePlugin($cookieJar); - - $this->httpClient->addSubscriber($this->cookiePlugin); - - $xml = $document->saveXML(); - - $httpResponse = $this->httpClient - ->post($this->getEndpoint(), $headers, $xml) - ->send(); - - if ($this instanceof \Omnipay\WorldPayXML\Message\ModifyRequest) { - return $this->response = new ModifyResponse( - $this, - $httpResponse->getBody() - ); - } - - return $this->response = new RedirectResponse( - $this, - $httpResponse->getBody() - ); - } - - /** - * Get endpoint - * - * Returns endpoint depending on test mode - * - * @access protected - * @return string - */ - protected function getEndpoint() - { - if ($this->getTestMode()) { - return self::EP_HOST_TEST . self::EP_PATH; - } - - return self::EP_HOST_LIVE . self::EP_PATH; - } -} \ No newline at end of file diff --git a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php b/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php deleted file mode 100644 index d2d3645..0000000 --- a/omnipay-worldpay-xml/src/Omnipay/WorldPayXML/Message/AuthorisationRequest.php +++ /dev/null @@ -1,25 +0,0 @@ -setParameter('authorisation', $value); - } - - public function getAuthorisation() - { - return $this->getParameter('authorisation'); - } - - public function getData() - { - $data = $this->getBase(); - $authorise = $data->modify->orderModification->addChild('authorise'); - $authorise->addAttribute('authorisationCode', $this->getAuthorisation()); - - return $data; - } -} diff --git a/src/Omnipay/WorldPayXML/Gateway.php b/src/Omnipay/WorldPayXML/Gateway.php index a2c36a0..2d9af3e 100755 --- a/src/Omnipay/WorldPayXML/Gateway.php +++ b/src/Omnipay/WorldPayXML/Gateway.php @@ -80,11 +80,11 @@ public function getInstallation() * @param string $value Installation value * * @access public - * @return void + * @return $this */ public function setInstallation($value) { - $this->setParameter('installation', $value); + return $this->setParameter('installation', $value); } /** @@ -104,11 +104,11 @@ public function getMerchant() * @param string $value Merchant value * * @access public - * @return void + * @return $this */ public function setMerchant($value) { - $this->setParameter('merchant', $value); + return $this->setParameter('merchant', $value); } /** @@ -128,11 +128,11 @@ public function getPaResponse() * @param string $value Pa response value * * @access public - * @return void + * @return $this */ public function setPaResponse($value) { - $this->setParameter('pa_response', $value); + return $this->setParameter('pa_response', $value); } /** @@ -152,11 +152,11 @@ public function getPassword() * @param string $value Password value * * @access public - * @return void + * @return $this */ public function setPassword($value) { - $this->setParameter('password', $value); + return $this->setParameter('password', $value); } /** @@ -176,11 +176,11 @@ public function getRedirectCookie() * @param string $value Redirect cookie value * * @access public - * @return void + * @return $this */ public function setRedirectCookie($value) { - $this->setParameter('redirect_cookie', $value); + return $this->setParameter('redirect_cookie', $value); } /** @@ -200,11 +200,11 @@ public function getRedirectEcho() * @param string $value Redirect echo value * * @access public - * @return void + * @return $this */ public function setRedirectEcho($value) { - $this->setParameter('redirect_echo', $value); + return $this->setParameter('redirect_echo', $value); } /** @@ -224,11 +224,11 @@ public function getSession() * @param string $value Session value * * @access public - * @return void + * @return $this */ public function setSession($value) { - $this->setParameter('session', $value); + return $this->setParameter('session', $value); } /** @@ -248,11 +248,11 @@ public function getUserAgentHeader() * @param string $value User agent header value * * @access public - * @return void + * @return $this */ public function setUserAgentHeader($value) { - $this->setParameter('userAgentHeader', $value); + return $this->setParameter('userAgentHeader', $value); } /** @@ -272,11 +272,11 @@ public function getUserIP() * @param string $value User ip value * * @access public - * @return void + * @return $this */ public function setUserIP($value) { - $this->setParameter('userIP', $value); + return $this->setParameter('userIP', $value); } /** diff --git a/tests/Omnipay/WorldPayXML/GatewayTest.php b/tests/Omnipay/WorldPayXML/GatewayTest.php index e1a713d..7234c74 100755 --- a/tests/Omnipay/WorldPayXML/GatewayTest.php +++ b/tests/Omnipay/WorldPayXML/GatewayTest.php @@ -155,6 +155,22 @@ public function testCaptureSuccess() $this->assertEquals('T0211010', $response->getTransactionReference()); } + public function testCaptureFailure() + { + $this->setMockHttpResponse('CaptureFailure.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'currencyCode' => 'EUR', + 'debitCreditIndicator' => 'credit', + ]; + + $response = $this->gateway->capture($options)->send(); + + $this->assertFalse($response->isSuccessful()); + } + public function testIncreasAuthorisationSuccess() { $this->setMockHttpResponse('IncreaseAuthorisationSuccess.txt'); @@ -215,6 +231,39 @@ public function testInquiryFailure() $this->assertFalse($response->isSuccessful()); } + public function testRefundSuccess() + { + $this->setMockHttpResponse('RefundSuccess.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'amountCurrencyCode' => 'GBP', + 'debitOrCredit' => 'credit', + ]; + + $response = $this->gateway->void($options)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals('T0211010', $response->getTransactionReference()); + } + + public function testRefundFailure() + { + $this->setMockHttpResponse('RefundFailure.txt'); + + $options = [ + 'orderCode' => 'T0211010', + 'amount' => 12.34, + 'amountCurrencyCode' => 'GBP', + 'debitOrCredit' => 'xxxxx', + ]; + + $response = $this->gateway->void($options)->send(); + + $this->assertFalse($response->isSuccessful()); + } + public function testVoidSuccess() { $this->setMockHttpResponse('VoidSuccess.txt'); From dff15857ccb0446a95c0a4767e36a1e0fe2dbff6 Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Fri, 15 Jan 2016 09:47:16 +0000 Subject: [PATCH 5/8] Correcting returns of transaction reference from response --- src/Omnipay/WorldPayXML/Message/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Omnipay/WorldPayXML/Message/Response.php b/src/Omnipay/WorldPayXML/Message/Response.php index b269a02..e6b3ca0 100755 --- a/src/Omnipay/WorldPayXML/Message/Response.php +++ b/src/Omnipay/WorldPayXML/Message/Response.php @@ -166,7 +166,7 @@ public function getTransactionReference() $attributes = $this->data->attributes(); if (isset($attributes['orderCode'])) { - return $attributes['orderCode']; + return (string)$attributes['orderCode']; } } From a31029105d48afa829a2616fb6be9a9443f441cf Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Mon, 25 Jan 2016 15:14:27 +0000 Subject: [PATCH 6/8] Switching to dev-master on omnipay/common --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ad28a8..4e8e177 100755 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "guzzle/plugin-cookie": "~3.7", - "omnipay/common": "~2.3" + "omnipay/common": "dev-master" }, "require-dev": { "omnipay/tests": "~2.0" From 106df88237bc4246dfb0c1cde85926b461774ecd Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Mon, 25 Jan 2016 15:16:11 +0000 Subject: [PATCH 7/8] reverting --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4e8e177..8ad28a8 100755 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "guzzle/plugin-cookie": "~3.7", - "omnipay/common": "dev-master" + "omnipay/common": "~2.3" }, "require-dev": { "omnipay/tests": "~2.0" From 7589ef700aca725538cb8a0581fabcd7b1ed7a94 Mon Sep 17 00:00:00 2001 From: Nick Snellock Date: Thu, 28 Jan 2016 11:33:50 +0000 Subject: [PATCH 8/8] Temp change to level of omnipay/common required --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ad28a8..271baa4 100755 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "guzzle/plugin-cookie": "~3.7", - "omnipay/common": "~2.3" + "omnipay/common": "*" }, "require-dev": { "omnipay/tests": "~2.0"