From c86b38dd681aaa4047709ae1a76a2af331f4b4a5 Mon Sep 17 00:00:00 2001 From: Brendan Bullen Date: Wed, 30 Sep 2020 10:35:46 +0100 Subject: [PATCH 1/2] Correct typos --- src/ConstantsInterface.php | 3 +++ src/DirectGateway.php | 2 +- src/Message/AbstractRequest.php | 6 +++--- src/Message/DirectAuthorizeRequest.php | 8 ++++---- src/Message/DirectTokenRegistrationRequest.php | 2 +- src/Message/Form/AuthorizeRequest.php | 4 ++-- src/Message/ServerAuthorizeResponse.php | 2 +- src/Message/ServerCompleteAuthorizeResponse.php | 6 +++--- src/Message/ServerNotifyRequest.php | 6 +++--- src/Traits/GatewayParamsTrait.php | 4 ++-- src/Traits/ServerNotifyTrait.php | 2 +- tests/DirectGatewayTest.php | 2 +- tests/Message/DirectAuthorizeRequestTest.php | 10 +++++----- tests/Message/DirectPurchaseRequestTest.php | 2 +- tests/Message/ServerNotifyRequestTest.php | 8 ++++---- tests/Message/SharedCaptureRequestTest.php | 4 ++-- 16 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/ConstantsInterface.php b/src/ConstantsInterface.php index e4efa7a..30a4d48 100644 --- a/src/ConstantsInterface.php +++ b/src/ConstantsInterface.php @@ -106,6 +106,7 @@ interface ConstantsInterface const TXTYPE_REFUND = 'REFUND'; const TXTYPE_REPEAT = 'REPEAT'; const TXTYPE_REPEATDEFERRED = 'REPEATDEFERRED'; + const TXTYPE_COMPLETE = 'COMPLETE'; /** * @@ -115,6 +116,7 @@ interface ConstantsInterface const SERVICE_REPEAT = 'repeat'; const SERVICE_TOKEN = 'directtoken'; const SERVICE_DIRECT3D = 'direct3dcallback'; + const SERVICE_PAYPAL = 'complete'; /** * 0 = Do not send either customer or vendor emails @@ -149,6 +151,7 @@ interface ConstantsInterface const SAGEPAY_STATUS_MALFORMED = 'MALFORMED'; const SAGEPAY_STATUS_INVALID = 'INVALID'; const SAGEPAY_STATUS_ERROR = 'ERROR'; + const SAGEPAY_STATUS_PAYPALOK = 'PAYPALOK'; /** * Raw values for AddressResult diff --git a/src/DirectGateway.php b/src/DirectGateway.php index d0ffc2f..be782ef 100644 --- a/src/DirectGateway.php +++ b/src/DirectGateway.php @@ -86,7 +86,7 @@ public function abort(array $parameters = []) } /** - * Void a completed (captured) transation. + * Void a completed (captured) transaction. */ public function refund(array $parameters = []) { diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 31f0233..e3b3848 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -60,7 +60,7 @@ public function getService() } /** - * If it is used, i.e. needed for an enpoint, then it must be defined. + * If it is used, i.e. needed for an endpoint, then it must be defined. * * @return string the transaction type. * @throws InvalidRequestException @@ -185,7 +185,7 @@ protected function getDeliveryAddressData(array $data = []) * then use that to instantiate the response object. * * @param array - * @return Response The reponse object initialised with the data returned from the gateway. + * @return Response The response object initialised with the data returned from the gateway. */ public function sendData($data) { @@ -332,7 +332,7 @@ public function getCreateCard() /** * An optional flag to indicate if you wish to continue to store the * Token in the SagePay token database for future use. - * Values set in contants SET_TOKEN_* + * Values set in constants SET_TOKEN_* * * Note: this is just an override method. It is best to leave this unset, * and use either setToken or setCardReference. This flag will then be diff --git a/src/Message/DirectAuthorizeRequest.php b/src/Message/DirectAuthorizeRequest.php index 19325f2..8d1a592 100644 --- a/src/Message/DirectAuthorizeRequest.php +++ b/src/Message/DirectAuthorizeRequest.php @@ -9,7 +9,7 @@ class DirectAuthorizeRequest extends AbstractRequest { /** - * @var array Some mapping from Omnipay card brand codes to Sage Pay card branc codes. + * @var array Some mapping from Omnipay card brand codes to Sage Pay card branch codes. */ protected $cardBrandMap = array( 'mastercard' => 'MC', @@ -104,7 +104,7 @@ protected function getBaseAuthorizeData() * SagePay throws an error if passed an IPv6 address. * Filter out addresses that are not IPv4 format. * - * @return string|null The IPv4 IP addess string or null if not available in this format. + * @return string|null The IPv4 IP address string or null if not available in this format. */ public function getClientIp() { @@ -247,7 +247,7 @@ public function getData() // A CVV may be supplied whether using a token or credit card details. // On *first* use of a token for which a CVV was provided, that CVV will // be used when making a transaction. The CVV will then be deleted by the - // gateway. For each *resuse* of a cardReference, a new CVV must be provided, + // gateway. For each *reuse* of a cardReference, a new CVV must be provided, // if the security rules require it. if ($this->getCard()->getCvv() !== null) { @@ -285,7 +285,7 @@ public function setSurchargeXml($surchargeXml) } /** - * @return string The XML surchange data as set. + * @return string The XML surcharge data as set. */ public function getSurchargeXml() { diff --git a/src/Message/DirectTokenRegistrationRequest.php b/src/Message/DirectTokenRegistrationRequest.php index b486151..b9d174e 100644 --- a/src/Message/DirectTokenRegistrationRequest.php +++ b/src/Message/DirectTokenRegistrationRequest.php @@ -37,7 +37,7 @@ public function getData() $data['CV2'] = $this->getCard()->getCvv(); $data['CardType'] = $this->getCardBrand(); - // The account type only comes into play when a transation is requested. + // The account type only comes into play when a transaction is requested. unset($data['AccountType']); return $data; diff --git a/src/Message/Form/AuthorizeRequest.php b/src/Message/Form/AuthorizeRequest.php index eef3f88..1cfd486 100644 --- a/src/Message/Form/AuthorizeRequest.php +++ b/src/Message/Form/AuthorizeRequest.php @@ -186,7 +186,7 @@ public function generateCrypt(array $data) // is used to submit the form, because that is how the gateway treats // the data internally. // This package assumes input data will be UTF-8 by default, and will - // comvert it accordingly. This can be disabled if the data is already + // convert it accordingly. This can be disabled if the data is already // ISO8859-1. // For the Server and Direct gateway methods, the POST encoding type // will tell the gateway how to interpret the character encoding, and @@ -211,7 +211,7 @@ public function generateCrypt(array $data) $key = $this->getEncryptionKey(); - // Normally IV (paramert 5, initialization vector) would be a kind of salt. + // Normally IV (parameter 5, initialization vector) would be a kind of salt. // That is more relevant when encrypting user details where multiple users // could have identical passwords. But this is a one-off transport of a message // that will always be unique, so no variable IV is needed. diff --git a/src/Message/ServerAuthorizeResponse.php b/src/Message/ServerAuthorizeResponse.php index 5d0bdda..008a6e5 100644 --- a/src/Message/ServerAuthorizeResponse.php +++ b/src/Message/ServerAuthorizeResponse.php @@ -48,7 +48,7 @@ public function getRedirectMethod() } /** - * @return array empy array; all the data is in the GET URL + * @return array empty array; all the data is in the GET URL */ public function getRedirectData() { diff --git a/src/Message/ServerCompleteAuthorizeResponse.php b/src/Message/ServerCompleteAuthorizeResponse.php index 2630ad5..c206c36 100644 --- a/src/Message/ServerCompleteAuthorizeResponse.php +++ b/src/Message/ServerCompleteAuthorizeResponse.php @@ -46,10 +46,10 @@ public function confirm($nextUrl, $detail = null) * Error (Sage Pay Server only) * * Notify Sage Pay you received the payment details but there was an error and the payment - * cannot be completed. Error should be called rarely, and only when something unforseen + * cannot be completed. Error should be called rarely, and only when something unforeseen * has happened on your server or database. * - * @param string URL to foward the customer to. Note this is different to your standard + * @param string URL to forward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for not accepting the transaction. */ @@ -66,7 +66,7 @@ public function error($nextUrl, $detail = null) * of the POST, such as the MD5 hash signatures did not match or you do not wish to proceed * with the order. * - * @param string URL to foward the customer to. Note this is different to your standard + * @param string URL to forward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for not accepting the transaction. */ diff --git a/src/Message/ServerNotifyRequest.php b/src/Message/ServerNotifyRequest.php index 443187c..dc23d0b 100644 --- a/src/Message/ServerNotifyRequest.php +++ b/src/Message/ServerNotifyRequest.php @@ -65,7 +65,7 @@ public function setTransactionReference($reference) { if (strpos($reference, 'SecurityKey') !== false) { // A JSON string provided - the legacy transactionReference format. - // Decode it then extact the securityKey. + // Decode it then extract the securityKey. // We only need the security key here for the signature; all other // items from the reference will be in the server request. @@ -138,7 +138,7 @@ public function accept($nextUrl, $detail = null) * Notify Sage Pay you received the payment details but there was an error and the payment * cannot be completed. * - * @param string URL to foward the customer to. + * @param string URL to forward the customer to. * @param string Optional human readable reasons for not accepting the transaction. */ public function error($nextUrl, $detail = null) @@ -168,7 +168,7 @@ public function reject($nextUrl, $detail = null) * of the POST, such as the MD5 hash signatures did not match or you do not wish to proceed * with the order. * - * @param string URL to foward the customer to. + * @param string URL to forward the customer to. * @param string Optional human readable reasons for not accepting the transaction. */ public function invalid($nextUrl, $detail = null) diff --git a/src/Traits/GatewayParamsTrait.php b/src/Traits/GatewayParamsTrait.php index 83ccdd2..c38f9bc 100644 --- a/src/Traits/GatewayParamsTrait.php +++ b/src/Traits/GatewayParamsTrait.php @@ -78,7 +78,7 @@ public function getUseOldBasketFormat() * and this option allows it to be turned back on for legacy * merchant sites. * - * @param mixed true if the notify reponse exits the application. + * @param mixed true if the notify response exits the application. * @return $this */ public function setExitOnResponse($value) @@ -87,7 +87,7 @@ public function setExitOnResponse($value) } /** - * @return mixed true if the notify reponse exits the application. + * @return mixed true if the notify response exits the application. */ public function getExitOnResponse() { diff --git a/src/Traits/ServerNotifyTrait.php b/src/Traits/ServerNotifyTrait.php index 0d54111..319104d 100644 --- a/src/Traits/ServerNotifyTrait.php +++ b/src/Traits/ServerNotifyTrait.php @@ -47,7 +47,7 @@ public function buildSignature() $VPSTxId = str_replace(['{', '}'], '', $VPSTxId); } - // Transaction types PAYMENT, DEFERRED and AUTHENTICATE (when suppoted) + // Transaction types PAYMENT, DEFERRED and AUTHENTICATE (when supported) // and non-transaction TOKEN request. $signatureData = array( diff --git a/tests/DirectGatewayTest.php b/tests/DirectGatewayTest.php index 7355783..4685855 100644 --- a/tests/DirectGatewayTest.php +++ b/tests/DirectGatewayTest.php @@ -73,7 +73,7 @@ public function testAuthorizeFailure() $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); - // With no suuccess and no redirect, there will be no transaction reference. + // With no success and no redirect, there will be no transaction reference. //$this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getTransactionReference()); diff --git a/tests/Message/DirectAuthorizeRequestTest.php b/tests/Message/DirectAuthorizeRequestTest.php index a7462fb..e18bf2b 100644 --- a/tests/Message/DirectAuthorizeRequestTest.php +++ b/tests/Message/DirectAuthorizeRequestTest.php @@ -6,7 +6,7 @@ class DirectAuthorizeRequestTest extends TestCase { - // VISA incurrs a surcharge of 2.5% when used. + // VISA incurs a surcharge of 2.5% when used. const SURCHARGE_XML = '' . 'VISA2.50' . ''; @@ -287,13 +287,13 @@ public function testMixedBasketWithSpecialChars() { $items = new \Omnipay\Common\ItemBag(array( new \Omnipay\Common\Item(array( - 'name' => "Denisé's Odd & Wierd £name? #12345678901234567890123456789012345678901234567890123456789012345678901234567890", + 'name' => "Denisé's Odd & Weird £name? #12345678901234567890123456789012345678901234567890123456789012345678901234567890", 'description' => 'Description', 'quantity' => 2, 'price' => 4.23, )), array( - 'name' => "Denisé's \"Odd\" & Wierd £discount? #", + 'name' => "Denisé's \"Odd\" & Weird £discount? #", 'description' => 'My Offer', 'quantity' => 2, 'price' => -0.10, @@ -309,11 +309,11 @@ public function testMixedBasketWithSpecialChars() // Names/descriptions should be max 100 characters in length, once invalid characters have been removed. $expected = '' - . 'Denis\'s Odd & Wierd name 1234567890123456789012345678901234567890123456789012345678901234567890123452' + . 'Denis\'s Odd & Weird name 1234567890123456789012345678901234567890123456789012345678901234567890123452' . '4.230.00' . '4.238.46' . '' - . '0.2Denis\'s "Odd" Wierd discount? #' + . '0.2Denis\'s "Odd" Weird discount? #' . '1.61234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' . ''; diff --git a/tests/Message/DirectPurchaseRequestTest.php b/tests/Message/DirectPurchaseRequestTest.php index d14918b..1fb0417 100644 --- a/tests/Message/DirectPurchaseRequestTest.php +++ b/tests/Message/DirectPurchaseRequestTest.php @@ -6,7 +6,7 @@ class DirectPurchaseRequestTest extends DirectAuthorizeRequestTest { - // VISA incurrs a surcharge of 2.5% when used. + // VISA incurs a surcharge of 2.5% when used. const SURCHARGE_XML = '' . 'VISA2.50' . ''; diff --git a/tests/Message/ServerNotifyRequestTest.php b/tests/Message/ServerNotifyRequestTest.php index 5875df2..34dc911 100644 --- a/tests/Message/ServerNotifyRequestTest.php +++ b/tests/Message/ServerNotifyRequestTest.php @@ -62,8 +62,8 @@ public function testServerNotifyResponseSuccess() $this->request->setSecurityKey('JEUPDN1N7E'); - // With the security key added, the signatue check will now be valid, - // i.e. an untampered inbound notification. + // With the security key added, the signature check will now be valid, + // i.e. an un-tampered inbound notification. $this->assertTrue($this->request->isValid()); @@ -123,7 +123,7 @@ public function testServerNotifyRequestFailure() $this->getHttpRequest() ); - // The transactino reference in Response and ServerNotifyTrait + // The transaction reference in Response and ServerNotifyTrait // will return null if there is no transaction data provided // by the gateway. @@ -227,7 +227,7 @@ public function testInvalid() } /** - * sendRequest lets you return a raw message with no additinal + * sendRequest lets you return a raw message with no additional * checks on the validity of what was received. */ public function testSendResponse() diff --git a/tests/Message/SharedCaptureRequestTest.php b/tests/Message/SharedCaptureRequestTest.php index 0035709..ba73081 100644 --- a/tests/Message/SharedCaptureRequestTest.php +++ b/tests/Message/SharedCaptureRequestTest.php @@ -25,13 +25,13 @@ public function testTxType() $this->assertSame('RELEASE', $this->request->getTxType()); - // User authenticate explicity true. + // User authenticate explicitly true. $this->request->setUseAuthenticate(true); $this->assertSame('AUTHORISE', $this->request->getTxType()); - // User authenticate explicity false (back to the default). + // User authenticate explicitly false (back to the default). $this->request->setUseAuthenticate(false); From e3f6b5350632211c73e433655f2fb7f17e0930fe Mon Sep 17 00:00:00 2001 From: Brendan Bullen Date: Wed, 30 Sep 2020 11:02:33 +0100 Subject: [PATCH 2/2] Add SagePay Direct PayPal integration handling --- composer.json | 2 + src/DirectGateway.php | 6 ++ src/Message/AbstractRequest.php | 5 +- src/Message/DirectAuthorizeRequest.php | 21 +++++- src/Message/DirectCompletePayPalRequest.php | 77 +++++++++++++++++++++ src/Message/Response.php | 45 ++++++++---- src/PayPal.php | 65 +++++++++++++++++ src/Traits/ResponseFieldsTrait.php | 15 ++-- 8 files changed, 212 insertions(+), 24 deletions(-) create mode 100644 src/Message/DirectCompletePayPalRequest.php create mode 100644 src/PayPal.php diff --git a/composer.json b/composer.json index 40ebdeb..c029dc6 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,8 @@ }, "require": { "php": "^5.6|^7", + "ext-json": "*", + "ext-simplexml": "*", "omnipay/common": "~3.0" }, "require-dev": { diff --git a/src/DirectGateway.php b/src/DirectGateway.php index be782ef..6089b83 100644 --- a/src/DirectGateway.php +++ b/src/DirectGateway.php @@ -4,6 +4,7 @@ use Omnipay\SagePay\Message\DirectAuthorizeRequest; use Omnipay\SagePay\Message\DirectCompleteAuthorizeRequest; +use Omnipay\SagePay\Message\DirectCompletePayPalRequest; use Omnipay\SagePay\Message\DirectPurchaseRequest; use Omnipay\SagePay\Message\SharedCaptureRequest; use Omnipay\SagePay\Message\SharedVoidRequest; @@ -44,6 +45,11 @@ public function completeAuthorize(array $parameters = []) return $this->createRequest(DirectCompleteAuthorizeRequest::class, $parameters); } + public function completePayPal(array $parameters = []) + { + return $this->createRequest(DirectCompletePayPalRequest::class, $parameters); + } + /** * Purchase and handling of return from 3D Secure or PayPal redirection. */ diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index e3b3848..0c62a80 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -437,11 +437,10 @@ public function getAllowGiftAid() * Values defined in static::ALLOW_GIFT_AID_* constant. * * @param bool|int $allowGiftAid value that casts to boolean - * @return $this */ - public function setAllowGiftAid($value) + public function setAllowGiftAid($allowGiftAid) { - $this->setParameter('allowGiftAid', $value); + $this->setParameter('allowGiftAid', $allowGiftAid); } /** diff --git a/src/Message/DirectAuthorizeRequest.php b/src/Message/DirectAuthorizeRequest.php index 8d1a592..325b935 100644 --- a/src/Message/DirectAuthorizeRequest.php +++ b/src/Message/DirectAuthorizeRequest.php @@ -2,6 +2,8 @@ namespace Omnipay\SagePay\Message; +use Omnipay\SagePay\PayPal; + /** * Sage Pay Direct Authorize Request */ @@ -9,7 +11,7 @@ class DirectAuthorizeRequest extends AbstractRequest { /** - * @var array Some mapping from Omnipay card brand codes to Sage Pay card branch codes. + * @var array Some mapping from Omnipay card brand codes to Sage Pay card brand codes. */ protected $cardBrandMap = array( 'mastercard' => 'MC', @@ -191,6 +193,14 @@ public function getCardData($data = array()) // Validate the card details (number, date, cardholder name). $this->getCard()->validate(); + $data['CardType'] = $this->getCardBrand(); + + if ($this->isPayPalPayment()) { + $data['PayPalCallbackURL'] = $this->getCard()->getCallbackUrl(); + + return $data; + } + if ($this->getCardholderName()) { $data['CardHolder'] = $this->getCardholderName(); } else { @@ -203,7 +213,6 @@ public function getCardData($data = array()) } $data['ExpiryDate'] = $this->getCard()->getExpiryDate('my'); - $data['CardType'] = $this->getCardBrand(); if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { $data['StartDate'] = $this->getCard()->getStartDate('my'); @@ -291,4 +300,12 @@ public function getSurchargeXml() { return $this->getParameter('surchargeXml'); } + + /** + * @return bool + */ + protected function isPayPalPayment() + { + return $this->getCardBrand() === 'PAYPAL' && $this->getCard() instanceof PayPal; + } } diff --git a/src/Message/DirectCompletePayPalRequest.php b/src/Message/DirectCompletePayPalRequest.php new file mode 100644 index 0000000..b9d2e4d --- /dev/null +++ b/src/Message/DirectCompletePayPalRequest.php @@ -0,0 +1,77 @@ +getBaseAuthorizeData(); + } + + /** + * The required fields concerning what is being authorised and who + * it is being authorised for. + * + * @return array + * @throws InvalidRequestException + */ + protected function getBaseAuthorizeData() + { + $this->validate('transactionId', 'amount', 'accept'); + + // Start with the authorisation and API version details. + $data = $this->getBaseData(); + + // Money formatted as major unit decimal. + $data['VPSTxId'] = $this->getTransactionId(); + $data['Amount'] = $this->getAmount(); + $data['Accept'] = !$this->getAccept() || strtoupper($this->getAccept()) === 'NO' ? 'NO' : 'YES'; + + return $data; + } + + /** + * @return string + */ + public function getAccept() + { + return $this->getParameter('accept'); + } + + /** + * Override the MD passed into the current request. + * + * @param string $value + * @return $this + */ + public function setAccept($value) + { + return $this->setParameter('accept', $value); + } +} \ No newline at end of file diff --git a/src/Message/Response.php b/src/Message/Response.php index 34d54d3..a3c21ac 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -4,7 +4,6 @@ use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; -use Omnipay\Common\Message\RequestInterface; use Omnipay\SagePay\Traits\ResponseFieldsTrait; use Omnipay\SagePay\ConstantsInterface; @@ -43,7 +42,7 @@ public function getTransactionReference() // The reference is null if we have no transaction details. if (empty($reference)) { - return; + return null; } // Remaining transaction details supplied by the merchant site @@ -66,17 +65,23 @@ public function getTransactionReference() */ public function isRedirect() { - return $this->getStatus() === static::SAGEPAY_STATUS_3DAUTH; + return $this->getStatus() === static::SAGEPAY_STATUS_3DAUTH || $this->getStatus() === static::SAGEPAY_STATUS_PPREDIRECT; } /** - * @return string URL to 3D Secure endpoint. + * @return string|null URL to 3D Secure endpoint. */ public function getRedirectUrl() { - if ($this->isRedirect()) { - return $this->getDataItem('ACSURL'); + if (!$this->isRedirect()) { + return null; } + + if ($this->getStatus() === static::SAGEPAY_STATUS_PPREDIRECT) { + return $this->getDataItem('PayPalRedirectURL'); + } + + return $this->getDataItem('ACSURL'); } /** @@ -84,6 +89,14 @@ public function getRedirectUrl() */ public function getRedirectMethod() { + if (!$this->isRedirect()) { + return null; + } + + if ($this->getStatus() === static::SAGEPAY_STATUS_PPREDIRECT) { + return 'GET'; + } + return 'POST'; } @@ -91,17 +104,23 @@ public function getRedirectMethod() * The usual reason for a redirect is for a 3D Secure check. * Note: when PayPal is supported, a different set of data will be returned. * - * @return array Collected 3D Secure POST data. + * @return array|null Collected 3D Secure POST data. */ public function getRedirectData() { - if ($this->isRedirect()) { - return array( - 'PaReq' => $this->getDataItem('PAReq'), - 'TermUrl' => $this->getRequest()->getReturnUrl(), - 'MD' => $this->getDataItem('MD'), - ); + if (!$this->isRedirect()) { + return null; } + + if ($this->getStatus() === static::SAGEPAY_STATUS_PPREDIRECT) { + return array(); + } + + return array( + 'PaReq' => $this->getDataItem('PAReq'), + 'TermUrl' => $this->getRequest()->getReturnUrl(), + 'MD' => $this->getDataItem('MD'), + ); } /** diff --git a/src/PayPal.php b/src/PayPal.php new file mode 100644 index 0000000..b7621f7 --- /dev/null +++ b/src/PayPal.php @@ -0,0 +1,65 @@ + 'PayPal callback URL', + ); + + foreach ($requiredParameters as $key => $val) { + if (!$this->getParameter($key)) { + throw new InvalidCreditCardException("The $val is required"); + } + } + } + + /** + * Get the card CVV. + * + * @return string + */ + public function getCallbackUrl() + { + return $this->getParameter('callbackUrl'); + } + + /** + * Sets the card CVV. + * + * @param string $value + * @return $this + */ + public function setCallbackUrl($value) + { + return $this->setParameter('callbackUrl', $value); + } +} \ No newline at end of file diff --git a/src/Traits/ResponseFieldsTrait.php b/src/Traits/ResponseFieldsTrait.php index a14525a..6f59ec0 100644 --- a/src/Traits/ResponseFieldsTrait.php +++ b/src/Traits/ResponseFieldsTrait.php @@ -18,8 +18,6 @@ trait ResponseFieldsTrait */ protected function getDataItem($name, $default = null) { - $data = $this->getData(); - return isset($this->data[$name]) ? $this->data[$name] : $default; } @@ -31,7 +29,8 @@ public function isSuccessful() return $this->getStatus() === static::SAGEPAY_STATUS_OK || $this->getStatus() === static::SAGEPAY_STATUS_OK_REPEATED || $this->getStatus() === static::SAGEPAY_STATUS_REGISTERED - || $this->getStatus() === static::SAGEPAY_STATUS_AUTHENTICATED; + || $this->getStatus() === static::SAGEPAY_STATUS_AUTHENTICATED + || $this->getStatus() === static::SAGEPAY_STATUS_PAYPALOK; } /** @@ -171,7 +170,7 @@ public function getCAVV() } /** - * The raw frawd response from the gateway. + * The raw fraud response from the gateway. * * @return string One of static::FRAUD_RESPONSE_* */ @@ -193,7 +192,7 @@ public function getBankAuthCode() * The decline code from the bank. These codes are * specific to the bank. Please contact them for a description * of each code. e.g. 00 - * @return string Two digit code, specific to the bacnk. + * @return string Two digit code, specific to the bank. */ public function getDeclineCode() { @@ -248,6 +247,8 @@ public function getExpiryMonth() if (! empty($expiryDate)) { return (int)substr($expiryDate, 0, 2); } + + return null; } /** @@ -260,10 +261,12 @@ public function getExpiryYear() $expiryDate = $this->getDataItem('ExpiryDate'); if (! empty($expiryDate)) { - // COnvert 2-digit year to 4-dogot year, in 1970-2069 range. + // Convert 2-digit year to 4-digit year, in 1970-2069 range. $dateTime = \DateTime::createFromFormat('y', substr($expiryDate, 2, 2)); return (int)$dateTime->format('Y'); } + + return null; } /**