From 02fa83ab482837b1c304cdd6b6993ff7c76b98c1 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 23 Oct 2018 14:34:24 +0200 Subject: [PATCH 1/6] changed composer name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index aabdd05..38597ed 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "andypieters/omnipay-paynl", + "name": "paynl/omnipay-paynl", "type": "library", "description": "Pay.nl driver for the Omnipay payment processing library", "keywords": [ From accc7d1b6a66cdab7887c64e65eb4e9fbd9db73c Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 30 Jan 2019 13:33:18 +0100 Subject: [PATCH 2/6] Updated badges in readme --- .gitignore | 3 ++- README.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a01afa8..236c05e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ composer.lock composer.phar /nbproject/ -/.idea/* \ No newline at end of file +/.idea/* +/build/* \ No newline at end of file diff --git a/README.md b/README.md index 0eb5aed..2ad87bd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Build Status](https://travis-ci.org/andypieters/omnipay-paynl.svg?branch=master)](https://travis-ci.org/andypieters/omnipay-paynl) -[![Coverage Status](https://coveralls.io/repos/github/andypieters/omnipay-paynl/badge.svg?branch=master)](https://coveralls.io/github/andypieters/omnipay-paynl?branch=master) +[![Build Status](https://travis-ci.org/paynl/omnipay-paynl.svg?branch=master)](https://travis-ci.org/paynl/omnipay-paynl) +[![Coverage Status](https://coveralls.io/repos/github/paynl/omnipay-paynl/badge.svg?branch=master)](https://coveralls.io/github/paynl/omnipay-paynl?branch=master) # omnipay-paynl Pay.nl driver for the Omnipay payment processing library From 14a55da6b5d29f398d66b65de24a41a8643deb9b Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 30 Jan 2019 15:53:45 +0100 Subject: [PATCH 3/6] Added extra fields to PurchaseRequest --- src/Message/PurchaseRequest.php | 133 ++++++++++++++++++++++++-- tests/Message/PurchaseRequestTest.php | 57 +++++++++++ 2 files changed, 180 insertions(+), 10 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index b0d1cdb..339c57c 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -9,7 +9,8 @@ * * @method \Omnipay\Paynl\Message\PurchaseResponse send() */ -class PurchaseRequest extends AbstractRequest { +class PurchaseRequest extends AbstractRequest +{ /** * Regex to find streetname, housenumber and suffix out of a street string @@ -21,7 +22,8 @@ class PurchaseRequest extends AbstractRequest { * Return the data formatted for PAY.nl * @return array */ - public function getData() { + public function getData() + { $this->validate('apitoken', 'serviceId', 'amount', 'description', 'returnUrl'); $data['amount'] = round($this->getAmount() * 100); @@ -39,10 +41,10 @@ public function getData() { $data['transaction']['orderExchangeUrl'] = $this->getNotifyUrl(); } - if($this->getCurrency()){ + if ($this->getCurrency()) { $data['transaction']['currency'] = $this->getCurrency(); } - + $data['enduser'] = array(); if ($card = $this->getCard()) { $billingAddressParts = $this->getAddressParts($card->getBillingAddress1()); $shippingAddressParts = ($card->getShippingAddress1() ? $this->getAddressParts($card->getShippingAddress1()) : $billingAddressParts); @@ -77,10 +79,17 @@ public function getData() { ) ); } + if(!empty($this->getCustomerReference())){ + $data['enduser']['customerReference'] = $this->getCustomerReference(); + } + if(is_numeric($this->getCustomerTrust())){ + $data['enduser']['customerTrust'] = $this->getCustomerTrust(); + } + $data['saleData'] = array(); if ($items = $this->getItems()) { $data['saleData'] = array( - 'orderData' => array_map(function($item) { + 'orderData' => array_map(function ($item) { /** @var Item $item */ $data = array( 'description' => $item->getDescription(), @@ -108,16 +117,119 @@ public function getData() { ); } + if(!empty($this->getInvoiceDate())){ + $data['saleData']['invoiceDate'] = $this->getInvoiceDate(); + } + if(!empty($this->getDeliveryDate())){ + $data['saleData']['deliveryDate'] = $this->getDeliveryDate(); + } + + if ($statsData = $this->getStatsData()) { + // Could be someone erroneously not set an array + if (is_array($statsData)) { + $allowableParams = ["promotorId", "info", "tool", "extra1", "extra2", "extra3", "transferData"]; + $data['statsData'] = array_filter($statsData, function ($k) use ($allowableParams) { + return in_array($k, $allowableParams); + }, ARRAY_FILTER_USE_KEY); + } + } + $data['testMode'] = $this->getTestMode() ? 1 : 0; return $data; } + /** + * @return array + */ + public function getStatsData() + { + return $this->getParameter('statsData'); + } + + /** + * @param $value array + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setStatsData($value) + { + return $this->setParameter('statsData', $value); + } + + /** + * @return string + */ + public function getInvoiceDate() + { + return $this->getParameter('invoiceDate'); + } + + /** + * @param $value string + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setInvoiceDate($value) + { + return $this->setParameter('invoiceDate', $value); + } + + /** + * @return string + */ + public function getDeliveryDate() + { + return $this->getParameter('deliveryDate'); + } + + /** + * @param $value string + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setDeliveryDate($value) + { + return $this->setParameter('deliveryDate', $value); + } + + /** + * @return string + */ + public function getCustomerReference() + { + return $this->getParameter('customerReference'); + } + + /** + * @param $value string + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setCustomerReference($value) + { + return $this->setParameter('customerReference', $value); + } + + /** + * @return integer + */ + public function getCustomerTrust() + { + return $this->getParameter('customerTrust'); + } + + /** + * @param $value integer + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setCustomerTrust($value) + { + return $this->setParameter('customerTrust', $value); + } + /** * Send the data * @param array $data * @return AbstractResponse */ - public function sendData($data) { + public function sendData($data) + { $httpResponse = $this->sendRequest('POST', 'transaction/start', $data); return $this->response = new PurchaseResponse($this, $httpResponse->json()); } @@ -127,9 +239,10 @@ public function sendData($data) { * @param string $address * @return array */ - public function getAddressParts($address) { - $addressParts = []; - preg_match($this->addressRegex, $address, $addressParts); - return array_filter($addressParts, 'trim'); + public function getAddressParts($address) + { + $addressParts = []; + preg_match($this->addressRegex, $address, $addressParts); + return array_filter($addressParts, 'trim'); } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 491b540..71c7142 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -62,6 +62,63 @@ public function testLanguage(){ $this->assertArrayHasKey('enduser', $data); $this->assertEquals('NL', $data['enduser']['language']); } + public function testStatsData() + { + $statsData = [ + 'promotorId' => uniqid(), + 'info' => uniqid(), + 'tool' => uniqid(), + 'extra1' => uniqid(), + 'extra2' => uniqid(), + 'extra3' => uniqid() + ]; + + $this->request->setStatsData($statsData); + + $data = $this->request->getData(); + + $this->assertArrayHasKey('statsData', $data); + $this->assertEquals($statsData['promotorId'], $data['statsData']['promotorId']); + $this->assertEquals($statsData['info'], $data['statsData']['info']); + $this->assertEquals($statsData['tool'], $data['statsData']['tool']); + $this->assertEquals($statsData['extra1'], $data['statsData']['extra1']); + $this->assertEquals($statsData['extra2'], $data['statsData']['extra2']); + $this->assertEquals($statsData['extra3'], $data['statsData']['extra3']); + } + public function testDates() + { + $invoiceDate = new \DateTime('now'); + $deliveryDate = new \DateTime('tomorrow'); + $invoiceDate = $invoiceDate->format('d-m-Y'); + $deliveryDate = $deliveryDate->format('d-m-Y'); + + $this->request->setInvoiceDate($invoiceDate); + $this->request->setDeliveryDate($deliveryDate); + + $data = $this->request->getData(); + + $this->assertArrayHasKey('saleData', $data); + $this->assertArrayHasKey('invoiceDate', $data['saleData']); + $this->assertArrayHasKey('deliveryDate', $data['saleData']); + $this->assertEquals($invoiceDate, $data['saleData']['invoiceDate']); + $this->assertEquals($deliveryDate, $data['saleData']['deliveryDate']); + } + public function testCustomerData() + { + $customerReference = uniqid(); + $customerTrust = rand(-10, 10); + + $this->request->setCustomerReference($customerReference); + $this->request->setCustomerTrust($customerTrust); + + $data = $this->request->getData(); + + $this->assertArrayHasKey('enduser', $data); + $this->assertArrayHasKey('customerReference', $data['enduser']); + $this->assertArrayHasKey('customerTrust', $data['enduser']); + $this->assertEquals($customerReference, $data['enduser']['customerReference']); + $this->assertEquals($customerTrust, $data['enduser']['customerTrust']); + } public function testWithCardOnlyShipping(){ $arrCard = $this->getValidCard(); From eb0a6eabfe8b822bc48c2a943baca4dc6d13ff7b Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 30 Jan 2019 16:47:04 +0100 Subject: [PATCH 4/6] Dropped support for php version 5.4 and 5.5 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e8ba8d8..8eac877 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,6 @@ branches: matrix: include: - - php: 5.4 - - php: 5.5 - php: 5.6 - php: 7 - php: 7.1 From 762787c3f958b75f2bd6faec7c6506affeff959d Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Wed, 3 Feb 2021 12:02:37 +0100 Subject: [PATCH 5/6] Update README.md --- README.md | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ad87bd..530c17e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,234 @@ -[![Build Status](https://travis-ci.org/paynl/omnipay-paynl.svg?branch=master)](https://travis-ci.org/paynl/omnipay-paynl) -[![Coverage Status](https://coveralls.io/repos/github/paynl/omnipay-paynl/badge.svg?branch=master)](https://coveralls.io/github/paynl/omnipay-paynl?branch=master) +

+ +

+

PAY. Omnipay driver

-# omnipay-paynl -Pay.nl driver for the Omnipay payment processing library +# Description + +PAY. driver for the Omnipay payment processing library + +- [Description](#description) +- [Available payment methods](#available-payment-methods) +- [Requirements](#requirements) +- [Installation](#installation) +- [Update instructions](#update-instructions) +- [Usage](#usage) +- [Support](#support) + + +# Available payment methods + +Bank Payments | Creditcards | Gift cards & Vouchers | Pay by invoice | Others | +:-----------: | :-----------: | :-----------: | :-----------: | :-----------: | +iDEAL + QR |Visa | VVV Cadeaukaart | AfterPay | PayPal | +Bancontact + QR | Mastercard | Webshop Giftcard | Achteraf betalen via Billink | WeChatPay | +Giropay |American Express | FashionCheque | Focum AchterafBetalen.nl | AmazonPay | +MyBank | Carte Bancaire | Podium Cadeaukaart | Capayable Achteraf Betalen | Cashly | +SOFORT | PostePay | Gezondheidsbon | in3 keer betalen, 0% rente | Pay Fixed Price (phone) | +Maestro | Dankort | Fashion Giftcard | Klarna | Instore Payments (POS) | +Bank Transfer | Cartasi | GivaCard | SprayPay | Przelewy24 | +| Tikkie | De Cadeaukaart | YourGift | Creditclick | Apple Pay | +| Multibanco | | Paysafecard | | Payconiq +| | | Huis en Tuin Cadeau + + +# Requirements + + PHP 5.6 or higher + + +# Installation +#### Installing + +In command line, navigate to the installation directory of Omnipay + +Enter the following command: + +``` +composer require league/omnipay:^3 paynl/omnipay-paynl +``` + +The plugin is now installed + + +##### Setup + +1. Create a new php file +2. Use the following code: +``` +# require autoloader +require_once('vendor/autoload.php'); + +use Omnipay\Omnipay; + +# Setup payment gateway +$gateway = Omnipay::create('Paynl'); + +$gateway->setApiToken('abcdefgdjwaiodjwaodjaowidwad'); +$gateway->setTokenCode('AT-0000-0000'); +$gateway->setServiceId('SL-0000-0000'); +``` +3. Enter the TokenCode, API token and serviceID (these can be found in the PAY. Admin Panel --> https://admin.pay.nl/programs/programs +4. Save the file +5. Require the file where you wish to use the plugin. + +Go to the *Manage* / *Services* tab in the PAY. Admin Panel to enable extra payment methods. + + +#### Update instructions + +In command line, navigate to the installation directory of Omnipay + +Enter the following command: + +``` +composer update league/omnipay:^3 paynl/omnipay-paynl +``` + +The plugin has now been updated + + +# Usage + +Start a transaction + +``` +# Send purchase request +$response = $gateway->purchase( + [ + 'amount' => '10.00', + 'currency' => 'USD', + 'transactionReference' => 'referenceID1', + 'clientIp' => '192.168.192.12', + 'returnUrl' => 'https://omnipay/return', + 'items' => array( + array( + 'name' => 10, + 'price' => '5.00', + 'description' => 'Product 1 Desc', + 'quantity' => 2, + 'ProductId' => 1 + ), + array( + 'name' => 12, + 'price' => '5.00', + 'description' => 'Shipping for Product 1', + 'quantity' => 1, + 'ProductId' => 1 + ), + array( + 'name' => 12, + 'price' => '0.00', + 'description' => 'Promotion', + 'quantity' => 1, + 'ProductId' => 1 + ), + ), + 'card' => array( + 'firstName' => 'Example', + 'lastName' => 'User', + 'number' => '1111111111111111', + 'expiryMonth' => 7, + 'expiryYear' => 2022, + 'cvv' => 123, + 'address1' => '123 Shipping St', + 'address2' => 'Shipsville', + 'city' => 'Shipstown', + 'postcode' => '54321', + 'state' => 'NY', + 'country' => 'US', + 'phone' => '(123) 123-6543', + 'email' => 'john@example.com', + ) + ] +)->send(); + +# Process response +if ($response->isSuccessful()) { + + # Payment was successful + print_r($response); + +} elseif ($response->isRedirect()) { + + # Redirect to offsite payment gateway + # $response->redirect() + print_r($response); + +} else { + + # Payment failed + echo $response->getMessage(); +} +``` + +Refund a transaction +``` +$response = $gateway->refund([ + 'transactionReference' => "PAY. transactionId", + 'amount' => '10.00', + 'currency' => 'USD', + 'transactionId' => 765897 +])->send(); + +if ($response->isSuccessful()) { + + # Refund was successful + print_r($response); + +} else { + + # Refund failed + echo $response->getMessage(); +} + +``` + +Capture a transaction +``` +$response = $gateway->capture([ + 'transactionReference' => "PAY. transactionId", + 'amount' => '10.00', + 'currency' => 'USD', + 'transactionId' => 765897, + 'items' => array( + array( + 'name' => 10, + 'price' => '5.00', + 'description' => 'Product 1 Desc', + 'quantity' => 2, + 'ProductId' => 1 + ), + array( + 'name' => 12, + 'price' => '5.00', + 'description' => 'Shipping for Product 1', + 'quantity' => 1, + 'ProductId' => 1 + ), + array( + 'name' => 12, + 'price' => '0.00', + 'description' => 'Promotion', + 'quantity' => 1, + 'ProductId' => 1 + ), + ), +])->send(); + +if ($response->isSuccessful()) { + + # Capture was successful + print_r($response); + +} else { + + # Capture failed + echo $response->getMessage(); +} +``` + +# Support +https://www.pay.nl + +Contact us: support@pay.nl From 19d970d61b4e1e129c04af91175c522c5430216b Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Wed, 3 Feb 2021 15:28:05 +0100 Subject: [PATCH 6/6] Update README.md --- README.md | 133 +++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 530c17e..6bb39cc 100644 --- a/README.md +++ b/README.md @@ -90,55 +90,81 @@ The plugin has now been updated # Usage + +PAY. items +``` +# Use PAY. Item class +use Omnipay\Paynl\Common\Item; + +# Add items to transaction +$arrItems = array(); +$item = new Item(); +$item->setProductId('SKU01') + ->setProductType('ARTICLE') + ->setVatPercentage(21) + ->setDescription('Description') + ->setName('PAY. article') + ->setPrice('10') + ->setQuantity(4); +$arrItems[] = $item; + +$item = new Item(); +$item->setProductId('SHIP01') + ->setProductType('SHIPPING') + ->setVatPercentage(21) + ->setDescription('Description') + ->setName('PAY. shipping') + ->setPrice('5') + ->setQuantity(1); +$arrItems[] = $item; + +$item = new Item(); +$item->setProductId('SKU02') + ->setProductType('DISCOUNT') + ->setVatPercentage(21) + ->setDescription('Description') + ->setName('PAY. promotion') + ->setPrice('1') + ->setQuantity(1); +$arrItems[] = $item; +``` + Start a transaction ``` # Send purchase request $response = $gateway->purchase( [ - 'amount' => '10.00', + 'amount' => '46.00', 'currency' => 'USD', 'transactionReference' => 'referenceID1', 'clientIp' => '192.168.192.12', - 'returnUrl' => 'https://omnipay/return', - 'items' => array( - array( - 'name' => 10, - 'price' => '5.00', - 'description' => 'Product 1 Desc', - 'quantity' => 2, - 'ProductId' => 1 - ), - array( - 'name' => 12, - 'price' => '5.00', - 'description' => 'Shipping for Product 1', - 'quantity' => 1, - 'ProductId' => 1 - ), - array( - 'name' => 12, - 'price' => '0.00', - 'description' => 'Promotion', - 'quantity' => 1, - 'ProductId' => 1 - ), - ), + 'returnUrl' => 'http://dev.local:8080/pay.php', + 'items' => $arrItems, 'card' => array( 'firstName' => 'Example', 'lastName' => 'User', - 'number' => '1111111111111111', - 'expiryMonth' => 7, - 'expiryYear' => 2022, - 'cvv' => 123, - 'address1' => '123 Shipping St', - 'address2' => 'Shipsville', - 'city' => 'Shipstown', - 'postcode' => '54321', - 'state' => 'NY', - 'country' => 'US', - 'phone' => '(123) 123-6543', + 'gender' => 'M', + 'birthday' => '01-02-1992', + 'phone' => '1111111111111111', 'email' => 'john@example.com', + 'country' => 'NL', + + 'shippingAddress1' => 'Shippingstreet 1B', + 'shippingAddress2' => '', + 'shippingCity' => 'Shipingtown', + 'shippingPostcode' => '1234AB', + 'shippingState' => '', + 'country' => 'NL', + + 'billingFirstName' => 'Billingexample', + 'billingLastName' => 'Billinguser', + 'billingAddress1' => 'Billingstreet 1B', + 'billingAddress2' => '', + 'billingCity' => 'Billingtown', + 'billingPostcode' => '1234AB', + 'billingState' => '', + 'country' => 'NL' ) ] )->send(); @@ -147,13 +173,13 @@ $response = $gateway->purchase( if ($response->isSuccessful()) { # Payment was successful - print_r($response); + var_dump($response); } elseif ($response->isRedirect()) { # Redirect to offsite payment gateway - # $response->redirect() - print_r($response); + # $response->redirect(); + var_dump($response); } else { @@ -166,7 +192,7 @@ Refund a transaction ``` $response = $gateway->refund([ 'transactionReference' => "PAY. transactionId", - 'amount' => '10.00', + 'amount' => '46.00', 'currency' => 'USD', 'transactionId' => 765897 ])->send(); @@ -188,32 +214,7 @@ Capture a transaction ``` $response = $gateway->capture([ 'transactionReference' => "PAY. transactionId", - 'amount' => '10.00', - 'currency' => 'USD', - 'transactionId' => 765897, - 'items' => array( - array( - 'name' => 10, - 'price' => '5.00', - 'description' => 'Product 1 Desc', - 'quantity' => 2, - 'ProductId' => 1 - ), - array( - 'name' => 12, - 'price' => '5.00', - 'description' => 'Shipping for Product 1', - 'quantity' => 1, - 'ProductId' => 1 - ), - array( - 'name' => 12, - 'price' => '0.00', - 'description' => 'Promotion', - 'quantity' => 1, - 'ProductId' => 1 - ), - ), + 'items' => $arrItems ])->send(); if ($response->isSuccessful()) {