diff --git a/example/index.php b/example/index.php index 88fa17c7..613faf1f 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,13 +162,41 @@ // 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); $app['session']->set($sessionVar.'.card', $card); $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/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/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(); 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() diff --git a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php index d943484a..3e314cf6 100644 --- a/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php +++ b/src/Omnipay/SagePay/Message/ServerAuthorizeRequest.php @@ -14,6 +14,40 @@ public function getData() $data = $this->getBaseAuthorizeData(); $data['NotificationURL'] = $this->getReturnUrl(); + //if (null !== $this->getLowProfile()) { + $data['Profile'] = "LOW"; + //} + + $items = $this->getItems(); + + if ($items) + { + $i = count($items); + $data['Basket'] = ""; + 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())); + } + } + + 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; } 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);