diff --git a/src/Omnipay/SagePay/DirectGateway.php b/src/Omnipay/SagePay/DirectGateway.php index 0d3401b..d03c2fc 100644 --- a/src/Omnipay/SagePay/DirectGateway.php +++ b/src/Omnipay/SagePay/DirectGateway.php @@ -76,4 +76,20 @@ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\RefundRequest', $parameters); } + + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\SagePay\Message\DirectCreateTokenRequest', $parameters); + } + + public function repeatPayment(array $parameters = array()) + { + return $this->createRequest('\Omnipay\SagePay\Message\DirectRepeatPaymentRequest', $parameters); + } + + + public function deleteCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\SagePay\Message\DirectRemoveTokenRequest', $parameters); + } } diff --git a/src/Omnipay/SagePay/Message/AbstractRequest.php b/src/Omnipay/SagePay/Message/AbstractRequest.php index cf6c2d2..5d48460 100644 --- a/src/Omnipay/SagePay/Message/AbstractRequest.php +++ b/src/Omnipay/SagePay/Message/AbstractRequest.php @@ -21,6 +21,187 @@ public function setVendor($value) return $this->setParameter('vendor', $value); } + public function getFirstName() + { + return $this->getParameter('firstName'); + } + + public function setFirstName($value) + { + return $this->setParameter('firstName', $value); + } + + public function getLastName() + { + return $this->getParameter('lastName'); + } + + public function setLastName($value) + { + return $this->setParameter('lastName', $value); + } + + + public function getBillingAddress1() + { + return $this->getParameter('billingAddress1'); + } + + public function setBillingAddress1($value) + { + return $this->setParameter('billingAddress1', $value); + } + + public function getBillingAddress2() + { + return $this->getParameter('billingAddress2'); + } + + public function setBillingAddress2($value) + { + return $this->setParameter('billingAddress2', $value); + } + + public function getBillingCity() + { + return $this->getParameter('billingCity'); + } + + public function setBillingCity($value) + { + return $this->setParameter('billingCity', $value); + } + + public function getBillingPostcode() + { + return $this->getParameter('billingPostcode'); + } + + public function setBillingPostcode($value) + { + return $this->setParameter('billingPostcode', $value); + } + + public function getBillingState() + { + return $this->getParameter('billingState'); + } + + public function setBillingState($value) + { + return $this->setParameter('billingState', $value); + } + + public function getBillingPhone() + { + return $this->getParameter('billingPhone'); + } + + public function setBillingPhone($value) + { + return $this->setParameter('billingPhone', $value); + } + + public function getBillingCountry() + { + return $this->getParameter('billingCountry'); + } + + public function setBillingCountry($value) + { + return $this->setParameter('billingCountry', $value); + } + + public function getShippingAddress1() + { + return $this->getParameter('shippingAddress1'); + } + + public function setShippingAddress1($value) + { + return $this->setParameter('shippingAddress1', $value); + } + + public function getShippingAddress2() + { + return $this->getParameter('shippingAddress2'); + } + + public function setShippingAddress2($value) + { + return $this->setParameter('shippingAddress2', $value); + } + + public function getShippingCity() + { + return $this->getParameter('shippingCity'); + } + + public function setShippingCity($value) + { + return $this->setParameter('shippingCity', $value); + } + + public function getShippingPostcode() + { + return $this->getParameter('shippingPostcode'); + } + + public function setShippingPostcode($value) + { + return $this->setParameter('shippingPostcode', $value); + } + + public function getShippingState() + { + return $this->getParameter('shippingState'); + } + + public function setShippingState($value) + { + return $this->setParameter('shippingState', $value); + } + + public function getShippingPhone() + { + return $this->getParameter('shippingPhone'); + } + + public function setShippingPhone($value) + { + return $this->setParameter('shippingPhone', $value); + } + + public function getShippingCountry() + { + return $this->getParameter('shippingCountry'); + } + + public function setShippingCountry($value) + { + return $this->setParameter('shippingCountry', $value); + } + + public function getCompany() + { + return $this->getParameter('company'); + } + + public function setCompany($value) + { + return $this->setParameter('company', $value); + } + + public function getEmail() + { + return $this->getParameter('email'); + } + + public function setEmail($value) + { + return $this->setParameter('email', $value); + } + public function getSimulatorMode() { return $this->getParameter('simulatorMode'); diff --git a/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php b/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php index 201f161..82a55c1 100644 --- a/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php @@ -15,9 +15,7 @@ class DirectAuthorizeRequest extends AbstractRequest protected function getBaseAuthorizeData() { - $this->validate('amount', 'card', 'transactionId'); - $card = $this->getCard(); - + $this->validate('amount', 'transactionId'); $data = $this->getBaseData(); $data['Description'] = $this->getDescription(); $data['Amount'] = $this->getAmount(); @@ -27,50 +25,89 @@ protected function getBaseAuthorizeData() $data['ApplyAVSCV2'] = 0; // use account setting $data['Apply3DSecure'] = 0; // use account setting - // billing details - $data['BillingFirstnames'] = $card->getFirstName(); - $data['BillingSurname'] = $card->getLastName(); - $data['BillingAddress1'] = $card->getBillingAddress1(); - $data['BillingAddress2'] = $card->getBillingAddress2(); - $data['BillingCity'] = $card->getBillingCity(); - $data['BillingPostCode'] = $card->getBillingPostcode(); - $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null; - $data['BillingCountry'] = $card->getBillingCountry(); - $data['BillingPhone'] = $card->getBillingPhone(); - - // shipping details - $data['DeliveryFirstnames'] = $card->getFirstName(); - $data['DeliverySurname'] = $card->getLastName(); - $data['DeliveryAddress1'] = $card->getShippingAddress1(); - $data['DeliveryAddress2'] = $card->getShippingAddress2(); - $data['DeliveryCity'] = $card->getShippingCity(); - $data['DeliveryPostCode'] = $card->getShippingPostcode(); - $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null; - $data['DeliveryCountry'] = $card->getShippingCountry(); - $data['DeliveryPhone'] = $card->getShippingPhone(); - $data['CustomerEMail'] = $card->getEmail(); - + if (!$this->getCardReference()) { + $card = $this->getCard(); + // billing details + $data['BillingFirstnames'] = $card->getFirstName(); + $data['BillingSurname'] = $card->getLastName(); + $data['BillingAddress1'] = $card->getBillingAddress1(); + $data['BillingAddress2'] = $card->getBillingAddress2(); + $data['BillingCity'] = $card->getBillingCity(); + $data['BillingPostCode'] = $card->getBillingPostcode(); + $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null; + $data['BillingCountry'] = $card->getBillingCountry(); + $data['BillingPhone'] = $card->getBillingPhone(); + + // shipping details + $data['DeliveryFirstnames'] = $card->getFirstName(); + $data['DeliverySurname'] = $card->getLastName(); + $data['DeliveryAddress1'] = $card->getShippingAddress1(); + $data['DeliveryAddress2'] = $card->getShippingAddress2(); + $data['DeliveryCity'] = $card->getShippingCity(); + $data['DeliveryPostCode'] = $card->getShippingPostcode(); + $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null; + $data['DeliveryCountry'] = $card->getShippingCountry(); + $data['DeliveryPhone'] = $card->getShippingPhone(); + $data['CustomerEMail'] = $card->getEmail(); + } else { + //Card hasnt been sent so Values need to come from parameteres + $data['BillingFirstnames'] = $this->getFirstName(); + $data['BillingSurname'] = $this->getLastName(); + $data['BillingAddress1'] = $this->getBillingAddress1(); + $data['BillingAddress2'] = $this->getBillingAddress2(); + $data['BillingCity'] = $this->getBillingCity(); + $data['BillingPostCode'] = $this->getBillingPostcode(); + $data['BillingState'] = $this->getBillingCountry() === 'US' ? $this->getBillingState() : null; + $data['BillingCountry'] = $this->getBillingCountry(); + $data['BillingPhone'] = $this->getBillingPhone(); + + // shipping details + $data['DeliveryFirstnames'] = $this->getFirstName(); + $data['DeliverySurname'] = $this->getLastName(); + $data['DeliveryAddress1'] = $this->getShippingAddress1(); + $data['DeliveryAddress2'] = $this->getShippingAddress2(); + $data['DeliveryCity'] = $this->getShippingCity(); + $data['DeliveryPostCode'] = $this->getShippingPostcode(); + $data['DeliveryState'] = $this->getShippingCountry() === 'US' ? $this->getShippingState() : null; + $data['DeliveryCountry'] = $this->getShippingCountry(); + $data['DeliveryPhone'] = $this->getShippingPhone(); + $data['CustomerEMail'] = $this->getEmail(); + + } return $data; } public function getData() { $data = $this->getBaseAuthorizeData(); - $this->getCard()->validate(); + + //If this is a Token payment, add the Token data item, otherwise its a normal card purchase. + if ($this->getCardReference()) { + $data['Token'] = $this->getCardReference(); + $data['CV2'] = $this->getParameter('cvv'); + $data['StoreToken'] = 1; + + } else { + $this->getCard()->validate(); + + $data['CardHolder'] = $this->getCard()->getName(); + $data['CardNumber'] = $this->getCard()->getNumber(); + $data['ExpiryDate'] = $this->getCard()->getExpiryDate('my'); + $data['CV2'] = $this->getCard()->getCvv(); + $data['CardType'] = $this->getCardBrand(); + + if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { + $data['StartDate'] = $this->getCard()->getStartDate('my'); + } + + if ($this->getCard()->getIssueNumber()) { + $data['IssueNumber'] = $this->getCard()->getIssueNumber(); + } - $data['CardHolder'] = $this->getCard()->getName(); - $data['CardNumber'] = $this->getCard()->getNumber(); - $data['CV2'] = $this->getCard()->getCvv(); - $data['ExpiryDate'] = $this->getCard()->getExpiryDate('my'); - $data['CardType'] = $this->getCardBrand(); - - if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { - $data['StartDate'] = $this->getCard()->getStartDate('my'); } - if ($this->getCard()->getIssueNumber()) { - $data['IssueNumber'] = $this->getCard()->getIssueNumber(); - } + + return $data; } @@ -90,4 +127,29 @@ protected function getCardBrand() return $brand; } + + + /** + * CVV parameter getter + * + * @return string + */ + public function getCvv() + { + return $this->getParameter('cvv'); + } + + /** + * CVV parameter setter + * Setter added to allow payments with token and cvv. + * Without setter CVV parameter is stripped out from request parameters. + * + * @param $value string + * @return $this + */ + public function setCvv($value) + { + return $this->setParameter('cvv', $value); + } + } diff --git a/src/Omnipay/SagePay/Message/DirectCreateTokenRequest.php b/src/Omnipay/SagePay/Message/DirectCreateTokenRequest.php new file mode 100644 index 0000000..bcd931d --- /dev/null +++ b/src/Omnipay/SagePay/Message/DirectCreateTokenRequest.php @@ -0,0 +1,97 @@ + 'mc', + 'diners_club' => 'dc' + ); + + protected function getBaseAuthorizeData() + { + $data = $this->getBaseData(); + + //$data['Currency'] = $this->getParameter['Currency']; + + $data['ClientIPAddress'] = $this->getClientIp(); + $data['ApplyAVSCV2'] = 0; // use account setting + $data['Apply3DSecure'] = 0; // use account setting + + $data['StoreToken'] = 1; //Token needs to be kept + + + + return $data; + + } + + public function getData() + { + $data = $this->getBaseAuthorizeData(); + $card = $this->getCard(); + + $data['Currency'] = 'GBP'; + $data['CardNumber'] = $card->getNumber(); + $data['ExpiryDate'] = $card->getExpiryDate('my'); + $data['CardType'] = $this->getCardBrand(); + $data['CardHolder'] = $card->getName(); + + // billing details + $data['BillingFirstnames'] = $card->getFirstName(); + $data['BillingSurname'] = $card->getLastName(); + $data['BillingAddress1'] = $card->getBillingAddress1(); + $data['BillingAddress2'] = $card->getBillingAddress2(); + $data['BillingCity'] = $card->getBillingCity(); + $data['BillingPostCode'] = $card->getBillingPostcode(); + $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null; + $data['BillingCountry'] = $card->getBillingCountry(); + $data['BillingPhone'] = $card->getBillingPhone(); + + // shipping details + $data['DeliveryFirstnames'] = $card->getFirstName(); + $data['DeliverySurname'] = $card->getLastName(); + $data['DeliveryAddress1'] = $card->getShippingAddress1(); + $data['DeliveryAddress2'] = $card->getShippingAddress2(); + $data['DeliveryCity'] = $card->getShippingCity(); + $data['DeliveryPostCode'] = $card->getShippingPostcode(); + $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null; + $data['DeliveryCountry'] = $card->getShippingCountry(); + $data['DeliveryPhone'] = $card->getShippingPhone(); + $data['CustomerEMail'] = $card->getEmail(); + + + if ($card->getStartMonth() && $card->getStartYear()) { + $data['StartDate'] = $card->getStartDate('my'); + } + if ($card->getIssueNumber()) { + $data['IssueNumber'] = $card->getIssueNumber(); + } + $data['CV2'] = $card->getCvv(); + + + return $data; + } + + public function getService() + { + return 'directtoken'; + } + + protected function getCardBrand() + { + $brand = $this->getCard()->getBrand(); + + if (isset($this->cardBrandMap[$brand])) { + return $this->cardBrandMap[$brand]; + } + + return $brand; + } +} diff --git a/src/Omnipay/SagePay/Message/DirectRemoveTokenRequest.php b/src/Omnipay/SagePay/Message/DirectRemoveTokenRequest.php new file mode 100644 index 0000000..5cace24 --- /dev/null +++ b/src/Omnipay/SagePay/Message/DirectRemoveTokenRequest.php @@ -0,0 +1,32 @@ +getBaseData(); + + return $data; + } + + public function getData() + { + $data = $this->getBaseAuthorizeData(); + //Add the token ID to remove + $data['Token'] = $this->getParameter('cardReference'); + + return $data; + } + + public function getService() + { + return 'removetoken'; + } +} diff --git a/src/Omnipay/SagePay/Message/DirectRepeatPaymentRequest.php b/src/Omnipay/SagePay/Message/DirectRepeatPaymentRequest.php new file mode 100644 index 0000000..faf337a --- /dev/null +++ b/src/Omnipay/SagePay/Message/DirectRepeatPaymentRequest.php @@ -0,0 +1,98 @@ +getBaseData(); + + return $data; + + } + + public function getData() + { + $data = $this->getBaseAuthorizeData(); + + + $data['Currency'] = 'GBP'; + $data['Amount'] = $this->getAmount(); + + $data['Description'] = $this->getDescription(); + //Unique reference to THIS payment + $data['VendorTxCode'] = $this->getTransactionId(); + + //Specific to repeat payments + //Return results from previous Payments + $data['RelatedVPSTxId'] = $this->getRelatedVPSTxId(); + $data['RelatedVendorTxCode'] = $this->getRelatedTransactionId(); + $data['RelatedSecurityKey'] = $this->getRelatedSecurityKey(); + $data['RelatedTxAuthNo'] = $this->getRelatedTxAuthNo(); + + // billing details + return $data; + } + + + public function getDescription() + { + return $this->getParameter('description'); + } + + public function setDescription($value) + { + return $this->setParameter('description', $value); + } + + public function getRelatedVPSTxId() + { + return $this->getParameter('relatedVPSTxId'); + } + + public function setRelatedVPSTxId($value) + { + return $this->setParameter('relatedVPSTxId', $value); + } + + public function getRelatedTransactionId() + { + return $this->getParameter('relatedTransactionId'); + } + + public function setRelatedTransactionId($value) + { + return $this->setParameter('relatedTransactionId', $value); + } + + public function getRelatedSecurityKey() + { + return $this->getParameter('relatedSecurityKey'); + } + + public function setRelatedSecurityKey($value) + { + return $this->setParameter('relatedSecurityKey', $value); + } + + public function getRelatedTxAuthNo() + { + return $this->getParameter('relatedTxAuthNo'); + } + + public function setRelatedTxAuthNo($value) + { + return $this->setParameter('relatedTxAuthNo', $value); + } + + public function getService() + { + return 'repeat'; + } +} diff --git a/src/Omnipay/SagePay/Message/Response.php b/src/Omnipay/SagePay/Message/Response.php index f4c38a4..891d540 100644 --- a/src/Omnipay/SagePay/Message/Response.php +++ b/src/Omnipay/SagePay/Message/Response.php @@ -57,6 +57,11 @@ public function getMessage() return isset($this->data['StatusDetail']) ? $this->data['StatusDetail'] : null; } + public function getToken() + { + return isset($this->data['Token']) ? $this->data['Token'] : null; + } + public function getRedirectUrl() { if ($this->isRedirect()) {