From 1d62cc4ee81dd26145b1e643e8c4af05b4718640 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 14 Nov 2013 14:23:38 +0000 Subject: [PATCH 1/6] SagePay Basket, added item IDs, shipping and tax to Paypal Included the basket data for SagePay server, also introduced taxes and shipping to orders and item id numbers for SKU or unique product references --- src/Omnipay/Common/Item.php | 32 +++++++++++++++++++ .../Common/Message/AbstractRequest.php | 26 +++++++++++++++ .../Message/ExpressAuthorizeRequest.php | 5 +++ .../Message/ServerAuthorizeRequest.php | 21 ++++++++++++ 4 files changed, 84 insertions(+) diff --git a/src/Omnipay/Common/Item.php b/src/Omnipay/Common/Item.php index dae49aa6..25c9609d 100644 --- a/src/Omnipay/Common/Item.php +++ b/src/Omnipay/Common/Item.php @@ -118,4 +118,36 @@ public function setPrice($value) { return $this->setParameter('price', $value); } + + /** + * {@inheritDoc} + */ + public function getId() + { + return $this->getParameter('id'); + } + + /** + * Set the item price + */ + public function setId($value) + { + return $this->setParameter('id', $value); + } + + /** + * {@inheritDoc} + */ + public function getTax() + { + return $this->getParameter('tax'); + } + + /** + * Set the item price + */ + public function setTax($value) + { + return $this->setParameter('tax', $value); + } } diff --git a/src/Omnipay/Common/Message/AbstractRequest.php b/src/Omnipay/Common/Message/AbstractRequest.php index 2bbf4f9e..b29759c6 100644 --- a/src/Omnipay/Common/Message/AbstractRequest.php +++ b/src/Omnipay/Common/Message/AbstractRequest.php @@ -186,6 +186,32 @@ public function getAmountInteger() return (int) round($this->getAmount() * $this->getCurrencyDecimalFactor()); } + public function getTax() + { + $tax = $this->getParameter('tax'); + if ($tax) { + return $this->formatCurrency($tax); + } + } + + public function setTax($value) + { + return $this->setParameter('tax', $value); + } + + public function getShipping() + { + $shipping = $this->getParameter('shipping'); + if ($shipping) { + return $this->formatCurrency($shipping); + } + } + + public function setShipping($value) + { + return $this->setParameter('shipping', $value); + } + public function getCurrency() { return $this->getParameter('currency'); diff --git a/src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php b/src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php index 48607d8a..5129a7af 100644 --- a/src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php +++ b/src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php @@ -14,7 +14,10 @@ public function getData() $this->validate('amount', 'returnUrl', 'cancelUrl'); $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization'; + $data['PAYMENTREQUEST_0_TAXAMT'] = $this->getTax(); + $data['PAYMENTREQUEST_0_SHIPPINGAMT'] = $this->getShipping(); $data['PAYMENTREQUEST_0_AMT'] = $this->getAmount(); + $data['PAYMENTREQUEST_0_ITEMAMT'] = $this->getAmount() - $this->getTax() - $this->getShipping(); $data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency(); $data['PAYMENTREQUEST_0_INVNUM'] = $this->getTransactionId(); $data['PAYMENTREQUEST_0_DESC'] = $this->getDescription(); @@ -53,10 +56,12 @@ public function getData() $items = $this->getItems(); if ($items) { foreach ($items as $n => $item) { + $data["L_PAYMENTREQUEST_0_NUMBER$n"] = $item->getId(); $data["L_PAYMENTREQUEST_0_NAME$n"] = $item->getName(); $data["L_PAYMENTREQUEST_0_DESC$n"] = $item->getDescription(); $data["L_PAYMENTREQUEST_0_QTY$n"] = $item->getQuantity(); $data["L_PAYMENTREQUEST_0_AMT$n"] = $this->formatCurrency($item->getPrice()); + $data["L_PAYMENTREQUEST_0_TAXAMT$n"] = $this->formatCurrency($item->getTax()); } } diff --git a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php index d943484a..9da94c86 100644 --- a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php @@ -14,6 +14,27 @@ public function getData() $data = $this->getBaseAuthorizeData(); $data['NotificationURL'] = $this->getReturnUrl(); + //if (null !== $this->getLowProfile()) { + // $data['Profile'] = "LOW"; + //} + + $items = $this->getItems(); + + if ($items) { + + $data['Basket'] = count($items); + foreach ($items as $n => $item) { + + $data['Basket'] .= ':' . $item->getId()." - ".$item->getName(); + $data['Basket'] .= ':' . $item->getQuantity(); + $data['Basket'] .= ':' . $this->formatCurrency($item->getPrice()); + $data['Basket'] .= ':' . $this->formatCurrency($item->getTax()); + $data['Basket'] .= ':' . $this->formatCurrency($item->getPrice() + $item->getTax()); + $data['Basket'] .= ':' . $this->formatCurrency($item->getQuantity() * ($item->getPrice() + $item->getTax())); + } + + } + return $data; } From d4082bb31bcfba5aa02f0cffc90095450cc77553 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 15 Nov 2013 15:52:51 +0000 Subject: [PATCH 2/6] Added shipping to SagePay --- example/index.php | 31 +++++++++++++++++++ .../Message/ServerAuthorizeRequest.php | 17 ++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/example/index.php b/example/index.php index 88fa17c7..f77111ca 100644 --- a/example/index.php +++ b/example/index.php @@ -136,8 +136,13 @@ $gateway->initialize((array) $app['session']->get($sessionVar)); $params = $app['session']->get($sessionVar.'.purchase', array()); + $params['returnUrl'] = str_replace('/purchase', '/completePurchase', $app['request']->getUri()); $params['cancelUrl'] = $app['request']->getUri(); + + + + $card = new Omnipay\Common\CreditCard($app['session']->get($sessionVar.'.card')); return $app['twig']->render('request.twig', array( @@ -157,6 +162,25 @@ // load POST data $params = $app['request']->get('params'); $card = $app['request']->get('card'); + $items = new Omnipay\Common\ItemBag; + $items->add(array( + 'id' => 'ABC123', + 'name' => 'Food', + 'quantity' => 1, + 'price' => '1.00', + 'tax' => '2.00', + )); +/* + $items->add(array( + 'id' => 'ZZZ1234', + 'name' => 'Food2', + 'quantity' => 1, + 'price' => '1.00', + 'tax' => '1.00', + )); +*/ + $params['tax'] = "2.00"; + $params['shipping'] = "1.00"; // save POST data into session $app['session']->set($sessionVar.'.purchase', $params); @@ -164,6 +188,13 @@ $params['card'] = $card; $params['clientIp'] = $app['request']->getClientIp(); + //$params['lowProfile'] = true; + $params['items'] = $items; + +/* + print_r($params); + die(); +*/ $response = $gateway->purchase($params)->send(); return $app['twig']->render('response.twig', array( diff --git a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php index 9da94c86..94d4b068 100644 --- a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php @@ -21,8 +21,7 @@ public function getData() $items = $this->getItems(); if ($items) { - - $data['Basket'] = count($items); + $i = count($items); foreach ($items as $n => $item) { $data['Basket'] .= ':' . $item->getId()." - ".$item->getName(); @@ -32,9 +31,21 @@ public function getData() $data['Basket'] .= ':' . $this->formatCurrency($item->getPrice() + $item->getTax()); $data['Basket'] .= ':' . $this->formatCurrency($item->getQuantity() * ($item->getPrice() + $item->getTax())); } - } + if($this->getShipping()) + { + $i++; + $data['Basket'] .= ':' . 'Delivery'; + $data['Basket'] .= ':' . '1'; + $data['Basket'] .= ':' . $this->getShipping(); + $data['Basket'] .= ':' . '---'; + $data['Basket'] .= ':' . $this->getShipping(); + $data['Basket'] .= ':' . $this->getShipping(); + } + + if(isset($data['Basket'])) $data['Basket'] = $i.$data['Basket']; + return $data; } From f178fd32e43fd7cc844219641ece336b9c8eaf1c Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 17 Nov 2013 12:47:13 +0000 Subject: [PATCH 3/6] Fix: Undefined index: Basket --- src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php index 94d4b068..5c27285f 100644 --- a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php @@ -22,6 +22,7 @@ public function getData() if ($items) { $i = count($items); + $data['Basket'] = ""; foreach ($items as $n => $item) { $data['Basket'] .= ':' . $item->getId()." - ".$item->getName(); From da72b0768db13fd73b03fe5996be214d96911773 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 19 Nov 2013 20:53:22 +0000 Subject: [PATCH 4/6] Removed TxAuthNo from transactions reference --- example/index.php | 8 +++++--- src/Omnipay/SagePay/Message/Response.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/example/index.php b/example/index.php index f77111ca..613faf1f 100644 --- a/example/index.php +++ b/example/index.php @@ -162,6 +162,7 @@ // load POST data $params = $app['request']->get('params'); $card = $app['request']->get('card'); + /* $items = new Omnipay\Common\ItemBag; $items->add(array( 'id' => 'ABC123', @@ -171,6 +172,7 @@ 'tax' => '2.00', )); /* + $items->add(array( 'id' => 'ZZZ1234', 'name' => 'Food2', @@ -178,10 +180,10 @@ 'price' => '1.00', 'tax' => '1.00', )); -*/ + $params['tax'] = "2.00"; $params['shipping'] = "1.00"; - +*/ // save POST data into session $app['session']->set($sessionVar.'.purchase', $params); $app['session']->set($sessionVar.'.card', $card); @@ -189,7 +191,7 @@ $params['card'] = $card; $params['clientIp'] = $app['request']->getClientIp(); //$params['lowProfile'] = true; - $params['items'] = $items; + //$params['items'] = $items; /* print_r($params); diff --git a/src/Omnipay/SagePay/Message/Response.php b/src/Omnipay/SagePay/Message/Response.php index f4c38a4e..eaf5cdbc 100644 --- a/src/Omnipay/SagePay/Message/Response.php +++ b/src/Omnipay/SagePay/Message/Response.php @@ -40,6 +40,7 @@ public function isRedirect() */ public function getTransactionReference() { +/* if (isset($this->data['SecurityKey']) && isset($this->data['TxAuthNo']) && isset($this->data['VPSTxId'])) { return json_encode( array( @@ -50,6 +51,19 @@ public function getTransactionReference() ) ); } +*/ + + if (isset($this->data['SecurityKey']) && isset($this->data['VPSTxId'])) { + return json_encode( + array( + 'SecurityKey' => $this->data['SecurityKey'], + //'TxAuthNo' => $this->data['TxAuthNo'], + 'VPSTxId' => $this->data['VPSTxId'], + 'VendorTxCode' => $this->getRequest()->getTransactionId(), + ) + ); + } + } public function getMessage() From dcde93912d82316e590d25ae7c206c97692475ba Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 23 Dec 2013 16:40:57 +0000 Subject: [PATCH 5/6] Low profile --- src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php | 9 +++++---- src/Omnipay/SagePay/ServerGateway.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php index 5c27285f..3e314cf6 100644 --- a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php @@ -15,16 +15,17 @@ public function getData() $data['NotificationURL'] = $this->getReturnUrl(); //if (null !== $this->getLowProfile()) { - // $data['Profile'] = "LOW"; + $data['Profile'] = "LOW"; //} $items = $this->getItems(); - if ($items) { + if ($items) + { $i = count($items); $data['Basket'] = ""; - foreach ($items as $n => $item) { - + foreach ($items as $n => $item) + { $data['Basket'] .= ':' . $item->getId()." - ".$item->getName(); $data['Basket'] .= ':' . $item->getQuantity(); $data['Basket'] .= ':' . $this->formatCurrency($item->getPrice()); diff --git a/src/Omnipay/SagePay/ServerGateway.php b/src/Omnipay/SagePay/ServerGateway.php index acf64a76..599a817e 100644 --- a/src/Omnipay/SagePay/ServerGateway.php +++ b/src/Omnipay/SagePay/ServerGateway.php @@ -16,6 +16,16 @@ public function getName() return 'Sage Pay Server'; } + public function getLowProfile() + { + return $this->getParameter('lowProfile'); + } + + public function setLowProfile($value) + { + return $this->setParameter('lowProfile', $value); + } + public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\ServerAuthorizeRequest', $parameters); From 1753433a54672ffd6f9c92222c861abffec88a65 Mon Sep 17 00:00:00 2001 From: mbeech Date: Thu, 17 Dec 2015 13:44:24 +0000 Subject: [PATCH 6/6] Update DirectAuthorizeRequest.php Send empty values for state instead of null --- src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php b/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php index 201f1611..83c140e8 100644 --- a/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php @@ -34,7 +34,7 @@ protected function getBaseAuthorizeData() $data['BillingAddress2'] = $card->getBillingAddress2(); $data['BillingCity'] = $card->getBillingCity(); $data['BillingPostCode'] = $card->getBillingPostcode(); - $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null; + $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : ''; $data['BillingCountry'] = $card->getBillingCountry(); $data['BillingPhone'] = $card->getBillingPhone(); @@ -45,7 +45,7 @@ protected function getBaseAuthorizeData() $data['DeliveryAddress2'] = $card->getShippingAddress2(); $data['DeliveryCity'] = $card->getShippingCity(); $data['DeliveryPostCode'] = $card->getShippingPostcode(); - $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null; + $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : ''; $data['DeliveryCountry'] = $card->getShippingCountry(); $data['DeliveryPhone'] = $card->getShippingPhone(); $data['CustomerEMail'] = $card->getEmail();