From 9d0bc10d1b3d8241fde490b35ea6220ab2e6209c Mon Sep 17 00:00:00 2001 From: frederik Date: Tue, 30 Sep 2014 16:24:44 +0200 Subject: [PATCH 1/6] Mollie API also allows a webhookUrl. The PurchaseRequest now accepts this parameter. For more info: https://www.mollie.nl/files/documentatie/payments-api.html --- composer.json | 76 +++++++++++++-------------- src/Message/PurchaseRequest.php | 16 ++++++ tests/Message/PurchaseRequestTest.php | 25 +++++++++ 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 48ebe06..cf4aff1 100644 --- a/composer.json +++ b/composer.json @@ -1,39 +1,39 @@ { - "name": "omnipay/mollie", - "type": "library", - "description": "Mollie driver for the Omnipay payment processing library", - "keywords": [ - "gateway", - "merchant", - "mollie", - "omnipay", - "pay", - "payment" - ], - "homepage": "https://github.com/thephpleague/omnipay-mollie", - "license": "MIT", - "authors": [ - { - "name": "Adrian Macneil", - "email": "adrian@adrianmacneil.com" - }, - { - "name": "Omnipay Contributors", - "homepage": "https://github.com/thephpleague/omnipay-mollie/contributors" - } - ], - "autoload": { - "psr-4": { "Omnipay\\Mollie\\" : "src/" } - }, - "require": { - "omnipay/common": "~2.2" - }, - "require-dev": { - "omnipay/tests": "~2.0" - }, - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - } -} + "name" : "omnipay/mollie", + "type" : "library", + "description" : "Mollie driver for the Omnipay payment processing library", + "keywords" : [ + "gateway", + "merchant", + "mollie", + "omnipay", + "pay", + "payment" + ], + "homepage" : "https://github.com/thephpleague/omnipay-mollie", + "license" : "MIT", + "authors" : [{ + "name" : "Adrian Macneil", + "email" : "adrian@adrianmacneil.com" + }, { + "name" : "Omnipay Contributors", + "homepage" : "https://github.com/thephpleague/omnipay-mollie/contributors" + } + ], + "autoload" : { + "psr-4" : { + "Omnipay\\Mollie\\" : "src/" + } + }, + "require" : { + "omnipay/common" : "~2.2" + }, + "require-dev" : { + "omnipay/tests" : "~2.0" + }, + "extra" : { + "branch-alias" : { + "dev-master" : "2.0.x-dev" + } + } +} \ No newline at end of file diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index b6a57c3..19d07e4 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -18,6 +18,16 @@ public function setMetadata($value) { return $this->setParameter('metadata', $value); } + + public function setWebhookUrl ($value) + { + $this->setParameter('webhookUrl', $value); + } + + public function getWebhookUrl () + { + return $this->getParameter('webhookUrl'); + } public function getData() { @@ -30,6 +40,12 @@ public function getData() $data['method'] = $this->getPaymentMethod(); $data['metadata'] = $this->getMetadata(); $data['issuer'] = $this->getIssuer(); + + $webhookUrl = $this->getWebhookUrl(); + if (null !== $webhookUrl) + { + $data['webhookUrl'] = $webhookUrl; + } return $data; } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index f659c9c..4dbb9a3 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -47,6 +47,31 @@ public function testGetData() $this->assertSame('my bank', $data['issuer']); $this->assertCount(6, $data); } + + public function testGetDataWithWebhook() + { + $this->request->initialize(array( + 'apiKey' => 'mykey', + 'amount' => '12.00', + 'description' => 'Description', + 'returnUrl' => 'https://www.example.com/return', + 'paymentMethod' => 'ideal', + 'metadata' => 'meta', + 'issuer' => 'my bank', + 'webhookUrl' => 'https://www.example.com/hook', + )); + + $data = $this->request->getData(); + + $this->assertSame("12.00", $data['amount']); + $this->assertSame('Description', $data['description']); + $this->assertSame('https://www.example.com/return', $data['redirectUrl']); + $this->assertSame('ideal', $data['method']); + $this->assertSame('meta', $data['metadata']); + $this->assertSame('my bank', $data['issuer']); + $this->assertSame('https://www.example.com/hook', $data['webhookUrl']); + $this->assertCount(7, $data); + } public function testSendSuccess() { From 3ff185ab4499a24145d84d2eb072c890ee0663c9 Mon Sep 17 00:00:00 2001 From: frederik Date: Tue, 30 Sep 2014 16:27:33 +0200 Subject: [PATCH 2/6] composer.json was modified by my IDE, reverted --- composer.json | 76 +++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index cf4aff1..48ebe06 100644 --- a/composer.json +++ b/composer.json @@ -1,39 +1,39 @@ { - "name" : "omnipay/mollie", - "type" : "library", - "description" : "Mollie driver for the Omnipay payment processing library", - "keywords" : [ - "gateway", - "merchant", - "mollie", - "omnipay", - "pay", - "payment" - ], - "homepage" : "https://github.com/thephpleague/omnipay-mollie", - "license" : "MIT", - "authors" : [{ - "name" : "Adrian Macneil", - "email" : "adrian@adrianmacneil.com" - }, { - "name" : "Omnipay Contributors", - "homepage" : "https://github.com/thephpleague/omnipay-mollie/contributors" - } - ], - "autoload" : { - "psr-4" : { - "Omnipay\\Mollie\\" : "src/" - } - }, - "require" : { - "omnipay/common" : "~2.2" - }, - "require-dev" : { - "omnipay/tests" : "~2.0" - }, - "extra" : { - "branch-alias" : { - "dev-master" : "2.0.x-dev" - } - } -} \ No newline at end of file + "name": "omnipay/mollie", + "type": "library", + "description": "Mollie driver for the Omnipay payment processing library", + "keywords": [ + "gateway", + "merchant", + "mollie", + "omnipay", + "pay", + "payment" + ], + "homepage": "https://github.com/thephpleague/omnipay-mollie", + "license": "MIT", + "authors": [ + { + "name": "Adrian Macneil", + "email": "adrian@adrianmacneil.com" + }, + { + "name": "Omnipay Contributors", + "homepage": "https://github.com/thephpleague/omnipay-mollie/contributors" + } + ], + "autoload": { + "psr-4": { "Omnipay\\Mollie\\" : "src/" } + }, + "require": { + "omnipay/common": "~2.2" + }, + "require-dev": { + "omnipay/tests": "~2.0" + }, + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + } +} From 0750e197943067b99b396281218f3e6a90c17ad7 Mon Sep 17 00:00:00 2001 From: frederik Date: Tue, 30 Sep 2014 16:40:39 +0200 Subject: [PATCH 3/6] code conventions: PSR2 --- src/Message/PurchaseRequest.php | 25 ++++++++++++------------- tests/Message/PurchaseRequestTest.php | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 19d07e4..27005c3 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -1,5 +1,4 @@ getParameter('metadata'); @@ -18,21 +18,21 @@ public function setMetadata($value) { return $this->setParameter('metadata', $value); } - - public function setWebhookUrl ($value) + + public function setWebhookUrl($value) { - $this->setParameter('webhookUrl', $value); + $this->setParameter('webhookUrl', $value); } - - public function getWebhookUrl () + + public function getWebhookUrl() { - return $this->getParameter('webhookUrl'); + return $this->getParameter('webhookUrl'); } public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); - + $data = array(); $data['amount'] = $this->getAmount(); $data['description'] = $this->getDescription(); @@ -42,18 +42,17 @@ public function getData() $data['issuer'] = $this->getIssuer(); $webhookUrl = $this->getWebhookUrl(); - if (null !== $webhookUrl) - { - $data['webhookUrl'] = $webhookUrl; + if (null !== $webhookUrl) { + $data['webhookUrl'] = $webhookUrl; } - + return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('POST', '/payments', $data); - + return $this->response = new PurchaseResponse($this, $httpResponse->json()); } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 4dbb9a3..d2dbe5f 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -1,12 +1,13 @@ 'Description', 'returnUrl' => 'https://www.example.com/return', 'method' => 'ideal', - 'metadata' => 'meta', + 'metadata' => 'meta' )); } @@ -34,11 +35,11 @@ public function testGetData() 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', 'metadata' => 'meta', - 'issuer' => 'my bank', + 'issuer' => 'my bank' )); - + $data = $this->request->getData(); - + $this->assertSame("12.00", $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); @@ -47,7 +48,7 @@ public function testGetData() $this->assertSame('my bank', $data['issuer']); $this->assertCount(6, $data); } - + public function testGetDataWithWebhook() { $this->request->initialize(array( @@ -58,11 +59,11 @@ public function testGetDataWithWebhook() 'paymentMethod' => 'ideal', 'metadata' => 'meta', 'issuer' => 'my bank', - 'webhookUrl' => 'https://www.example.com/hook', + 'webhookUrl' => 'https://www.example.com/hook' )); - + $data = $this->request->getData(); - + $this->assertSame("12.00", $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); @@ -77,7 +78,7 @@ public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); - + $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); @@ -95,7 +96,7 @@ public function testSendFailure() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); - + $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); From 87000b99e565905752d67c7dd33f266849b5f498 Mon Sep 17 00:00:00 2001 From: frederik Date: Wed, 15 Oct 2014 15:57:23 +0200 Subject: [PATCH 4/6] webhookUrl -> notifyUrl --- src/Message/PurchaseRequest.php | 10 +++++----- tests/Message/PurchaseRequestTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 27005c3..bd4685c 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -19,14 +19,14 @@ public function setMetadata($value) return $this->setParameter('metadata', $value); } - public function setWebhookUrl($value) + public function setNotifyUrl($value) { - $this->setParameter('webhookUrl', $value); + $this->setParameter('notifyUrl', $value); } - public function getWebhookUrl() + public function getNotifyUrl() { - return $this->getParameter('webhookUrl'); + return $this->getParameter('notifyUrl'); } public function getData() @@ -41,7 +41,7 @@ public function getData() $data['metadata'] = $this->getMetadata(); $data['issuer'] = $this->getIssuer(); - $webhookUrl = $this->getWebhookUrl(); + $webhookUrl = $this->getNotifyUrl(); if (null !== $webhookUrl) { $data['webhookUrl'] = $webhookUrl; } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index d2dbe5f..83ad669 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -59,7 +59,7 @@ public function testGetDataWithWebhook() 'paymentMethod' => 'ideal', 'metadata' => 'meta', 'issuer' => 'my bank', - 'webhookUrl' => 'https://www.example.com/hook' + 'notifyUrl' => 'https://www.example.com/hook' )); $data = $this->request->getData(); From 15b992e634183c8750a77ac4c46ffb90fdeacdf1 Mon Sep 17 00:00:00 2001 From: frederik Date: Wed, 15 Oct 2014 16:07:20 +0200 Subject: [PATCH 5/6] removed methods, they are already available in AbstractRequest --- src/Message/PurchaseRequest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index bd4685c..630cf9c 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -19,16 +19,6 @@ public function setMetadata($value) return $this->setParameter('metadata', $value); } - public function setNotifyUrl($value) - { - $this->setParameter('notifyUrl', $value); - } - - public function getNotifyUrl() - { - return $this->getParameter('notifyUrl'); - } - public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); From e12dce94add64763ad2378a74dd923f2123a37f8 Mon Sep 17 00:00:00 2001 From: frederik Date: Wed, 15 Oct 2014 16:19:06 +0200 Subject: [PATCH 6/6] php cs fixer: removed white space --- src/Gateway.php | 2 +- src/Message/PurchaseRequest.php | 8 ++++---- tests/Message/PurchaseRequestTest.php | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 1d58ce0..cfe2988 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -38,7 +38,7 @@ public function getApiKey() } /** - * @param string $value + * @param string $value * @return $this */ public function setApiKey($value) diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 630cf9c..909a4b8 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -22,7 +22,7 @@ public function setMetadata($value) public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); - + $data = array(); $data['amount'] = $this->getAmount(); $data['description'] = $this->getDescription(); @@ -30,19 +30,19 @@ public function getData() $data['method'] = $this->getPaymentMethod(); $data['metadata'] = $this->getMetadata(); $data['issuer'] = $this->getIssuer(); - + $webhookUrl = $this->getNotifyUrl(); if (null !== $webhookUrl) { $data['webhookUrl'] = $webhookUrl; } - + return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('POST', '/payments', $data); - + return $this->response = new PurchaseResponse($this, $httpResponse->json()); } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 83ad669..0c209b8 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -37,9 +37,9 @@ public function testGetData() 'metadata' => 'meta', 'issuer' => 'my bank' )); - + $data = $this->request->getData(); - + $this->assertSame("12.00", $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); @@ -61,9 +61,9 @@ public function testGetDataWithWebhook() 'issuer' => 'my bank', 'notifyUrl' => 'https://www.example.com/hook' )); - + $data = $this->request->getData(); - + $this->assertSame("12.00", $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); @@ -78,7 +78,7 @@ public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); - + $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); @@ -96,7 +96,7 @@ public function testSendFailure() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); - + $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect());