From 50a4bc76dc63ffd4348ceef6ddcfc158bb33ec32 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Thu, 19 Jul 2018 13:31:23 +0200 Subject: [PATCH 01/25] Update the fetch issuer endpoint and some preparations --- .gitignore | 1 + composer.json | 3 ++ src/Gateway.php | 20 ++++---- src/Message/AbstractRequest.php | 6 ++- src/Message/AbstractResponse.php | 8 +-- src/Message/CompletePurchaseRequest.php | 2 +- src/Message/CreateCustomerRequest.php | 4 +- src/Message/FetchCustomerRequest.php | 4 +- src/Message/FetchIssuersRequest.php | 9 +++- src/Message/FetchIssuersResponse.php | 8 +-- src/Message/FetchPaymentMethodsResponse.php | 2 +- src/Message/FetchTransactionRequest.php | 2 +- src/Message/PurchaseRequest.php | 2 +- src/Message/RefundRequest.php | 2 +- src/Message/UpdateCustomerRequest.php | 4 +- tests/Message/AssertRequestTrait.php | 13 +++++ tests/Message/CompletePurchaseRequestTest.php | 3 +- tests/Message/CreateCustomerRequestTest.php | 3 +- tests/Message/FetchCustomerRequestTest.php | 3 +- tests/Message/FetchIssuersRequestTest.php | 19 +++++-- .../FetchPaymentMethodsRequestTest.php | 3 +- tests/Message/FetchTransactionRequestTest.php | 3 +- tests/Message/PurchaseRequestTest.php | 3 +- tests/Message/RefundRequestTest.php | 3 +- tests/Message/UpdateCustomerRequestTest.php | 3 +- tests/Mock/FetchIssuersFailure.txt | 12 +++-- tests/Mock/FetchIssuersSuccess.txt | 49 ++++++++++++++----- 27 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 tests/Message/AssertRequestTrait.php diff --git a/.gitignore b/.gitignore index 8a282a5..a00f07e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock composer.phar phpunit.xml +/.idea diff --git a/composer.json b/composer.json index 65e2d05..85512d4 100755 --- a/composer.json +++ b/composer.json @@ -29,6 +29,9 @@ "autoload": { "psr-4": { "Omnipay\\Mollie\\" : "src/" } }, + "autoload-dev": { + "psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" } + }, "require": { "omnipay/common": "^3" }, diff --git a/src/Gateway.php b/src/Gateway.php index d1f8751..8e5b1c0 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -50,16 +50,16 @@ public function setApiKey($value) * @param array $parameters * @return \Omnipay\Mollie\Message\FetchIssuersRequest */ - public function fetchIssuers(array $parameters = array()) + public function fetchIssuers(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\FetchIssuersRequest', $parameters); + return $this->createRequest(\Omnipay\Mollie\Message\FetchIssuersRequest::class, $parameters); } /** * @param array $parameters * @return \Omnipay\Mollie\Message\FetchPaymentMethodsRequest */ - public function fetchPaymentMethods(array $parameters = array()) + public function fetchPaymentMethods(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\FetchPaymentMethodsRequest', $parameters); } @@ -68,7 +68,7 @@ public function fetchPaymentMethods(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\FetchTransactionRequest */ - public function fetchTransaction(array $parameters = array()) + public function fetchTransaction(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\FetchTransactionRequest', $parameters); } @@ -77,7 +77,7 @@ public function fetchTransaction(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\PurchaseRequest */ - public function purchase(array $parameters = array()) + public function purchase(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\PurchaseRequest', $parameters); } @@ -86,7 +86,7 @@ public function purchase(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\CompletePurchaseRequest */ - public function completePurchase(array $parameters = array()) + public function completePurchase(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\CompletePurchaseRequest', $parameters); } @@ -95,7 +95,7 @@ public function completePurchase(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\RefundRequest */ - public function refund(array $parameters = array()) + public function refund(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\RefundRequest', $parameters); } @@ -104,7 +104,7 @@ public function refund(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\CreateCustomerRequest */ - public function createCustomer(array $parameters = array()) + public function createCustomer(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\CreateCustomerRequest', $parameters); } @@ -113,7 +113,7 @@ public function createCustomer(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\UpdateCustomerRequest */ - public function updateCustomer(array $parameters = array()) + public function updateCustomer(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\UpdateCustomerRequest', $parameters); } @@ -122,7 +122,7 @@ public function updateCustomer(array $parameters = array()) * @param array $parameters * @return \Omnipay\Mollie\Message\FetchCustomerRequest */ - public function fetchCustomer(array $parameters = array()) + public function fetchCustomer(array $parameters = []) { return $this->createRequest('\Omnipay\Mollie\Message\FetchCustomerRequest', $parameters); } diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 9e8ddb4..cbe53fd 100755 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -4,7 +4,9 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - protected $endpoint = 'https://api.mollie.nl/v1'; + protected $apiVersion = "v2"; + + protected $baseUrl = 'https://api.mollie.com/'; public function getApiKey() { @@ -30,7 +32,7 @@ protected function sendRequest($method, $endpoint, $data = null) { $response = $this->httpClient->request( $method, - $this->endpoint . $endpoint, + $this->baseUrl . $this->apiVersion . $endpoint, array( 'Authorization' => 'Bearer ' . $this->getApiKey() ), diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index 7929545..902af7f 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -6,13 +6,15 @@ class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse { public function isSuccessful() { - return !$this->isRedirect() && !isset($this->data['error']); + return !isset($this->data['status']) || ($this->data['status'] >= 200 && $this->data['status'] < 300); } public function getMessage() { - if (isset($this->data['error'])) { - return $this->data['error']['message']; + if (isset($this->data['title']) && isset($this->data['detail'])) { + return json_encode($this->data); } + + return "Request is successful."; } } diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 5db02a9..73e1d62 100755 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -15,7 +15,7 @@ public function getData() { $this->validate('apiKey'); - $data = array(); + $data = []; $data['id'] = $this->getTransactionReference(); if (!isset($data['id'])) { diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index a37d301..061744b 100755 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -79,7 +79,7 @@ public function getData() { $this->validate('apiKey', 'description', 'email'); - $data = array(); + $data = []; $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); $data['metadata'] = $this->getMetadata(); @@ -108,6 +108,6 @@ public function sendData($data) */ public function getEndpoint() { - return $this->endpoint.'/customers'; + return $this->baseUrl.'/customers'; } } diff --git a/src/Message/FetchCustomerRequest.php b/src/Message/FetchCustomerRequest.php index fdb9991..fca0115 100755 --- a/src/Message/FetchCustomerRequest.php +++ b/src/Message/FetchCustomerRequest.php @@ -33,7 +33,7 @@ public function getData() { $this->validate('apiKey', 'customerReference'); - return array(); + return []; } /** @@ -52,6 +52,6 @@ public function sendData($data) */ public function getEndpoint() { - return $this->endpoint.'/customers'; + return $this->baseUrl.'/customers'; } } diff --git a/src/Message/FetchIssuersRequest.php b/src/Message/FetchIssuersRequest.php index ec1da97..438c982 100755 --- a/src/Message/FetchIssuersRequest.php +++ b/src/Message/FetchIssuersRequest.php @@ -9,17 +9,22 @@ */ class FetchIssuersRequest extends AbstractRequest { + + protected $endpoint = '/methods/ideal?include=issuers'; + /** - * @return null + * @return array */ public function getData() { $this->validate('apiKey'); + + return []; } public function sendData($data) { - $response = $this->sendRequest('GET', '/issuers'); + $response = $this->sendRequest('GET', $this->endpoint); return $this->response = new FetchIssuersResponse($this, $response); } diff --git a/src/Message/FetchIssuersResponse.php b/src/Message/FetchIssuersResponse.php index 5febdfe..1f3e114 100644 --- a/src/Message/FetchIssuersResponse.php +++ b/src/Message/FetchIssuersResponse.php @@ -14,10 +14,10 @@ class FetchIssuersResponse extends AbstractResponse implements FetchIssuersRespo */ public function getIssuers() { - if (isset($this->data['data'])) { - $issuers = array(); - foreach ($this->data['data'] as $issuer) { - $issuers[] = new Issuer($issuer['id'], $issuer['name'], $issuer['method']); + if (isset($this->data['issuers'])) { + $issuers = []; + foreach ($this->data['issuers'] as $issuer) { + $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); } return $issuers; diff --git a/src/Message/FetchPaymentMethodsResponse.php b/src/Message/FetchPaymentMethodsResponse.php index dbbbc4e..7f4cd01 100644 --- a/src/Message/FetchPaymentMethodsResponse.php +++ b/src/Message/FetchPaymentMethodsResponse.php @@ -15,7 +15,7 @@ class FetchPaymentMethodsResponse extends AbstractResponse implements FetchPayme public function getPaymentMethods() { if (isset($this->data['data'])) { - $paymentMethods = array(); + $paymentMethods = []; foreach ($this->data['data'] as $method) { $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index 1e383a4..63556fd 100755 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -13,7 +13,7 @@ public function getData() { $this->validate('apiKey', 'transactionReference'); - $data = array(); + $data = []; $data['id'] = $this->getTransactionReference(); return $data; diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 4cb1273..4847c33 100755 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -42,7 +42,7 @@ public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); - $data = array(); + $data = []; $data['amount'] = $this->getAmount(); $data['description'] = $this->getDescription(); $data['redirectUrl'] = $this->getReturnUrl(); diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 217a66c..7db160b 100755 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -9,7 +9,7 @@ public function getData() { $this->validate('apiKey', 'transactionReference'); - $data = array(); + $data = []; if ($this->getAmountInteger() > 0) { $data['amount'] = $this->getAmount(); } diff --git a/src/Message/UpdateCustomerRequest.php b/src/Message/UpdateCustomerRequest.php index 5f2c2cd..1f94980 100755 --- a/src/Message/UpdateCustomerRequest.php +++ b/src/Message/UpdateCustomerRequest.php @@ -98,7 +98,7 @@ public function getData() { $this->validate('apiKey', 'customerReference'); - $data = array(); + $data = []; $data['id'] = $this->getCustomerReference(); $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); @@ -128,6 +128,6 @@ public function sendData($data) */ public function getEndpoint() { - return $this->endpoint.'/customers/'.$this->getCustomerReference(); + return $this->baseUrl.'/customers/'.$this->getCustomerReference(); } } diff --git a/tests/Message/AssertRequestTrait.php b/tests/Message/AssertRequestTrait.php new file mode 100644 index 0000000..92edd53 --- /dev/null +++ b/tests/Message/AssertRequestTrait.php @@ -0,0 +1,13 @@ +assertEquals($expectedRequest->getUri(), $actualRequest->getUri(), "Request Uri should be the same."); + } +} \ No newline at end of file diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index eb339d1..3d20d7d 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -1,7 +1,8 @@ setMockHttpResponse('FetchIssuersSuccess.txt'); $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); + $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); - $expectedIssuer = new Issuer('ideal_TESTNL99', 'TBM Bank', 'ideal'); - $this->assertEquals(array($expectedIssuer), $response->getIssuers()); + + $expectedIssuer = new Issuer('ideal_ABNANL2A', 'ABN AMRO', 'ideal'); + $expectedIssuer2 = new Issuer('ideal_ASNBNL21', 'ASN Bank', 'ideal'); + + $this->assertEquals(array($expectedIssuer, $expectedIssuer2), $response->getIssuers()); } public function testSendFailure() @@ -45,11 +53,14 @@ public function testSendFailure() $this->setMockHttpResponse('FetchIssuersFailure.txt'); $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); + $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); - $this->assertSame('Unauthorized request', $response->getMessage()); + $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); $this->assertNull($response->getIssuers()); } + } diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php index d84a918..4fcf4ed 100644 --- a/tests/Message/FetchPaymentMethodsRequestTest.php +++ b/tests/Message/FetchPaymentMethodsRequestTest.php @@ -1,8 +1,9 @@ Date: Thu, 19 Jul 2018 14:33:14 +0200 Subject: [PATCH 02/25] Update payment request to v2 --- src/Message/AbstractResponse.php | 2 - src/Message/FetchTransactionResponse.php | 26 +++--- src/Message/PurchaseRequest.php | 11 ++- tests/Message/AssertRequestTrait.php | 8 +- tests/Message/PurchaseRequestTest.php | 100 ++++++++++++----------- tests/Mock/PurchaseFailure.txt | 19 ----- tests/Mock/PurchaseIssuerFailure.txt | 26 +++--- tests/Mock/PurchaseSuccess.txt | 60 ++++++++------ tests/Mock/PurchaseSystemFailure.txt | 18 ---- 9 files changed, 128 insertions(+), 142 deletions(-) delete mode 100644 tests/Mock/PurchaseFailure.txt delete mode 100644 tests/Mock/PurchaseSystemFailure.txt diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index 902af7f..1758e8f 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -14,7 +14,5 @@ public function getMessage() if (isset($this->data['title']) && isset($this->data['detail'])) { return json_encode($this->data); } - - return "Request is successful."; } } diff --git a/src/Message/FetchTransactionResponse.php b/src/Message/FetchTransactionResponse.php index 99a151f..eefac74 100644 --- a/src/Message/FetchTransactionResponse.php +++ b/src/Message/FetchTransactionResponse.php @@ -9,27 +9,27 @@ class FetchTransactionResponse extends AbstractResponse implements RedirectRespo /** * {@inheritdoc} */ - public function isRedirect() + public function getRedirectMethod() { - return isset($this->data['links']['paymentUrl']); + return 'GET'; } /** * {@inheritdoc} */ - public function getRedirectUrl() + public function isRedirect() { - if ($this->isRedirect()) { - return $this->data['links']['paymentUrl']; - } + return isset($this->data['_links']['checkout']['href']); } /** * {@inheritdoc} */ - public function getRedirectMethod() + public function getRedirectUrl() { - return 'GET'; + if ($this->isRedirect()) { + return $this->data['_links']['checkout']['href']; + } } /** @@ -61,7 +61,7 @@ public function isOpen() */ public function isCancelled() { - return isset($this->data['status']) && 'cancelled' === $this->data['status']; + return isset($this->data['status']) && 'canceled' === $this->data['status']; } /** @@ -69,7 +69,7 @@ public function isCancelled() */ public function isPaid() { - return isset($this->data['status']) && 'paid' === $this->data['status']; + return isset($this->data['paidAt']) && !empty($this->data['paidAt']); } /** @@ -77,7 +77,7 @@ public function isPaid() */ public function isPaidOut() { - return isset($this->data['status']) && 'paidout' === $this->data['status']; + return isset($this->data['_links']['settlement']); } /** @@ -90,12 +90,12 @@ public function isExpired() public function isRefunded() { - return isset($this->data['status']) && 'refunded' === $this->data['status']; + return isset($this->data['_links']['refunds']); } public function isPartialRefunded() { - return $this->isRefunded() && isset($this->data['amountRemaining']) && $this->data['amountRemaining'] > 0; + return $this->isRefunded() && isset($this->data['amountRemaining']) && $this->data['amountRemaining']['value'] > 0; } /** diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 4847c33..fc5f894 100755 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -42,12 +42,15 @@ public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); - $data = []; - $data['amount'] = $this->getAmount(); + $data = []; + $data['amount'] = [ + "value" => $this->getAmount(), + "currency" => $this->getCurrency() + ]; $data['description'] = $this->getDescription(); $data['redirectUrl'] = $this->getReturnUrl(); - $data['method'] = $this->getPaymentMethod(); - $data['metadata'] = $this->getMetadata(); + $data['method'] = $this->getPaymentMethod(); + $data['metadata'] = $this->getMetadata(); if ($this->getTransactionId()) { $data['metadata']['transactionId'] = $this->getTransactionId(); diff --git a/tests/Message/AssertRequestTrait.php b/tests/Message/AssertRequestTrait.php index 92edd53..ff9a6a4 100644 --- a/tests/Message/AssertRequestTrait.php +++ b/tests/Message/AssertRequestTrait.php @@ -6,8 +6,14 @@ trait AssertRequestTrait { abstract function assertEquals($expected, $actual, $message = null); + abstract function assertJsonStringEqualsJsonString($expected, $actual, $message = null); + public function assertEqualRequest(\Psr\Http\Message\RequestInterface $expectedRequest, \Psr\Http\Message\RequestInterface $actualRequest) { - $this->assertEquals($expectedRequest->getUri(), $actualRequest->getUri(), "Request Uri should be the same."); + $this->assertEquals($expectedRequest->getUri(), $actualRequest->getUri(), "Expected request Uri should be equal to actual request body."); + + if(!empty((string) $expectedRequest->getBody())) { + $this->assertJsonStringEqualsJsonString((string) $expectedRequest->getBody(), (string) $actualRequest->getBody(), "Expected request Body should be equal to actual request body."); + } } } \ No newline at end of file diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index e288340..f2370bd 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -2,14 +2,15 @@ namespace Omnipay\Mollie\Test\Message; use Omnipay\Mollie\Message\PurchaseRequest; +use Omnipay\Mollie\Message\PurchaseResponse; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { + use AssertRequestTrait; /** - * - * @var \Omnipay\Mollie\Message\PurchaseRequest + * @var PurchaseRequest */ protected $request; @@ -19,6 +20,7 @@ public function setUp() $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', + 'currency' => 'USD', 'issuer' => 'my bank', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', @@ -31,21 +33,22 @@ public function setUp() public function testGetData() { - $this->request->initialize(array( - 'apiKey' => 'mykey', - 'amount' => '12.00', - 'description' => 'Description', - 'returnUrl' => 'https://www.example.com/return', + $this->request->initialize([ + 'apiKey' => 'mykey', + 'amount' => '12.00', + 'currency' => 'USD', + 'description' => 'Description', + 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', - 'metadata' => 'meta', - 'issuer' => 'my bank', - 'locale' => 'fr_FR', - 'billingEmail' => 'billing-email@example.com', - )); + 'metadata' => 'meta', + 'issuer' => 'my bank', + 'locale' => 'fr_FR', + 'billingEmail' => 'billing-email@example.com', + ]); $data = $this->request->getData(); - $this->assertSame("12.00", $data['amount']); + $this->assertSame(["value" => "12.00", "currency" => "USD"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); @@ -61,6 +64,7 @@ public function testGetDataWithWebhook() $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', + 'currency' => 'EUR', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', @@ -73,7 +77,7 @@ public function testGetDataWithWebhook() $data = $this->request->getData(); - $this->assertSame("12.00", $data['amount']); + $this->assertSame(["value" => "12.00", "currency" => "EUR"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); @@ -90,6 +94,7 @@ public function testNoIssuer() $this->request->initialize(array( 'apiKey' => 'mykey', 'amount' => '12.00', + 'currency' => 'SEK', 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', @@ -101,7 +106,7 @@ public function testNoIssuer() $data = $this->request->getData(); - $this->assertSame("12.00", $data['amount']); + $this->assertSame(["value" => "12.00", "currency" => "SEK"], $data['amount']); $this->assertSame('Description', $data['description']); $this->assertSame('https://www.example.com/return', $data['redirectUrl']); $this->assertSame('ideal', $data['method']); @@ -117,51 +122,54 @@ public function testSendSuccess() $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); + $this->assertEqualRequest( + new \GuzzleHttp\Psr7\Request( + "POST", + "https://api.mollie.com/v2/payments", + [], + '{ + "amount":{ + "value":"12.00", + "currency":"USD" + }, + "description":"Description", + "redirectUrl":"https:\/\/www.example.com\/return", + "method":null, + "metadata":"meta", + "issuer":"my bank", + "locale":"fr_FR", + "billingEmail":"billing-email@example.com" + }' + ), + $this->getMockClient()->getLastRequest() + ); + + + $this->assertInstanceOf(PurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('GET', $response->getRedirectMethod()); - $this->assertSame('https://www.mollie.nl/payscreen/pay/Qzin4iTWrU', $response->getRedirectUrl()); + $this->assertSame('https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); - $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); + $this->assertSame('tr_7UhSN1zuXS', $response->getTransactionReference()); $this->assertTrue($response->isOpen()); $this->assertFalse($response->isPaid()); $this->assertNull($response->getCode()); $this->assertNull($response->getMessage()); } - 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()); - $this->assertNull($response->getTransactionReference()); - $this->assertNull($response->getRedirectUrl()); - $this->assertNull($response->getRedirectData()); - $this->assertSame("The issuer is invalid", $response->getMessage()); - } - public function testIssuerFailure() { $this->setMockHttpResponse('PurchaseIssuerFailure.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); - $this->assertFalse($response->isSuccessful()); - $this->assertFalse($response->isRedirect()); - $this->assertNull($response->getTransactionReference()); - $this->assertNull($response->getRedirectUrl()); - $this->assertNull($response->getRedirectData()); - $this->assertSame("Issuer failure", $response->getMessage()); - } - - public function testSystemFailure() - { - $this->setMockHttpResponse('PurchaseSystemFailure.txt'); - $response = $this->request->send(); + $this->assertEqualRequest( + new \GuzzleHttp\Psr7\Request( + "POST", + "https://api.mollie.com/v2/payments" + ), + $this->getMockClient()->getLastRequest() + ); $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); @@ -169,6 +177,6 @@ public function testSystemFailure() $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); - $this->assertSame("Payment platform for this payment method temporarily not available", $response->getMessage()); + $this->assertSame('{"status":422,"title":"Unprocessable Entity","detail":"The payment method is invalid","field":"method","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } } diff --git a/tests/Mock/PurchaseFailure.txt b/tests/Mock/PurchaseFailure.txt deleted file mode 100644 index 06cfd7a..0000000 --- a/tests/Mock/PurchaseFailure.txt +++ /dev/null @@ -1,19 +0,0 @@ -HTTP/1.1 422 Unprocessable Entity -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:19:39 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 101 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains - -{ - "error":{ - "type":"request", - "message":"The issuer is invalid", - "field":"issuer" - } -} diff --git a/tests/Mock/PurchaseIssuerFailure.txt b/tests/Mock/PurchaseIssuerFailure.txt index 4c34eeb..d8051e4 100644 --- a/tests/Mock/PurchaseIssuerFailure.txt +++ b/tests/Mock/PurchaseIssuerFailure.txt @@ -1,19 +1,15 @@ -HTTP/1.1 503 Service Temporarily Unavailable -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:19:39 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 101 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains +HTTP/1.1 422 Unprocessable Entity +Content-Type: application/hal+json; charset=utf-8 { - "error":{ - "type":"system", - "message":"Issuer failure", - "field":"issuer" + "status": 422, + "title": "Unprocessable Entity", + "detail": "The payment method is invalid", + "field": "method", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/handling-errors", + "type": "text/html" + } } } diff --git a/tests/Mock/PurchaseSuccess.txt b/tests/Mock/PurchaseSuccess.txt index 3cc2326..0dd924e 100644 --- a/tests/Mock/PurchaseSuccess.txt +++ b/tests/Mock/PurchaseSuccess.txt @@ -1,28 +1,40 @@ HTTP/1.1 201 Created -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:41:55 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 344 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +Content-Type: application/hal+json; charset=utf-8 { - "id":"tr_Qzin4iTWrU", - "mode":"test", - "createdDatetime":"2014-01-19T11:41:55.0Z", - "status":"open", - "amount":"100.00", - "description":"Description", - "method":"ideal", - "metadata":"meta", - "details":null, - "links":{ - "paymentUrl":"https://www.mollie.nl/payscreen/pay/Qzin4iTWrU", - "redirectUrl":"http://www.google.nl" - } + "resource": "payment", + "id": "tr_7UhSN1zuXS", + "mode": "test", + "createdAt": "2018-03-20T09:13:37+00:00", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "description": "My first payment", + "method": null, + "metadata": { + "order_id": "12345" + }, + "status": "open", + "isCancelable": false, + "expiresAt": "2018-03-20T09:28:37+00:00", + "details": null, + "profileId": "pfl_QkEhN94Ba", + "sequenceType": "oneoff", + "redirectUrl": "https://webshop.example.org/order/12345/", + "webhookUrl": "https://webshop.example.org/payments/webhook/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/payments-api/create-payment", + "type": "text/html" + } + } } diff --git a/tests/Mock/PurchaseSystemFailure.txt b/tests/Mock/PurchaseSystemFailure.txt deleted file mode 100644 index 3de75a8..0000000 --- a/tests/Mock/PurchaseSystemFailure.txt +++ /dev/null @@ -1,18 +0,0 @@ -HTTP/1.1 503 Service Temporarily Unavailable -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:19:39 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 101 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains - -{ - "error":{ - "type":"system", - "message":"Payment platform for this payment method temporarily not available" - } -} From 5e2c4c29c16cd86a26c632b0a128676c2d4d8d19 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Thu, 19 Jul 2018 14:41:22 +0200 Subject: [PATCH 03/25] Signature update in order to be compatible with PHP unit --- tests/Message/AssertRequestTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Message/AssertRequestTrait.php b/tests/Message/AssertRequestTrait.php index ff9a6a4..20cc6f3 100644 --- a/tests/Message/AssertRequestTrait.php +++ b/tests/Message/AssertRequestTrait.php @@ -4,7 +4,7 @@ trait AssertRequestTrait { - abstract function assertEquals($expected, $actual, $message = null); + abstract function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false); abstract function assertJsonStringEqualsJsonString($expected, $actual, $message = null); From 7ff3931f044d01b2e4fcb1fd763f0f2cab2f90d0 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Thu, 19 Jul 2018 14:54:53 +0200 Subject: [PATCH 04/25] Update complete purchase request tests --- src/Message/AbstractResponse.php | 6 +- tests/Message/CompletePurchaseRequestTest.php | 18 ++--- tests/Mock/CompletePurchaseExpired.txt | 48 ++++++------- tests/Mock/CompletePurchaseFailure.txt | 19 ----- tests/Mock/CompletePurchaseSuccess.txt | 70 ++++++++++++------- 5 files changed, 80 insertions(+), 81 deletions(-) delete mode 100644 tests/Mock/CompletePurchaseFailure.txt diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index 1758e8f..18430e7 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -6,7 +6,11 @@ class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse { public function isSuccessful() { - return !isset($this->data['status']) || ($this->data['status'] >= 200 && $this->data['status'] < 300); + if(isset($this->data['status']) && isset($this->data['detail'])) { + return $this->data['status'] >= 200 && $this->data['status'] < 300; + } + + return true; } public function getMessage() diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index 3d20d7d..de4e5b3 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -7,6 +7,8 @@ class CompletePurchaseRequestTest extends TestCase { + use AssertRequestTrait; + /** * @var \Omnipay\Mollie\Message\CompletePurchaseRequest */ @@ -50,6 +52,8 @@ public function testSendSuccess() $this->setMockHttpResponse('CompletePurchaseSuccess.txt'); $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); + $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isOpen()); @@ -63,6 +67,8 @@ public function testSendExpired() $this->setMockHttpResponse('CompletePurchaseExpired.txt'); $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); + $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isPaid()); @@ -70,16 +76,4 @@ public function testSendExpired() $this->assertFalse($response->isRedirect()); $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); } - - public function testSendFailure() - { - $this->setMockHttpResponse('PurchaseFailure.txt'); - $response = $this->request->send(); - - $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response); - $this->assertFalse($response->isSuccessful()); - $this->assertFalse($response->isRedirect()); - $this->assertNull($response->getTransactionReference()); - $this->assertSame("The issuer is invalid", $response->getMessage()); - } } diff --git a/tests/Mock/CompletePurchaseExpired.txt b/tests/Mock/CompletePurchaseExpired.txt index 8a38c0b..6bc1757 100644 --- a/tests/Mock/CompletePurchaseExpired.txt +++ b/tests/Mock/CompletePurchaseExpired.txt @@ -1,28 +1,28 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 13:00:23 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 326 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-1 +Content-Type: application/hal+json; charset=utf-8 { - "id":"tr_Qzin4iTWrU", - "mode":"test", - "createdDatetime":"2014-01-19T11:41:54.0Z", - "status":"expired", - "expiredDatetime":"2014-01-19T11:58:01.0Z", - "amount":"100.00", - "description":"Description", - "method":"ideal", - "metadata":"meta", - "details":null, - "links":{ - "redirectUrl":"http://www.google.nl" - } + "resource": "payment", + "id": "tr_Qzin4iTWrU", + "mode": "test", + "createdAt": "2018-07-19T12:04:56+00:00", + "amount": { + "value": "100.00", + "currency": "EUR" + }, + "description": "apex.sh performance test payment", + "method": null, + "metadata": null, + "status": "expired", + "expiredAt": "2018-07-19T12:21:04+00:00", + "locale": "nl_NL", + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://www.example.org/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_wnUB738Suu", + "type": "application/hal+json" + } + } } diff --git a/tests/Mock/CompletePurchaseFailure.txt b/tests/Mock/CompletePurchaseFailure.txt deleted file mode 100644 index 06cfd7a..0000000 --- a/tests/Mock/CompletePurchaseFailure.txt +++ /dev/null @@ -1,19 +0,0 @@ -HTTP/1.1 422 Unprocessable Entity -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:19:39 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 101 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains - -{ - "error":{ - "type":"request", - "message":"The issuer is invalid", - "field":"issuer" - } -} diff --git a/tests/Mock/CompletePurchaseSuccess.txt b/tests/Mock/CompletePurchaseSuccess.txt index b04d0bc..57d87ab 100644 --- a/tests/Mock/CompletePurchaseSuccess.txt +++ b/tests/Mock/CompletePurchaseSuccess.txt @@ -1,31 +1,51 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 12:48:09 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 394 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +Content-Type: application/hal+json; charset=utf-8 { - "id":"tr_Qzin4iTWrU", - "mode":"test", - "createdDatetime":"2014-01-19T11:41:55.0Z", - "status":"paid", - "paidDatetime":"2014-01-19T12:47:46.0Z", - "amount":"100.00", - "description":"Description", - "method":"ideal", - "metadata":"meta", - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412" + "resource": "payment", + "id": "tr_Qzin4iTWrU", + "mode": "test", + "createdAt": "2018-07-19T12:38:21+00:00", + "amount": { + "value": "10.00", + "currency": "EUR" }, - "links":{ - "redirectUrl":"http://www.google.nl" + "description": "Order #1234", + "method": "ideal", + "metadata": null, + "status": "paid", + "paidAt": "2018-07-19T12:38:34+00:00", + "amountRefunded": { + "value": "0.00", + "currency": "EUR" + }, + "amountRemaining": { + "value": "35.00", + "currency": "EUR" + }, + "locale": "nl_NL", + "countryCode": "NL", + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "http://mollie.com", + "webhookUrl": "http://mollie.com", + "settlementAmount": { + "value": "10.00", + "currency": "EUR" + }, + "details": { + "consumerName": "T. TEST", + "consumerAccount": "NL17RABO0213698412", + "consumerBic": "INGBNL2A" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_2bMMNCF5A2", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", + "type": "text/html" + } } } From e0008ed4ef7b40d02a11d32fde68169747d477f8 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Thu, 19 Jul 2018 15:14:35 +0200 Subject: [PATCH 05/25] SiRefund creation --- tests/Mock/Refund401Failure.txt | 24 ++++++++++++++++++++++++ tests/Mock/Refund422Failure.txt | 15 +++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/Mock/Refund401Failure.txt create mode 100644 tests/Mock/Refund422Failure.txt diff --git a/tests/Mock/Refund401Failure.txt b/tests/Mock/Refund401Failure.txt new file mode 100644 index 0000000..6ee9064 --- /dev/null +++ b/tests/Mock/Refund401Failure.txt @@ -0,0 +1,24 @@ +HTTP/1.1 401 Authorization Required +Server: nginx/1.4.4 +Date: Mon, 20 Jan 2014 10:04:18 GMT +Content-Type: application/json; charset=utf-8 +Content-Length: 155 +Connection: keep-alive +Access-Control-Allow-Credentials: true +Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE +Access-Control-Max-Age: 300 +Cache-Control: no-cache, no-store +Strict-Transport-Security: max-age=31556926; includeSubDomains +Www-Authenticate: Basic realm="Mollie API Key" + +{ + "status": 401, + "title": "Unauthorized Request", + "detail": "Missing authentication, or failed to authenticate", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/authentication", + "type": "text/html" + } + } +} diff --git a/tests/Mock/Refund422Failure.txt b/tests/Mock/Refund422Failure.txt new file mode 100644 index 0000000..d8051e4 --- /dev/null +++ b/tests/Mock/Refund422Failure.txt @@ -0,0 +1,15 @@ +HTTP/1.1 422 Unprocessable Entity +Content-Type: application/hal+json; charset=utf-8 + +{ + "status": 422, + "title": "Unprocessable Entity", + "detail": "The payment method is invalid", + "field": "method", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/handling-errors", + "type": "text/html" + } + } +} From 8e6a9256fb11cda01d3166de252015c69bd9a3d1 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Thu, 19 Jul 2018 15:23:34 +0200 Subject: [PATCH 06/25] Refund creation - missing part --- src/Message/RefundRequest.php | 11 ++++++ src/Message/RefundResponse.php | 16 +++++++- tests/Message/FetchIssuersRequestTest.php | 11 +++++- tests/Message/RefundRequestTest.php | 42 +++++++++++++++++++++ tests/Mock/RefundSuccess.txt | 46 +++++++++++------------ 5 files changed, 98 insertions(+), 28 deletions(-) diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 7db160b..6ca7b63 100755 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -3,8 +3,15 @@ namespace Omnipay\Mollie\Message; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Common\Message\ResponseInterface; + class RefundRequest extends AbstractRequest { + /** + * @return array + * @throws InvalidRequestException + */ public function getData() { $this->validate('apiKey', 'transactionReference'); @@ -17,6 +24,10 @@ public function getData() return $data; } + /** + * @param array $data + * @return ResponseInterface|RefundResponse + */ public function sendData($data) { $response = $this->sendRequest('POST', '/payments/' . $this->getTransactionReference() . '/refunds', $data); diff --git a/src/Message/RefundResponse.php b/src/Message/RefundResponse.php index 2ca1a8e..842b14e 100644 --- a/src/Message/RefundResponse.php +++ b/src/Message/RefundResponse.php @@ -5,13 +5,27 @@ class RefundResponse extends AbstractResponse { + /** + * @return null|string + */ public function getTransactionReference() { - return $this->data['payment']['id']; + return $this->data['paymentId']; } + /** + * @return string + */ public function getTransactionId() { return $this->data['id']; } + + /** + * @return bool + */ + public function isSuccessful() + { + return isset($this->data['id']); + } } diff --git a/tests/Message/FetchIssuersRequestTest.php b/tests/Message/FetchIssuersRequestTest.php index e76c5dd..eaaa5aa 100644 --- a/tests/Message/FetchIssuersRequestTest.php +++ b/tests/Message/FetchIssuersRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Common\Issuer; use Omnipay\Mollie\Message\FetchIssuersRequest; use Omnipay\Tests\TestCase; @@ -35,7 +36,10 @@ public function testSendSuccess() $this->setMockHttpResponse('FetchIssuersSuccess.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest( + new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), + $this->getMockClient()->getLastRequest() + ); $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); $this->assertTrue($response->isSuccessful()); @@ -53,7 +57,10 @@ public function testSendFailure() $this->setMockHttpResponse('FetchIssuersFailure.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest( + new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), + $this->getMockClient()->getLastRequest() + ); $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); $this->assertFalse($response->isSuccessful()); diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index 1200cfd..cf540d1 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -1,11 +1,14 @@ setMockHttpResponse('RefundSuccess.txt'); + /** @var RefundResponse $response */ $response = $this->request->send(); + $this->assertEqualRequest( + new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); $this->assertSame('re_4qqhO89gsT', $response->getTransactionId()); } + + public function test401Failure() + { + $this->setMockHttpResponse('Refund401Failure.txt'); + /** @var RefundResponse $response */ + $response = $this->request->send(); + + $this->assertEqualRequest( + new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); + } + + public function test422Failure() + { + $this->setMockHttpResponse('Refund422Failure.txt'); + /** @var RefundResponse $response */ + $response = $this->request->send(); + + $this->assertEqualRequest( + new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('{"status":422,"title":"Unprocessable Entity","detail":"The payment method is invalid","field":"method","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); + } } diff --git a/tests/Mock/RefundSuccess.txt b/tests/Mock/RefundSuccess.txt index 3b73567..a618003 100644 --- a/tests/Mock/RefundSuccess.txt +++ b/tests/Mock/RefundSuccess.txt @@ -12,32 +12,28 @@ Strict-Transport-Security: max-age=31556926; includeSubDomains X-Whom: dc1-web-2 { + "resource": "refund", "id": "re_4qqhO89gsT", - "payment": { - "id": "tr_WDqYK6vllg", - "mode": "test", - "createdDatetime": "2016-08-18T03:51:53.0Z", - "status": "refunded", - "amount": "35.07", - "amountRefunded": "5.95", - "amountRemaining": "54.12", - "description": "Order", - "method": "ideal", - "metadata": { - "order_id": "33" + "amount": { + "currency": "EUR", + "value": "5.95" + }, + "status": "pending", + "createdAt": "2018-03-14T17:09:02.0Z", + "description": "Order", + "paymentId": "tr_WDqYK6vllg", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", + "type": "application/hal+json" }, - "details": { - "consumerName": "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman", - "consumerAccount": "NL53INGB0654422370", - "consumerBic": "INGBNL2A" + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", + "type": "application/hal+json" }, - "locale": "nl", - "links": { - "webhookUrl": "https://webshop.example.org/payments/webhook", - "redirectUrl": "https://webshop.example.org/order/33/", - "refunds": "https://api.mollie.nl/v1/payments/tr_WDqYK6vllg/refunds" + "documentation": { + "href": "https://docs.mollie.com/reference/v2/refunds-api/create-refund", + "type": "text/html" } - }, - "amount": "5.95", - "refundedDatetime": "2016-08-19T08:49:58.0Z" -} + } +} \ No newline at end of file From 131a212394c5cea407179906bdc7fdfbe1631ad4 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Thu, 19 Jul 2018 15:24:57 +0200 Subject: [PATCH 07/25] Update the customer tests to v2 --- src/Message/CreateCustomerRequest.php | 8 ---- src/Message/UpdateCustomerRequest.php | 9 ---- tests/Message/CreateCustomerRequestTest.php | 38 ++++++++++----- tests/Message/FetchCustomerRequestTest.php | 16 +++++-- tests/Message/FetchIssuersRequestTest.php | 7 +-- tests/Message/UpdateCustomerRequestTest.php | 52 +++++++++++++-------- tests/Mock/CreateCustomerFailure.txt | 28 ++++------- tests/Mock/CreateCustomerSuccess.txt | 37 +++++++-------- tests/Mock/FetchCustomerFailure.txt | 25 ++++------ tests/Mock/FetchCustomerSuccess.txt | 37 +++++++-------- tests/Mock/FetchIssuersFailure.txt | 14 +----- tests/Mock/UpdateCustomerFailure.txt | 26 ++++------- tests/Mock/UpdateCustomerSuccess.txt | 39 ++++++++-------- 13 files changed, 162 insertions(+), 174 deletions(-) diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index 061744b..e025885 100755 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -102,12 +102,4 @@ public function sendData($data) return $this->response = new CreateCustomerResponse($this, $response); } - - /** - * @return string - */ - public function getEndpoint() - { - return $this->baseUrl.'/customers'; - } } diff --git a/src/Message/UpdateCustomerRequest.php b/src/Message/UpdateCustomerRequest.php index 1f94980..06a1bd5 100755 --- a/src/Message/UpdateCustomerRequest.php +++ b/src/Message/UpdateCustomerRequest.php @@ -99,7 +99,6 @@ public function getData() $this->validate('apiKey', 'customerReference'); $data = []; - $data['id'] = $this->getCustomerReference(); $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); $data['metadata'] = $this->getMetadata(); @@ -122,12 +121,4 @@ public function sendData($data) return $this->response = new UpdateCustomerResponse($this, $response); } - - /** - * @return string - */ - public function getEndpoint() - { - return $this->baseUrl.'/customers/'.$this->getCustomerReference(); - } } diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 286d49d..b709ee0 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -7,6 +7,8 @@ class CreateCustomerRequestTest extends TestCase { + use AssertRequestTrait; + /** * * @var \Omnipay\Mollie\Message\CreateCustomerRequest @@ -19,30 +21,25 @@ public function setUp() $this->request->initialize(array( 'apiKey' => 'mykey', - 'description' => 'Test Customer', - 'email' => 'test123@example.com', + 'description' => 'John Doe', + 'email' => 'john@doe.com', 'locale' => 'nl_NL', 'metadata' => 'Just some meta data.', )); } - public function testEndpoint() - { - $this->assertSame('https://api.mollie.nl/v1/customers', $this->request->getEndpoint()); - } - public function testData() { $this->request->initialize(array( 'apiKey' => 'mykey', - 'description' => 'Test Customer', - 'email' => 'test123@example.com', + 'description' => 'John Doe', + 'email' => 'john@doe.com', 'metadata' => 'Just some meta data.', )); $data = $this->request->getData(); - $this->assertSame("Test Customer", $data['name']); - $this->assertSame('test123@example.com', $data['email']); + $this->assertSame("John Doe", $data['name']); + $this->assertSame('john@doe.com', $data['email']); $this->assertSame('Just some meta data.', $data['metadata']); $this->assertCount(4, $data); } @@ -54,6 +51,21 @@ public function testSendSuccess() /** @var \Omnipay\Mollie\Message\CreateCustomerResponse $response */ $response = $this->request->send(); + $this->assertEqualRequest( + new \GuzzleHttp\Psr7\Request( + "GET", + "https://api.mollie.com/v2/customers", + [], + '{ + "name":"John Doe", + "email":"john@doe.com", + "metadata":"Just some meta data.", + "locale":"nl_NL" + }' + ), + $this->getMockClient()->getLastRequest() + ); + $this->assertInstanceOf('Omnipay\Mollie\Message\CreateCustomerResponse', $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); @@ -66,9 +78,11 @@ public function testSendFailure() $this->setMockHttpResponse('CreateCustomerFailure.txt'); $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers"), $this->getMockClient()->getLastRequest()); + $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); - $this->assertSame('Unauthorized request', $response->getMessage()); + $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } } \ No newline at end of file diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php index 2e9e26d..7645dc0 100644 --- a/tests/Message/FetchCustomerRequestTest.php +++ b/tests/Message/FetchCustomerRequestTest.php @@ -3,10 +3,13 @@ namespace Omnipay\Mollie\Test\Message; use Omnipay\Mollie\Message\FetchCustomerRequest; +use Omnipay\Mollie\Message\FetchCustomerResponse; use Omnipay\Tests\TestCase; class FetchCustomerRequestTest extends TestCase { + use AssertRequestTrait; + /** * @var \Omnipay\Mollie\Message\FetchCustomerRequest */ @@ -34,10 +37,12 @@ public function testSendSuccess() { $this->setMockHttpResponse('FetchCustomerSuccess.txt'); - /** @var \Omnipay\Mollie\Message\FetchCustomerResponse $response */ + /** @var FetchCustomerResponse $response */ $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchCustomerResponse', $response); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + + $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); @@ -47,11 +52,16 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse('FetchCustomerFailure.txt'); + + /** @var FetchCustomerResponse $response */ $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + + $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); - $this->assertSame("The customer id is invalid", $response->getMessage()); + $this->assertSame('{"status":404,"title":"Not Found","detail":"No customer exists with token cst_6HUkmjwzBBa.","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } } diff --git a/tests/Message/FetchIssuersRequestTest.php b/tests/Message/FetchIssuersRequestTest.php index e76c5dd..f84eb61 100644 --- a/tests/Message/FetchIssuersRequestTest.php +++ b/tests/Message/FetchIssuersRequestTest.php @@ -4,6 +4,7 @@ use Omnipay\Common\Issuer; use Omnipay\Mollie\Message\FetchIssuersRequest; +use Omnipay\Mollie\Message\FetchIssuersResponse; use Omnipay\Tests\TestCase; class FetchIssuersRequestTest extends TestCase @@ -11,7 +12,7 @@ class FetchIssuersRequestTest extends TestCase use AssertRequestTrait; /** - * @var \Omnipay\Mollie\Message\FetchIssuersRequest + * @var FetchIssuersRequest */ protected $request; @@ -37,7 +38,7 @@ public function testSendSuccess() $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); + $this->assertInstanceOf(FetchIssuersResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); @@ -55,7 +56,7 @@ public function testSendFailure() $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"), $this->getMockClient()->getLastRequest()); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersResponse', $response); + $this->assertInstanceOf(FetchIssuersResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index 3348d89..1ec59a6 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -3,10 +3,13 @@ namespace Omnipay\Mollie\Test\Message; use Omnipay\Mollie\Message\UpdateCustomerRequest; +use Omnipay\Mollie\Message\UpdateCustomerResponse; use Omnipay\Tests\TestCase; class UpdateCustomerRequestTest extends TestCase { + use AssertRequestTrait; + /** * * @var \Omnipay\Mollie\Message\UpdateCustomerRequest @@ -20,48 +23,54 @@ public function setUp() $this->request->initialize(array( 'apiKey' => 'mykey', 'customerReference' => 'cst_bSNBBJBzdG', - 'description' => 'Test Customer2', - 'email' => 'test123@example.com', + 'description' => 'Jane Doe', + 'email' => 'john@doe.com', 'locale' => 'nl_NL', 'metadata' => 'Just some meta data.', )); } - public function testEndpoint() - { - $this->assertSame( - 'https://api.mollie.nl/v1/customers/'.$this->request->getCustomerReference(), - $this->request->getEndpoint() - ); - } - public function testData() { $this->request->initialize(array( 'apiKey' => 'mykey', 'customerReference' => 'cst_bSNBBJBzdG', - 'description' => 'Test Customer2', - 'email' => 'test123@example.com', + 'description' => 'Jane Doe', + 'email' => 'john@doe.com', 'metadata' => 'Just some meta data.', )); $data = $this->request->getData(); - $this->assertSame("cst_bSNBBJBzdG", $data['id']); - $this->assertSame("Test Customer2", $data['name']); - $this->assertSame('test123@example.com', $data['email']); + $this->assertSame("Jane Doe", $data['name']); + $this->assertSame('john@doe.com', $data['email']); $this->assertSame('Just some meta data.', $data['metadata']); - $this->assertCount(5, $data); + $this->assertCount(4, $data); } public function testSendSuccess() { $this->setMockHttpResponse('UpdateCustomerSuccess.txt'); - /** @var \Omnipay\Mollie\Message\UpdateCustomerResponse $response */ + /** @var UpdateCustomerResponse $response */ $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\UpdateCustomerResponse', $response); + $this->assertEqualRequest( + new \GuzzleHttp\Psr7\Request( + "POST", + "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG", + [], + '{ + "name": "Jane Doe", + "email": "john@doe.com", + "metadata": "Just some meta data.", + "locale": "nl_NL" + }' + ), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf(UpdateCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); @@ -71,11 +80,16 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse('UpdateCustomerFailure.txt'); + + /** @var UpdateCustomerResponse $response */ $response = $this->request->send(); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + + $this->assertInstanceOf(UpdateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); - $this->assertSame('Unauthorized request', $response->getMessage()); + $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } } diff --git a/tests/Mock/CreateCustomerFailure.txt b/tests/Mock/CreateCustomerFailure.txt index bde033c..1fc3cd6 100644 --- a/tests/Mock/CreateCustomerFailure.txt +++ b/tests/Mock/CreateCustomerFailure.txt @@ -1,22 +1,14 @@ -HTTP/1.1 401 Authorization Required -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:04:18 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 155 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -Www-Authenticate: Basic realm="Mollie API Key" +HTTP/1.1 401 Unauthorized Request +Content-Type: application/hal+json; charset=utf-8 { - "error":{ - "type":"request", - "message":"Unauthorized request", - "links":{ - "documentation":"https://www.mollie.nl/api/docs/" + "status": 401, + "title": "Unauthorized Request", + "detail": "Missing authentication, or failed to authenticate", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/authentication", + "type": "text/html" } } -} +} \ No newline at end of file diff --git a/tests/Mock/CreateCustomerSuccess.txt b/tests/Mock/CreateCustomerSuccess.txt index a375ee4..a51381a 100644 --- a/tests/Mock/CreateCustomerSuccess.txt +++ b/tests/Mock/CreateCustomerSuccess.txt @@ -1,24 +1,23 @@ HTTP/1.1 201 Created -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:41:55 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 344 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", - "mode": "live", - "name": "Test Customer", - "email": "test123@example.com", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdDatetime": "2016-10-07T09:39:25.0Z" -} + "mode": "test", + "name": "John Doe", + "email": "john@doe.com", + "locale": "nl_NL", + "metadata": "Just some meta data.", + "createdAt": "2018-07-19T12:58:47+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/customers-api/create-customer", + "type": "text/html" + } + } +} \ No newline at end of file diff --git a/tests/Mock/FetchCustomerFailure.txt b/tests/Mock/FetchCustomerFailure.txt index 7e57dde..8ef8504 100644 --- a/tests/Mock/FetchCustomerFailure.txt +++ b/tests/Mock/FetchCustomerFailure.txt @@ -1,19 +1,14 @@ -HTTP/1.1 201 Created -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:41:55 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 344 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +HTTP/1.1 404 Not Found +Content-Type: application/hal+json; charset=utf-8 { - "error": { - "type": "request", - "message": "The customer id is invalid" + "status": 404, + "title": "Not Found", + "detail": "No customer exists with token cst_6HUkmjwzBBa.", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/handling-errors", + "type": "text/html" + } } } \ No newline at end of file diff --git a/tests/Mock/FetchCustomerSuccess.txt b/tests/Mock/FetchCustomerSuccess.txt index ad1e2a0..4b70960 100644 --- a/tests/Mock/FetchCustomerSuccess.txt +++ b/tests/Mock/FetchCustomerSuccess.txt @@ -1,24 +1,23 @@ -HTTP/1.1 201 Created -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:41:55 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 344 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +HTTP/1.1 200 OK +Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", - "mode": "live", - "name": "Test Customer2", - "email": "test123@example.com", - "locale": null, + "mode": "test", + "name": "John Doe", + "email": "john@doe.com", + "locale": "nl_NL", "metadata": null, - "recentlyUsedMethods": [], - "createdDatetime": "2016-10-07T09:39:25.0Z" -} + "createdAt": "2018-07-19T12:58:47+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", + "type": "text/html" + } + } +} \ No newline at end of file diff --git a/tests/Mock/FetchIssuersFailure.txt b/tests/Mock/FetchIssuersFailure.txt index 6ee9064..04cdb9d 100644 --- a/tests/Mock/FetchIssuersFailure.txt +++ b/tests/Mock/FetchIssuersFailure.txt @@ -1,15 +1,5 @@ -HTTP/1.1 401 Authorization Required -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:04:18 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 155 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -Www-Authenticate: Basic realm="Mollie API Key" +HTTP/1.1 401 Unauthorized Request +Content-Type: application/hal+json; charset=utf-8 { "status": 401, diff --git a/tests/Mock/UpdateCustomerFailure.txt b/tests/Mock/UpdateCustomerFailure.txt index bde033c..04cdb9d 100644 --- a/tests/Mock/UpdateCustomerFailure.txt +++ b/tests/Mock/UpdateCustomerFailure.txt @@ -1,22 +1,14 @@ -HTTP/1.1 401 Authorization Required -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:04:18 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 155 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -Www-Authenticate: Basic realm="Mollie API Key" +HTTP/1.1 401 Unauthorized Request +Content-Type: application/hal+json; charset=utf-8 { - "error":{ - "type":"request", - "message":"Unauthorized request", - "links":{ - "documentation":"https://www.mollie.nl/api/docs/" + "status": 401, + "title": "Unauthorized Request", + "detail": "Missing authentication, or failed to authenticate", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/authentication", + "type": "text/html" } } } diff --git a/tests/Mock/UpdateCustomerSuccess.txt b/tests/Mock/UpdateCustomerSuccess.txt index ad1e2a0..ba6cfd1 100644 --- a/tests/Mock/UpdateCustomerSuccess.txt +++ b/tests/Mock/UpdateCustomerSuccess.txt @@ -1,24 +1,23 @@ -HTTP/1.1 201 Created -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:41:55 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 344 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +HTTP/1.1 200 OK +Content-Type: application/hal+json; charset=utf-8 { "resource": "customer", "id": "cst_bSNBBJBzdG", - "mode": "live", - "name": "Test Customer2", - "email": "test123@example.com", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdDatetime": "2016-10-07T09:39:25.0Z" -} + "mode": "test", + "name": "Jane Doe", + "email": "john@doe.com", + "locale": "nl_NL", + "metadata": "Just some meta data.", + "createdAt": "2018-07-19T12:58:47+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/customers/cst_6HUkmjwzBB", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/customers-api/update-customer", + "type": "text/html" + } + } +} \ No newline at end of file From 97e764806fc6c67aaefc3725655f3a7cbee91a14 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Thu, 19 Jul 2018 15:31:21 +0200 Subject: [PATCH 08/25] Update the fetch payment methods request to v2 --- src/Message/FetchPaymentMethodsResponse.php | 4 +- .../FetchPaymentMethodsRequestTest.php | 17 +- tests/Mock/FetchIssuersSuccess.txt | 12 +- tests/Mock/FetchPaymentMethodsFailure.txt | 27 +- tests/Mock/FetchPaymentMethodsSuccess.txt | 247 ++++++++++++++---- 5 files changed, 215 insertions(+), 92 deletions(-) diff --git a/src/Message/FetchPaymentMethodsResponse.php b/src/Message/FetchPaymentMethodsResponse.php index 7f4cd01..bb58bc3 100644 --- a/src/Message/FetchPaymentMethodsResponse.php +++ b/src/Message/FetchPaymentMethodsResponse.php @@ -14,9 +14,9 @@ class FetchPaymentMethodsResponse extends AbstractResponse implements FetchPayme */ public function getPaymentMethods() { - if (isset($this->data['data'])) { + if (isset($this->data['_embedded']["methods"])) { $paymentMethods = []; - foreach ($this->data['data'] as $method) { + foreach ($this->data['_embedded']["methods"] as $method) { $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php index 4fcf4ed..6ab515a 100644 --- a/tests/Message/FetchPaymentMethodsRequestTest.php +++ b/tests/Message/FetchPaymentMethodsRequestTest.php @@ -4,12 +4,15 @@ use Omnipay\Common\PaymentMethod; use Omnipay\Mollie\Message\FetchPaymentMethodsRequest; +use Omnipay\Mollie\Message\FetchPaymentMethodsResponse; use Omnipay\Tests\TestCase; class FetchPaymentMethodsRequestTest extends TestCase { + use AssertRequestTrait; + /** - * @var \Omnipay\Mollie\Message\FetchPaymentMethodsRequest + * @var FetchPaymentMethodsRequest */ protected $request; @@ -33,12 +36,14 @@ public function testSendSuccess() $this->setMockHttpResponse('FetchPaymentMethodsSuccess.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchPaymentMethodsResponse', $response); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); + + $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $paymentMethods = $response->getPaymentMethods(); - $this->assertCount(4, $paymentMethods); + $this->assertCount(12, $paymentMethods); $expectedPaymentMethod = new PaymentMethod('ideal', 'iDEAL'); @@ -50,11 +55,13 @@ public function testSendFailure() $this->setMockHttpResponse('FetchPaymentMethodsFailure.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchPaymentMethodsResponse', $response); + $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); + + $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); - $this->assertSame('Unauthorized request', $response->getMessage()); + $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); $this->assertNull($response->getPaymentMethods()); } } diff --git a/tests/Mock/FetchIssuersSuccess.txt b/tests/Mock/FetchIssuersSuccess.txt index d808ee5..cc6f9c2 100644 --- a/tests/Mock/FetchIssuersSuccess.txt +++ b/tests/Mock/FetchIssuersSuccess.txt @@ -1,15 +1,5 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 11:28:09 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 152 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +Content-Type: application/hal+json; charset=utf-8 { "resource": "method", diff --git a/tests/Mock/FetchPaymentMethodsFailure.txt b/tests/Mock/FetchPaymentMethodsFailure.txt index 822caf0..1fc3cd6 100644 --- a/tests/Mock/FetchPaymentMethodsFailure.txt +++ b/tests/Mock/FetchPaymentMethodsFailure.txt @@ -1,21 +1,14 @@ -HTTP/1.1 401 Authorization Required -Server: nginx/1.4.4 -Date: Tue, 18 Mar 2014 20:44:58 GMT -Content-Type: application/json; charset=utf-8 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -Www-Authenticate: Basic realm="Mollie API Key" +HTTP/1.1 401 Unauthorized Request +Content-Type: application/hal+json; charset=utf-8 { - "error":{ - "type":"request", - "message":"Unauthorized request", - "links":{ - "documentation":"https://www.mollie.nl/api/docs/" + "status": 401, + "title": "Unauthorized Request", + "detail": "Missing authentication, or failed to authenticate", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/authentication", + "type": "text/html" } } -} +} \ No newline at end of file diff --git a/tests/Mock/FetchPaymentMethodsSuccess.txt b/tests/Mock/FetchPaymentMethodsSuccess.txt index a396f77..6c28a95 100644 --- a/tests/Mock/FetchPaymentMethodsSuccess.txt +++ b/tests/Mock/FetchPaymentMethodsSuccess.txt @@ -1,67 +1,200 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Tue, 18 Mar 2014 20:44:01 GMT -Content-Type: application/json; charset=utf-8 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-1 +Content-Type: application/hal+json; charset=utf-8 { - "totalCount":4, - "offset":0, - "count":4, - "data":[ - { - "id":"ideal", - "description":"iDEAL", - "amount":{ - "minimum":"0.43", - "maximum":"50000.00" + "_embedded": { + "methods": [ + { + "resource": "method", + "id": "ideal", + "description": "iDEAL", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/ideal", + "type": "application/hal+json" + } + } }, - "image":{ - "normal":"https://www.mollie.nl/images/payscreen/methods/ideal.png", - "bigger":"https://www.mollie.nl/images/payscreen/methods/ideal@2x.png" - } - }, - { - "id":"creditcard", - "description":"Creditcard", - "amount":{ - "minimum":"0.32", - "maximum":"10000.00" + { + "resource": "method", + "id": "creditcard", + "description": "Credit card", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/creditcard", + "type": "application/hal+json" + } + } }, - "image":{ - "normal":"https://www.mollie.nl/images/payscreen/methods/creditcard.png", - "bigger":"https://www.mollie.nl/images/payscreen/methods/creditcard@2x.png" - } - }, - { - "id":"mistercash", - "description":"Mister Cash", - "amount":{ - "minimum":"0.31", - "maximum":"10000.00" + { + "resource": "method", + "id": "paypal", + "description": "PayPal", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/paypal.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/paypal%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/paypal", + "type": "application/hal+json" + } + } }, - "image":{ - "normal":"https://www.mollie.nl/images/payscreen/methods/mistercash.png", - "bigger":"https://www.mollie.nl/images/payscreen/methods/mistercash@2x.png" - } - }, - { - "id":"banktransfer", - "description":"Bank transfer", - "amount":{ - "minimum":"0.31", - "maximum":"50000.00" + { + "resource": "method", + "id": "bancontact", + "description": "Bancontact", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/mistercash", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "banktransfer", + "description": "Bank transfer", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/banktransfer.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/banktransfer%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/banktransfer", + "type": "application/hal+json" + } + } }, - "image":{ - "normal":"https://www.mollie.nl/images/payscreen/methods/banktransfer.png", - "bigger":"https://www.mollie.nl/images/payscreen/methods/banktransfer@2x.png" + { + "resource": "method", + "id": "sofort", + "description": "SOFORT Banking", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/sofort.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/sofort%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/sofort", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "eps", + "description": "eps", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/eps.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/eps%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/eps", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "giropay", + "description": "Giropay", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/giropay.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/giropay%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/giropay", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "kbc", + "description": "KBC/CBC Payment Button", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/kbc.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/kbc%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/kbc", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "belfius", + "description": "Belfius Pay Button", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/belfius.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/belfius%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/belfius", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "inghomepay", + "description": "ING Home'Pay", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/inghomepay.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/inghomepay%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/inghomepay", + "type": "application/hal+json" + } + } + }, + { + "resource": "method", + "id": "bitcoin", + "description": "Bitcoin", + "image": { + "size1x": "https://www.mollie.com/images/payscreen/methods/bitcoin.png", + "size2x": "https://www.mollie.com/images/payscreen/methods/bitcoin%402x.png" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/methods/bitcoin", + "type": "application/hal+json" + } + } } + ] + }, + "count": 12, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.nl/v2/methods", + "type": "application/hal+json" } - ] + } } From 62e63f6fee2b36129587245f04b5b4446a4b0551 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Thu, 19 Jul 2018 15:58:29 +0200 Subject: [PATCH 09/25] Fix gateway test and do some cleanup --- src/Gateway.php | 58 +++++++++++++------ tests/GatewayTest.php | 49 ++++++++++------ tests/Message/CompletePurchaseRequestTest.php | 7 ++- tests/Message/CreateCustomerRequestTest.php | 8 ++- tests/Message/FetchCustomerRequestTest.php | 2 +- tests/Message/PurchaseRequestTest.php | 2 +- 6 files changed, 81 insertions(+), 45 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 8e5b1c0..f3f8860 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -3,11 +3,20 @@ namespace Omnipay\Mollie; use Omnipay\Common\AbstractGateway; +use Omnipay\Mollie\Message\CompletePurchaseRequest; +use Omnipay\Mollie\Message\CreateCustomerRequest; +use Omnipay\Mollie\Message\FetchCustomerRequest; +use Omnipay\Mollie\Message\FetchIssuersRequest; +use Omnipay\Mollie\Message\FetchPaymentMethodsRequest; +use Omnipay\Mollie\Message\FetchTransactionRequest; +use Omnipay\Mollie\Message\PurchaseRequest; +use Omnipay\Mollie\Message\RefundRequest; +use Omnipay\Mollie\Message\UpdateCustomerRequest; /** * Mollie (iDeal) Gateway * - * @link https://www.mollie.nl/files/documentatie/payments-api.html + * @link https://www.mollie.com/en/developers */ class Gateway extends AbstractGateway { @@ -48,82 +57,93 @@ public function setApiKey($value) /** * @param array $parameters - * @return \Omnipay\Mollie\Message\FetchIssuersRequest + * @return FetchIssuersRequest */ public function fetchIssuers(array $parameters = []) { - return $this->createRequest(\Omnipay\Mollie\Message\FetchIssuersRequest::class, $parameters); + return $this->createRequest(FetchIssuersRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\FetchPaymentMethodsRequest + * @return FetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\FetchPaymentMethodsRequest', $parameters); + return $this->createRequest(FetchPaymentMethodsRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\FetchTransactionRequest + * @return FetchTransactionRequest */ public function fetchTransaction(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\FetchTransactionRequest', $parameters); + return $this->createRequest(FetchTransactionRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\PurchaseRequest + * @return PurchaseRequest */ public function purchase(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\PurchaseRequest', $parameters); + return $this->createRequest(PurchaseRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\CompletePurchaseRequest + * @return CompletePurchaseRequest */ public function completePurchase(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\CompletePurchaseRequest', $parameters); + return $this->createRequest(CompletePurchaseRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\RefundRequest + * @return RefundRequest */ public function refund(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\RefundRequest', $parameters); + return $this->createRequest(RefundRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\CreateCustomerRequest + * @return CreateCustomerRequest */ public function createCustomer(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\CreateCustomerRequest', $parameters); + return $this->createRequest(CreateCustomerRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\UpdateCustomerRequest + * @return UpdateCustomerRequest */ public function updateCustomer(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\UpdateCustomerRequest', $parameters); + return $this->createRequest(UpdateCustomerRequest::class, $parameters); } /** * @param array $parameters - * @return \Omnipay\Mollie\Message\FetchCustomerRequest + * @return FetchCustomerRequest */ public function fetchCustomer(array $parameters = []) { - return $this->createRequest('\Omnipay\Mollie\Message\FetchCustomerRequest', $parameters); + return $this->createRequest(FetchCustomerRequest::class, $parameters); + } + + public function __call($name, $arguments) + { + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface authorize(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface completeAuthorize(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface capture(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface void(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface createCard(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface updateCard(array $options = array()) + // TODO: Implement @method \Omnipay\Common\Message\RequestInterface deleteCard(array $options = array()) } } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index bbba8be..7de065a 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -1,13 +1,23 @@ gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); + $this->gateway = new Gateway(); } public function testFetchIssuers() { $request = $this->gateway->fetchIssuers(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersRequest', $request); + $this->assertInstanceOf(FetchIssuersRequest::class, $request); } public function testFetchPaymentMethods() { $request = $this->gateway->fetchPaymentMethods(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchPaymentMethodsRequest', $request); + $this->assertInstanceOf(FetchPaymentMethodsRequest::class, $request); } public function testPurchase() { - $request = $this->gateway->purchase(array('amount' => '10.00')); + $request = $this->gateway->purchase(array('amount' => '10.00', 'currency' => 'EUR')); - $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseRequest', $request); + $this->assertInstanceOf(PurchaseRequest::class, $request); $this->assertSame('10.00', $request->getAmount()); + $this->assertSame('EUR', $request->getCurrency()); } public function testPurchaseReturn() { - $request = $this->gateway->completePurchase(array('amount' => '10.00')); + $request = $this->gateway->completePurchase(array('amount' => '10.00', 'currency' => 'EUR')); - $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseRequest', $request); + $this->assertInstanceOf(CompletePurchaseRequest::class, $request); $this->assertSame('10.00', $request->getAmount()); + $this->assertSame('EUR', $request->getCurrency()); } public function testRefund() @@ -57,18 +69,19 @@ public function testRefund() ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\RefundRequest', $request); + $this->assertInstanceOf(RefundRequest::class, $request); $data = $request->getData(); $this->assertFalse(array_key_exists('amount', $data)); $request = $this->gateway->refund( array( 'apiKey' => 'key', 'transactionReference' => 'tr_Qzin4iTWrU', - 'amount' => '10.00' + 'amount' => '10.00', + 'currency' => 'EUR' ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\RefundRequest', $request); + $this->assertInstanceOf(RefundRequest::class, $request); $data = $request->getData(); $this->assertSame('10.00', $data['amount']); } @@ -82,7 +95,7 @@ public function testFetchTransaction() ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchTransactionRequest', $request); + $this->assertInstanceOf(FetchTransactionRequest::class, $request); $data = $request->getData(); $this->assertSame('tr_Qzin4iTWrU', $data['id']); @@ -99,7 +112,7 @@ public function testCreateCustomer() ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\CreateCustomerRequest', $request); + $this->assertInstanceOf(CreateCustomerRequest::class, $request); } public function testUpdateCustomer() @@ -114,11 +127,11 @@ public function testUpdateCustomer() ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\UpdateCustomerRequest', $request); + $this->assertInstanceOf(UpdateCustomerRequest::class, $request); $data = $request->getData(); - $this->assertSame('cst_bSNBBJBzdG', $data['id']); + $this->assertSame('Test name2', $data['name']); } public function testFetchCustomer() @@ -130,6 +143,6 @@ public function testFetchCustomer() ) ); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchCustomerRequest', $request); + $this->assertInstanceOf(FetchCustomerRequest::class, $request); } } diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index de4e5b3..41eb1a6 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -3,6 +3,7 @@ namespace Omnipay\Mollie\Test\Message; use Omnipay\Mollie\Message\CompletePurchaseRequest; +use Omnipay\Mollie\Message\CompletePurchaseResponse; use Omnipay\Tests\TestCase; class CompletePurchaseRequestTest extends TestCase @@ -10,7 +11,7 @@ class CompletePurchaseRequestTest extends TestCase use AssertRequestTrait; /** - * @var \Omnipay\Mollie\Message\CompletePurchaseRequest + * @var CompletePurchaseRequest */ protected $request; @@ -54,7 +55,7 @@ public function testSendSuccess() $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); - $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response); + $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isOpen()); $this->assertTrue($response->isPaid()); @@ -69,7 +70,7 @@ public function testSendExpired() $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); - $this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response); + $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isPaid()); $this->assertTrue($response->isExpired()); diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index b709ee0..8462f3f 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -3,6 +3,7 @@ namespace Omnipay\Mollie\Test\Message; use Omnipay\Mollie\Message\CreateCustomerRequest; +use Omnipay\Mollie\Message\CreateCustomerResponse; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase @@ -11,7 +12,7 @@ class CreateCustomerRequestTest extends TestCase /** * - * @var \Omnipay\Mollie\Message\CreateCustomerRequest + * @var CreateCustomerRequest */ protected $request; @@ -48,7 +49,7 @@ public function testSendSuccess() { $this->setMockHttpResponse('CreateCustomerSuccess.txt'); - /** @var \Omnipay\Mollie\Message\CreateCustomerResponse $response */ + /** @var CreateCustomerResponse $response */ $response = $this->request->send(); $this->assertEqualRequest( @@ -66,7 +67,7 @@ public function testSendSuccess() $this->getMockClient()->getLastRequest() ); - $this->assertInstanceOf('Omnipay\Mollie\Message\CreateCustomerResponse', $response); + $this->assertInstanceOf(CreateCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); @@ -80,6 +81,7 @@ public function testSendFailure() $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers"), $this->getMockClient()->getLastRequest()); + $this->assertInstanceOf(CreateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php index 7645dc0..ae86e41 100644 --- a/tests/Message/FetchCustomerRequestTest.php +++ b/tests/Message/FetchCustomerRequestTest.php @@ -11,7 +11,7 @@ class FetchCustomerRequestTest extends TestCase use AssertRequestTrait; /** - * @var \Omnipay\Mollie\Message\FetchCustomerRequest + * @var FetchCustomerRequest */ protected $request; diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index f2370bd..7cb5d00 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -171,7 +171,7 @@ public function testIssuerFailure() $this->getMockClient()->getLastRequest() ); - $this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseResponse', $response); + $this->assertInstanceOf(PurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); From a640c7534dc005b10da38b1c2b366b2b1b6f4471 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Thu, 19 Jul 2018 16:25:30 +0200 Subject: [PATCH 10/25] ReFetch transaction --- src/Message/FetchTransactionResponse.php | 2 +- tests/Message/FetchTransactionRequestTest.php | 54 +++++++++++---- tests/Mock/FetchTransaction404Failure.txt | 14 ++++ tests/Mock/FetchTransactionExpired.txt | 51 ++++++++------- tests/Mock/FetchTransactionFailure.txt | 18 ----- tests/Mock/FetchTransactionSuccess.txt | 65 +++++++++++-------- 6 files changed, 121 insertions(+), 83 deletions(-) create mode 100644 tests/Mock/FetchTransaction404Failure.txt delete mode 100644 tests/Mock/FetchTransactionFailure.txt diff --git a/src/Message/FetchTransactionResponse.php b/src/Message/FetchTransactionResponse.php index eefac74..5c38abc 100644 --- a/src/Message/FetchTransactionResponse.php +++ b/src/Message/FetchTransactionResponse.php @@ -69,7 +69,7 @@ public function isCancelled() */ public function isPaid() { - return isset($this->data['paidAt']) && !empty($this->data['paidAt']); + return isset($this->data['status']) && 'paid' === $this->data['status']; } /** diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index 3703962..a8acc9b 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -2,11 +2,15 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Mollie\Message\FetchTransactionRequest; +use Omnipay\Mollie\Message\FetchTransactionResponse; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase { + use AssertRequestTrait; + /** * @var \Omnipay\Mollie\Message\FetchTransactionRequest */ @@ -18,7 +22,7 @@ public function setUp() $this->request->initialize( array( 'apiKey' => 'mykey', - 'transactionReference' => 'tr_Qzin4iTWrU', + 'transactionReference' => 'tr_WDqYK6vllg', ) ); } @@ -27,26 +31,36 @@ public function testGetData() { $data = $this->request->getData(); - $this->assertSame("tr_Qzin4iTWrU", $data['id']); + $this->assertSame("tr_WDqYK6vllg", $data['id']); $this->assertCount(1, $data); } public function testSendSuccess() { $this->setMockHttpResponse('FetchTransactionSuccess.txt'); + /** @var FetchTransactionResponse $response */ $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchTransactionResponse', $response); + $this->assertEqualRequest( + new Request( + "GET", + "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" + ), + $this->getMockClient()->getLastRequest() + ); + + + $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertTrue($response->isPaid()); $this->assertFalse($response->isCancelled()); $this->assertFalse($response->isPaidOut()); - $this->assertFalse($response->isRedirect()); + $this->assertTrue($response->isRedirect()); $this->assertFalse($response->isRefunded()); $this->assertFalse($response->isPartialRefunded()); $this->assertSame("paid", $response->getStatus()); - $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); - $this->assertSame("100.00", $response->getAmount()); + $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); + $this->assertSame(["value" => "10.00", "currency" => "EUR"], $response->getAmount()); } public function testSendExpired() @@ -54,23 +68,39 @@ public function testSendExpired() $this->setMockHttpResponse('FetchTransactionExpired.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchTransactionResponse', $response); + $this->assertEqualRequest( + new Request( + "GET", + "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" + ), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertFalse($response->isRedirect()); - $this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference()); + $this->assertTrue($response->isRedirect()); + $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); $this->assertTrue($response->isExpired()); } public function testSendFailure() { - $this->setMockHttpResponse('FetchTransactionFailure.txt'); + $this->setMockHttpResponse('FetchTransaction404Failure.txt'); $response = $this->request->send(); - $this->assertInstanceOf('Omnipay\Mollie\Message\FetchTransactionResponse', $response); + $this->assertEqualRequest( + new Request( + "GET", + "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" + ), + $this->getMockClient()->getLastRequest() + ); + + $this->assertInstanceOf(FetchTransactionResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); - $this->assertNull($response->getStatus()); + $this->assertEquals(404, $response->getStatus()); $this->assertNull($response->getAmount()); } } diff --git a/tests/Mock/FetchTransaction404Failure.txt b/tests/Mock/FetchTransaction404Failure.txt new file mode 100644 index 0000000..7e14757 --- /dev/null +++ b/tests/Mock/FetchTransaction404Failure.txt @@ -0,0 +1,14 @@ +HTTP/1.1 404 Not Found +Content-Type: application/hal+json; charset=utf-8 + +{ + "status": 404, + "title": "Not Found", + "detail": "No transaction exists with token tr_Qzin4iTWrU.", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/handling-errors", + "type": "text/html" + } + } +} \ No newline at end of file diff --git a/tests/Mock/FetchTransactionExpired.txt b/tests/Mock/FetchTransactionExpired.txt index 8a38c0b..719a6b3 100644 --- a/tests/Mock/FetchTransactionExpired.txt +++ b/tests/Mock/FetchTransactionExpired.txt @@ -1,28 +1,31 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 13:00:23 GMT Content-Type: application/json; charset=utf-8 -Content-Length: 326 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-1 { - "id":"tr_Qzin4iTWrU", - "mode":"test", - "createdDatetime":"2014-01-19T11:41:54.0Z", - "status":"expired", - "expiredDatetime":"2014-01-19T11:58:01.0Z", - "amount":"100.00", - "description":"Description", - "method":"ideal", - "metadata":"meta", - "details":null, - "links":{ - "redirectUrl":"http://www.google.nl" - } -} + "resource": "payment", + "id": "tr_WDqYK6vllg", + "mode": "test", + "createdAt": "2018-03-12T10:56:15+00:00", + "amount": { + "value": "1.00", + "currency": "EUR" + }, + "description": "Order 66", + "method": null, + "metadata": null, + "status": "expired", + "isCancelable": false, + "expiresAt": "2018-03-12T11:11:15+00:00", + "details": null, + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://www.example.org/payment/completed", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/PSj7b45bkj" + } + } +} \ No newline at end of file diff --git a/tests/Mock/FetchTransactionFailure.txt b/tests/Mock/FetchTransactionFailure.txt deleted file mode 100644 index 6107ac0..0000000 --- a/tests/Mock/FetchTransactionFailure.txt +++ /dev/null @@ -1,18 +0,0 @@ -HTTP/1.1 404 Not Found -Server: nginx/1.4.4 -Date: Mon, 20 Jan 2014 10:13:03 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 83 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains - -{ - "error":{ - "type":"request", - "message":"The payment id is invalid" - } -} diff --git a/tests/Mock/FetchTransactionSuccess.txt b/tests/Mock/FetchTransactionSuccess.txt index b04d0bc..90fffda 100644 --- a/tests/Mock/FetchTransactionSuccess.txt +++ b/tests/Mock/FetchTransactionSuccess.txt @@ -1,31 +1,40 @@ HTTP/1.1 200 OK -Server: nginx/1.4.4 -Date: Sun, 19 Jan 2014 12:48:09 GMT -Content-Type: application/json; charset=utf-8 -Content-Length: 394 -Connection: keep-alive -Access-Control-Allow-Credentials: true -Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE -Access-Control-Max-Age: 300 -Cache-Control: no-cache, no-store -Strict-Transport-Security: max-age=31556926; includeSubDomains -X-Whom: dc1-web-2 +Content-Type: application/hal+json; charset=utf-8 { - "id":"tr_Qzin4iTWrU", - "mode":"test", - "createdDatetime":"2014-01-19T11:41:55.0Z", - "status":"paid", - "paidDatetime":"2014-01-19T12:47:46.0Z", - "amount":"100.00", - "description":"Description", - "method":"ideal", - "metadata":"meta", - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412" - }, - "links":{ - "redirectUrl":"http://www.google.nl" - } -} + "resource": "payment", + "id": "tr_WDqYK6vllg", + "mode": "test", + "createdAt": "2018-03-20T13:13:37+00:00", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "description": "My first payment", + "method": null, + "metadata": { + "order_id": "12345" + }, + "status": "paid", + "isCancelable": false, + "expiresAt": "2018-03-20T13:28:37+00:00", + "details": null, + "profileId": "pfl_QkEhN94Ba", + "sequenceType": "oneoff", + "redirectUrl": "https://webshop.example.org/order/12345/", + "webhookUrl": "https://webshop.example.org/payments/webhook/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/WDqYK6vllg", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", + "type": "text/html" + } + } +} \ No newline at end of file From 99ffa2e3c0978d79bfbe46a6679e453914fd11e0 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 11:35:43 +0200 Subject: [PATCH 11/25] Splitting requests and responses to separate namespases and adding some doc blocks --- src/Gateway.php | 45 +++++++++++-------- src/Message/FetchIssuersRequest.php | 31 ------------- src/Message/FetchPaymentMethodsRequest.php | 26 ----------- src/Message/FetchTransactionRequest.php | 28 ------------ .../AbstractMollieRequest.php} | 40 +++++++++++++++-- .../{ => Request}/CompletePurchaseRequest.php | 15 +++++-- .../{ => Request}/CreateCustomerRequest.php | 28 +++++++----- .../{ => Request}/FetchCustomerRequest.php | 20 +++++---- src/Message/Request/FetchIssuersRequest.php | 40 +++++++++++++++++ .../Request/FetchPaymentMethodsRequest.php | 37 +++++++++++++++ .../Request/FetchTransactionRequest.php | 40 +++++++++++++++++ src/Message/{ => Request}/PurchaseRequest.php | 44 +++++++++++++++--- src/Message/{ => Request}/RefundRequest.php | 7 +-- .../{ => Request}/UpdateCustomerRequest.php | 34 +++++++------- .../{ => Response}/AbstractResponse.php | 6 +-- .../CompletePurchaseResponse.php | 2 +- .../{ => Response}/CreateCustomerResponse.php | 6 ++- .../{ => Response}/FetchCustomerResponse.php | 6 ++- .../{ => Response}/FetchIssuersResponse.php | 7 ++- .../FetchPaymentMethodsResponse.php | 7 ++- .../FetchTransactionResponse.php | 24 +++++++--- .../{ => Response}/PurchaseResponse.php | 2 +- src/Message/{ => Response}/RefundResponse.php | 2 +- .../{ => Response}/UpdateCustomerResponse.php | 6 ++- tests/GatewayTest.php | 25 +++++++---- tests/Message/CompletePurchaseRequestTest.php | 10 +++-- tests/Message/CreateCustomerRequestTest.php | 8 +++- tests/Message/FetchCustomerRequestTest.php | 8 +++- tests/Message/FetchIssuersRequestTest.php | 8 +++- .../FetchPaymentMethodsRequestTest.php | 8 +++- tests/Message/FetchTransactionRequestTest.php | 10 +++-- tests/Message/PurchaseRequestTest.php | 32 ++++++++----- tests/Message/RefundRequestTest.php | 20 ++++++--- tests/Message/UpdateCustomerRequestTest.php | 10 +++-- 34 files changed, 424 insertions(+), 218 deletions(-) delete mode 100755 src/Message/FetchIssuersRequest.php delete mode 100755 src/Message/FetchPaymentMethodsRequest.php delete mode 100755 src/Message/FetchTransactionRequest.php rename src/Message/{AbstractRequest.php => Request/AbstractMollieRequest.php} (53%) rename src/Message/{ => Request}/CompletePurchaseRequest.php (63%) rename src/Message/{ => Request}/CreateCustomerRequest.php (75%) rename src/Message/{ => Request}/FetchCustomerRequest.php (62%) create mode 100755 src/Message/Request/FetchIssuersRequest.php create mode 100755 src/Message/Request/FetchPaymentMethodsRequest.php create mode 100755 src/Message/Request/FetchTransactionRequest.php rename src/Message/{ => Request}/PurchaseRequest.php (67%) rename src/Message/{ => Request}/RefundRequest.php (71%) rename src/Message/{ => Request}/UpdateCustomerRequest.php (75%) rename src/Message/{ => Response}/AbstractResponse.php (68%) rename src/Message/{ => Response}/CompletePurchaseResponse.php (83%) rename src/Message/{ => Response}/CreateCustomerResponse.php (70%) rename src/Message/{ => Response}/FetchCustomerResponse.php (70%) rename src/Message/{ => Response}/FetchIssuersResponse.php (81%) rename src/Message/{ => Response}/FetchPaymentMethodsResponse.php (81%) rename src/Message/{ => Response}/FetchTransactionResponse.php (89%) rename src/Message/{ => Response}/PurchaseResponse.php (88%) rename src/Message/{ => Response}/RefundResponse.php (91%) rename src/Message/{ => Response}/UpdateCustomerResponse.php (70%) diff --git a/src/Gateway.php b/src/Gateway.php index f3f8860..a766eeb 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -3,20 +3,29 @@ namespace Omnipay\Mollie; use Omnipay\Common\AbstractGateway; -use Omnipay\Mollie\Message\CompletePurchaseRequest; -use Omnipay\Mollie\Message\CreateCustomerRequest; -use Omnipay\Mollie\Message\FetchCustomerRequest; -use Omnipay\Mollie\Message\FetchIssuersRequest; -use Omnipay\Mollie\Message\FetchPaymentMethodsRequest; -use Omnipay\Mollie\Message\FetchTransactionRequest; -use Omnipay\Mollie\Message\PurchaseRequest; -use Omnipay\Mollie\Message\RefundRequest; -use Omnipay\Mollie\Message\UpdateCustomerRequest; +use Omnipay\Common\Message\AbstractRequest; +use Omnipay\Common\Message\RequestInterface; +use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; +use Omnipay\Mollie\Message\Request\CreateCustomerRequest; +use Omnipay\Mollie\Message\Request\FetchCustomerRequest; +use Omnipay\Mollie\Message\Request\FetchIssuersRequest; +use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; +use Omnipay\Mollie\Message\Request\FetchTransactionRequest; +use Omnipay\Mollie\Message\Request\PurchaseRequest; +use Omnipay\Mollie\Message\Request\RefundRequest; +use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; /** * Mollie (iDeal) Gateway * * @link https://www.mollie.com/en/developers + * @method RequestInterface authorize(array $options = array()) + * @method RequestInterface completeAuthorize(array $options = array()) + * @method RequestInterface capture(array $options = array()) + * @method RequestInterface void(array $options = array()) + * @method RequestInterface createCard(array $options = array()) + * @method RequestInterface updateCard(array $options = array()) + * @method RequestInterface deleteCard(array $options = array()) */ class Gateway extends AbstractGateway { @@ -57,7 +66,7 @@ public function setApiKey($value) /** * @param array $parameters - * @return FetchIssuersRequest + * @return AbstractRequest|FetchIssuersRequest */ public function fetchIssuers(array $parameters = []) { @@ -66,7 +75,7 @@ public function fetchIssuers(array $parameters = []) /** * @param array $parameters - * @return FetchPaymentMethodsRequest + * @return AbstractRequest|FetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = []) { @@ -75,7 +84,7 @@ public function fetchPaymentMethods(array $parameters = []) /** * @param array $parameters - * @return FetchTransactionRequest + * @return AbstractRequest|FetchTransactionRequest */ public function fetchTransaction(array $parameters = []) { @@ -84,7 +93,7 @@ public function fetchTransaction(array $parameters = []) /** * @param array $parameters - * @return PurchaseRequest + * @return AbstractRequest|PurchaseRequest */ public function purchase(array $parameters = []) { @@ -93,7 +102,7 @@ public function purchase(array $parameters = []) /** * @param array $parameters - * @return CompletePurchaseRequest + * @return AbstractRequest|CompletePurchaseRequest */ public function completePurchase(array $parameters = []) { @@ -102,7 +111,7 @@ public function completePurchase(array $parameters = []) /** * @param array $parameters - * @return RefundRequest + * @return AbstractRequest|RefundRequest */ public function refund(array $parameters = []) { @@ -111,7 +120,7 @@ public function refund(array $parameters = []) /** * @param array $parameters - * @return CreateCustomerRequest + * @return AbstractRequest */ public function createCustomer(array $parameters = []) { @@ -120,7 +129,7 @@ public function createCustomer(array $parameters = []) /** * @param array $parameters - * @return UpdateCustomerRequest + * @return AbstractRequest|UpdateCustomerRequest */ public function updateCustomer(array $parameters = []) { @@ -129,7 +138,7 @@ public function updateCustomer(array $parameters = []) /** * @param array $parameters - * @return FetchCustomerRequest + * @return AbstractRequest|FetchCustomerRequest */ public function fetchCustomer(array $parameters = []) { diff --git a/src/Message/FetchIssuersRequest.php b/src/Message/FetchIssuersRequest.php deleted file mode 100755 index 438c982..0000000 --- a/src/Message/FetchIssuersRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -validate('apiKey'); - - return []; - } - - public function sendData($data) - { - $response = $this->sendRequest('GET', $this->endpoint); - - return $this->response = new FetchIssuersResponse($this, $response); - } -} diff --git a/src/Message/FetchPaymentMethodsRequest.php b/src/Message/FetchPaymentMethodsRequest.php deleted file mode 100755 index 7f1dffb..0000000 --- a/src/Message/FetchPaymentMethodsRequest.php +++ /dev/null @@ -1,26 +0,0 @@ -validate('apiKey'); - } - - public function sendData($data) - { - $response = $this->sendRequest('GET', '/methods'); - - return $this->response = new FetchPaymentMethodsResponse($this, $response); - } -} diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php deleted file mode 100755 index 63556fd..0000000 --- a/src/Message/FetchTransactionRequest.php +++ /dev/null @@ -1,28 +0,0 @@ -validate('apiKey', 'transactionReference'); - - $data = []; - $data['id'] = $this->getTransactionReference(); - - return $data; - } - - public function sendData($data) - { - $response = $this->sendRequest('GET', '/payments/' . $data['id']); - - return $this->response = new FetchTransactionResponse($this, $response); - } -} diff --git a/src/Message/AbstractRequest.php b/src/Message/Request/AbstractMollieRequest.php similarity index 53% rename from src/Message/AbstractRequest.php rename to src/Message/Request/AbstractMollieRequest.php index cbe53fd..5342928 100755 --- a/src/Message/AbstractRequest.php +++ b/src/Message/Request/AbstractMollieRequest.php @@ -1,34 +1,68 @@ getParameter('apiKey'); } + /** + * @param string $value + * @return $this + */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } + /** + * @param string $value + * @return $this + */ public function setTransactionId($value) { return $this->setParameter('transactionId', $value); } + /** + * @return string + */ public function getTransactionId() { return $this->getParameter('transactionId'); } - protected function sendRequest($method, $endpoint, $data = null) + /** + * @param string $method + * @param string $endpoint + * @param array $data + * @return array + */ + protected function sendRequest($method, $endpoint, array $data = null) { $response = $this->httpClient->request( $method, diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/Request/CompletePurchaseRequest.php similarity index 63% rename from src/Message/CompletePurchaseRequest.php rename to src/Message/Request/CompletePurchaseRequest.php index 73e1d62..2c448e3 100755 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/Request/CompletePurchaseRequest.php @@ -1,16 +1,21 @@ validate('apiKey'); @@ -29,9 +34,13 @@ public function getData() return $data; } + /** + * @param array $data + * @return CompletePurchaseResponse + */ public function sendData($data) { - $response = $this->sendRequest('GET', '/payments/' . $data['id']); + $response = $this->sendRequest(self::GET, '/payments/' . $data['id']); return $this->response = new CompletePurchaseResponse($this, $response); } diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/Request/CreateCustomerRequest.php similarity index 75% rename from src/Message/CreateCustomerRequest.php rename to src/Message/Request/CreateCustomerRequest.php index e025885..99ab8d5 100755 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/Request/CreateCustomerRequest.php @@ -5,9 +5,13 @@ * * URL: https://www.mollie.com/en/docs/reference/customers/create */ -namespace Omnipay\Mollie\Message; -class CreateCustomerRequest extends AbstractRequest +namespace Omnipay\Mollie\Message\Request; + +use Omnipay\Common\Message\AbstractRequest; +use Omnipay\Mollie\Message\Response\CreateCustomerResponse; + +class CreateCustomerRequest extends AbstractMollieRequest { /** * Get the customer's email address. @@ -20,8 +24,8 @@ public function getEmail() } /** - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest + * @param string $value + * @return AbstractRequest */ public function setEmail($value) { @@ -43,8 +47,8 @@ public function getLocale() /** * Optional value. * - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest + * @param string $value + * @return AbstractRequest */ public function setLocale($value) { @@ -54,7 +58,7 @@ public function setLocale($value) /** * Get the customer's metadata. * - * @return string + * @return array */ public function getMetadata() { @@ -64,8 +68,8 @@ public function getMetadata() /** * Optional value. * - * @param $value - * @return \Omnipay\Common\Message\AbstractRequest + * @param array $value + * @return AbstractRequest */ public function setMetadata($value) { @@ -74,6 +78,7 @@ public function setMetadata($value) /** * @return array + * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { @@ -82,7 +87,6 @@ public function getData() $data = []; $data['name'] = $this->getDescription(); $data['email'] = $this->getEmail(); - $data['metadata'] = $this->getMetadata(); $data['locale'] = $this->getLocale(); if ($this->getMetadata()) { @@ -93,12 +97,12 @@ public function getData() } /** - * @param mixed $data + * @param array $data * @return CreateCustomerResponse */ public function sendData($data) { - $response = $this->sendRequest('POST', '/customers', $data); + $response = $this->sendRequest(self::POST, '/customers', $data); return $this->response = new CreateCustomerResponse($this, $response); } diff --git a/src/Message/FetchCustomerRequest.php b/src/Message/Request/FetchCustomerRequest.php similarity index 62% rename from src/Message/FetchCustomerRequest.php rename to src/Message/Request/FetchCustomerRequest.php index fca0115..b943392 100755 --- a/src/Message/FetchCustomerRequest.php +++ b/src/Message/Request/FetchCustomerRequest.php @@ -1,13 +1,16 @@ sendRequest('GET', '/customers/' . $this->getCustomerReference(), $data); + $response = $this->sendRequest(self::GET, '/customers/' . $this->getCustomerReference(), $data); return $this->response = new FetchCustomerResponse($this, $response); } @@ -52,6 +56,6 @@ public function sendData($data) */ public function getEndpoint() { - return $this->baseUrl.'/customers'; + return $this->baseUrl . '/customers'; } } diff --git a/src/Message/Request/FetchIssuersRequest.php b/src/Message/Request/FetchIssuersRequest.php new file mode 100755 index 0000000..466070b --- /dev/null +++ b/src/Message/Request/FetchIssuersRequest.php @@ -0,0 +1,40 @@ +validate('apiKey'); + + return []; + } + + /** + * @param array $data + * @return ResponseInterface|FetchIssuersResponse + */ + public function sendData($data) + { + $response = $this->sendRequest(self::GET, $this->endpoint); + + return $this->response = new FetchIssuersResponse($this, $response); + } +} diff --git a/src/Message/Request/FetchPaymentMethodsRequest.php b/src/Message/Request/FetchPaymentMethodsRequest.php new file mode 100755 index 0000000..1d48eec --- /dev/null +++ b/src/Message/Request/FetchPaymentMethodsRequest.php @@ -0,0 +1,37 @@ +validate('apiKey'); + + return []; + } + + /** + * @param array $data + * @return ResponseInterface|FetchPaymentMethodsResponse + */ + public function sendData($data) + { + $response = $this->sendRequest(self::GET, '/methods'); + + return $this->response = new FetchPaymentMethodsResponse($this, $response); + } +} diff --git a/src/Message/Request/FetchTransactionRequest.php b/src/Message/Request/FetchTransactionRequest.php new file mode 100755 index 0000000..aeafea1 --- /dev/null +++ b/src/Message/Request/FetchTransactionRequest.php @@ -0,0 +1,40 @@ +validate('apiKey', 'transactionReference'); + + $data = []; + $data['id'] = $this->getTransactionReference(); + + return $data; + } + + /** + * @param array $data + * @return ResponseInterface|FetchTransactionResponse + */ + public function sendData($data) + { + $response = $this->sendRequest(self::GET, '/payments/' . $data['id']); + + return $this->response = new FetchTransactionResponse($this, $response); + } +} diff --git a/src/Message/PurchaseRequest.php b/src/Message/Request/PurchaseRequest.php similarity index 67% rename from src/Message/PurchaseRequest.php rename to src/Message/Request/PurchaseRequest.php index fc5f894..7b82eb7 100755 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/Request/PurchaseRequest.php @@ -1,43 +1,73 @@ getParameter('metadata'); } - public function setMetadata($value) + /** + * @param array $value + * @return $this + */ + public function setMetadata(array $value) { return $this->setParameter('metadata', $value); } + /** + * @return string + */ public function getLocale() { return $this->getParameter('locale'); } + /** + * @param string $value + * @return $this + */ public function setLocale($value) { return $this->setParameter('locale', $value); } + /** + * @return string + */ public function getBillingEmail() { return $this->getParameter('billingEmail'); } + /** + * @param string $value + * @return $this + */ public function setBillingEmail($value) { return $this->setParameter('billingEmail', $value); } + /** + * @return array + * @throws InvalidRequestException + */ public function getData() { $this->validate('apiKey', 'amount', 'description', 'returnUrl'); @@ -76,9 +106,13 @@ public function getData() return $data; } + /** + * @param array $data + * @return ResponseInterface|PurchaseResponse + */ public function sendData($data) { - $response = $this->sendRequest('POST', '/payments', $data); + $response = $this->sendRequest(self::POST, '/payments', $data); return $this->response = new PurchaseResponse($this, $response); } diff --git a/src/Message/RefundRequest.php b/src/Message/Request/RefundRequest.php similarity index 71% rename from src/Message/RefundRequest.php rename to src/Message/Request/RefundRequest.php index 6ca7b63..b7f9a4a 100755 --- a/src/Message/RefundRequest.php +++ b/src/Message/Request/RefundRequest.php @@ -1,12 +1,13 @@ sendRequest('POST', '/payments/' . $this->getTransactionReference() . '/refunds', $data); + $response = $this->sendRequest(self::POST, '/payments/' . $this->getTransactionReference() . '/refunds', $data); return $this->response = new RefundResponse($this, $response); } diff --git a/src/Message/UpdateCustomerRequest.php b/src/Message/Request/UpdateCustomerRequest.php similarity index 75% rename from src/Message/UpdateCustomerRequest.php rename to src/Message/Request/UpdateCustomerRequest.php index 06a1bd5..e504e92 100755 --- a/src/Message/UpdateCustomerRequest.php +++ b/src/Message/Request/UpdateCustomerRequest.php @@ -1,13 +1,17 @@ getDescription(); $data['email'] = $this->getEmail(); - $data['metadata'] = $this->getMetadata(); $data['locale'] = $this->getLocale(); if ($this->getMetadata()) { @@ -112,12 +116,12 @@ public function getData() } /** - * @param mixed $data + * @param array $data * @return UpdateCustomerResponse */ public function sendData($data) { - $response = $this->sendRequest('POST', '/customers/'.$this->getCustomerReference(), $data); + $response = $this->sendRequest(self::POST, '/customers/' . $this->getCustomerReference(), $data); return $this->response = new UpdateCustomerResponse($this, $response); } diff --git a/src/Message/AbstractResponse.php b/src/Message/Response/AbstractResponse.php similarity index 68% rename from src/Message/AbstractResponse.php rename to src/Message/Response/AbstractResponse.php index 18430e7..9cd7135 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/Response/AbstractResponse.php @@ -1,6 +1,6 @@ data['title']) && isset($this->data['detail'])) { - return json_encode($this->data); - } + return json_encode($this->data); } } diff --git a/src/Message/CompletePurchaseResponse.php b/src/Message/Response/CompletePurchaseResponse.php similarity index 83% rename from src/Message/CompletePurchaseResponse.php rename to src/Message/Response/CompletePurchaseResponse.php index bd66ae4..a47df93 100644 --- a/src/Message/CompletePurchaseResponse.php +++ b/src/Message/Response/CompletePurchaseResponse.php @@ -1,6 +1,6 @@ data['id'])) { return $this->data['id']; } + + return null; } } diff --git a/src/Message/FetchCustomerResponse.php b/src/Message/Response/FetchCustomerResponse.php similarity index 70% rename from src/Message/FetchCustomerResponse.php rename to src/Message/Response/FetchCustomerResponse.php index 2ba6137..0b86f73 100644 --- a/src/Message/FetchCustomerResponse.php +++ b/src/Message/Response/FetchCustomerResponse.php @@ -1,16 +1,18 @@ data['id'])) { return $this->data['id']; } + + return null; } } diff --git a/src/Message/FetchIssuersResponse.php b/src/Message/Response/FetchIssuersResponse.php similarity index 81% rename from src/Message/FetchIssuersResponse.php rename to src/Message/Response/FetchIssuersResponse.php index 1f3e114..1d7a5e8 100644 --- a/src/Message/FetchIssuersResponse.php +++ b/src/Message/Response/FetchIssuersResponse.php @@ -1,8 +1,9 @@ isRedirect()) { return $this->data['_links']['checkout']['href']; } + + return null; } /** @@ -99,52 +101,62 @@ public function isPartialRefunded() } /** - * @return mixed + * @return string:null */ public function getTransactionReference() { if (isset($this->data['id'])) { return $this->data['id']; } + + return null; } /** - * @return mixed + * @return string|null */ public function getTransactionId() { if (isset($this->data['metadata']['transactionId'])) { return $this->data['metadata']['transactionId']; } + + return null; } /** - * @return mixed + * @return string|null */ public function getStatus() { if (isset($this->data['status'])) { return $this->data['status']; } + + return null; } /** - * @return mixed + * @return string|null */ public function getAmount() { if (isset($this->data['amount'])) { return $this->data['amount']; } + + return null; } /** - * @return mixed + * @return array|null */ public function getMetadata() { if (isset($this->data['metadata'])) { return $this->data['metadata']; } + + return null; } } diff --git a/src/Message/PurchaseResponse.php b/src/Message/Response/PurchaseResponse.php similarity index 88% rename from src/Message/PurchaseResponse.php rename to src/Message/Response/PurchaseResponse.php index 2b43915..798fc43 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/Response/PurchaseResponse.php @@ -1,6 +1,6 @@ data['id'])) { return $this->data['id']; } + + return null; } } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 7de065a..254a4d6 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -2,16 +2,17 @@ namespace Omnipay\Mollie\Test; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Gateway; -use Omnipay\Mollie\Message\CompletePurchaseRequest; -use Omnipay\Mollie\Message\CreateCustomerRequest; -use Omnipay\Mollie\Message\FetchCustomerRequest; -use Omnipay\Mollie\Message\FetchIssuersRequest; -use Omnipay\Mollie\Message\FetchPaymentMethodsRequest; -use Omnipay\Mollie\Message\FetchTransactionRequest; -use Omnipay\Mollie\Message\PurchaseRequest; -use Omnipay\Mollie\Message\RefundRequest; -use Omnipay\Mollie\Message\UpdateCustomerRequest; +use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; +use Omnipay\Mollie\Message\Request\CreateCustomerRequest; +use Omnipay\Mollie\Message\Request\FetchCustomerRequest; +use Omnipay\Mollie\Message\Request\FetchIssuersRequest; +use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; +use Omnipay\Mollie\Message\Request\FetchTransactionRequest; +use Omnipay\Mollie\Message\Request\PurchaseRequest; +use Omnipay\Mollie\Message\Request\RefundRequest; +use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase @@ -42,6 +43,9 @@ public function testFetchPaymentMethods() $this->assertInstanceOf(FetchPaymentMethodsRequest::class, $request); } + /** + * @throws InvalidRequestException + */ public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '10.00', 'currency' => 'EUR')); @@ -51,6 +55,9 @@ public function testPurchase() $this->assertSame('EUR', $request->getCurrency()); } + /** + * @throws InvalidRequestException + */ public function testPurchaseReturn() { $request = $this->gateway->completePurchase(array('amount' => '10.00', 'currency' => 'EUR')); diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index 41eb1a6..f6f887b 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Mollie\Test\Message; -use Omnipay\Mollie\Message\CompletePurchaseRequest; -use Omnipay\Mollie\Message\CompletePurchaseResponse; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; +use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; class CompletePurchaseRequestTest extends TestCase @@ -28,7 +29,7 @@ public function setUp() } /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException + * @expectedException InvalidRequestException * @expectedExceptionMessage The transactionReference parameter is required */ public function testGetDataWithoutIDParameter() @@ -40,6 +41,9 @@ public function testGetDataWithoutIDParameter() $this->assertEmpty($data); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $data = $this->request->getData(); diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 8462f3f..20aefc0 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Mollie\Test\Message; -use Omnipay\Mollie\Message\CreateCustomerRequest; -use Omnipay\Mollie\Message\CreateCustomerResponse; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Mollie\Message\Request\CreateCustomerRequest; +use Omnipay\Mollie\Message\Response\CreateCustomerResponse; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase @@ -29,6 +30,9 @@ public function setUp() )); } + /** + * @throws InvalidRequestException + */ public function testData() { $this->request->initialize(array( diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php index ae86e41..bf1aef8 100644 --- a/tests/Message/FetchCustomerRequestTest.php +++ b/tests/Message/FetchCustomerRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Mollie\Test\Message; -use Omnipay\Mollie\Message\FetchCustomerRequest; -use Omnipay\Mollie\Message\FetchCustomerResponse; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Mollie\Message\Request\FetchCustomerRequest; +use Omnipay\Mollie\Message\Response\FetchCustomerResponse; use Omnipay\Tests\TestCase; class FetchCustomerRequestTest extends TestCase @@ -26,6 +27,9 @@ public function setUp() ); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $data = $this->request->getData(); diff --git a/tests/Message/FetchIssuersRequestTest.php b/tests/Message/FetchIssuersRequestTest.php index 392b602..6eee515 100644 --- a/tests/Message/FetchIssuersRequestTest.php +++ b/tests/Message/FetchIssuersRequestTest.php @@ -3,9 +3,10 @@ namespace Omnipay\Mollie\Test\Message; use GuzzleHttp\Psr7\Request; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Issuer; -use Omnipay\Mollie\Message\FetchIssuersRequest; -use Omnipay\Mollie\Message\FetchIssuersResponse; +use Omnipay\Mollie\Message\Request\FetchIssuersRequest; +use Omnipay\Mollie\Message\Response\FetchIssuersResponse; use Omnipay\Tests\TestCase; class FetchIssuersRequestTest extends TestCase @@ -25,6 +26,9 @@ public function setUp() )); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $data = $this->request->getData(); diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php index 6ab515a..f7eec11 100644 --- a/tests/Message/FetchPaymentMethodsRequestTest.php +++ b/tests/Message/FetchPaymentMethodsRequestTest.php @@ -2,9 +2,10 @@ namespace Omnipay\Mollie\Test\Message; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\PaymentMethod; -use Omnipay\Mollie\Message\FetchPaymentMethodsRequest; -use Omnipay\Mollie\Message\FetchPaymentMethodsResponse; +use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; +use Omnipay\Mollie\Message\Response\FetchPaymentMethodsResponse; use Omnipay\Tests\TestCase; class FetchPaymentMethodsRequestTest extends TestCase @@ -24,6 +25,9 @@ public function setUp() )); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $data = $this->request->getData(); diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index a8acc9b..979abb5 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -3,8 +3,9 @@ namespace Omnipay\Mollie\Test\Message; use GuzzleHttp\Psr7\Request; -use Omnipay\Mollie\Message\FetchTransactionRequest; -use Omnipay\Mollie\Message\FetchTransactionResponse; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Mollie\Message\Request\FetchTransactionRequest; +use Omnipay\Mollie\Message\Response\FetchTransactionResponse; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase @@ -12,7 +13,7 @@ class FetchTransactionRequestTest extends TestCase use AssertRequestTrait; /** - * @var \Omnipay\Mollie\Message\FetchTransactionRequest + * @var FetchTransactionRequest */ protected $request; @@ -27,6 +28,9 @@ public function setUp() ); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $data = $this->request->getData(); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 7cb5d00..ca7d18e 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -1,8 +1,9 @@ 'Description', 'returnUrl' => 'https://www.example.com/return', 'method' => 'ideal', - 'metadata' => 'meta', + 'metadata' => ['meta'], 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', )); } + /** + * @throws InvalidRequestException + */ public function testGetData() { $this->request->initialize([ @@ -40,7 +44,7 @@ public function testGetData() 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', - 'metadata' => 'meta', + 'metadata' => ['meta'], 'issuer' => 'my bank', 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', @@ -52,13 +56,16 @@ public function testGetData() $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(['meta'], $data['metadata']); $this->assertSame('my bank', $data['issuer']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); $this->assertCount(8, $data); } + /** + * @throws InvalidRequestException + */ public function testGetDataWithWebhook() { $this->request->initialize(array( @@ -68,7 +75,7 @@ public function testGetDataWithWebhook() 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', - 'metadata' => 'meta', + 'metadata' => ['meta'], 'issuer' => 'my bank', 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', @@ -81,7 +88,7 @@ public function testGetDataWithWebhook() $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(['meta'], $data['metadata']); $this->assertSame('my bank', $data['issuer']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); @@ -89,6 +96,9 @@ public function testGetDataWithWebhook() $this->assertCount(9, $data); } + /** + * @throws InvalidRequestException + */ public function testNoIssuer() { $this->request->initialize(array( @@ -98,7 +108,7 @@ public function testNoIssuer() 'description' => 'Description', 'returnUrl' => 'https://www.example.com/return', 'paymentMethod' => 'ideal', - 'metadata' => 'meta', + 'metadata' => ['meta'], 'locale' => 'fr_FR', 'billingEmail' => 'billing-email@example.com', 'notifyUrl' => 'https://www.example.com/hook', @@ -110,7 +120,7 @@ public function testNoIssuer() $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(['meta'], $data['metadata']); $this->assertSame('fr_FR', $data['locale']); $this->assertSame('billing-email@example.com', $data['billingEmail']); $this->assertSame('https://www.example.com/hook', $data['webhookUrl']); @@ -135,7 +145,9 @@ public function testSendSuccess() "description":"Description", "redirectUrl":"https:\/\/www.example.com\/return", "method":null, - "metadata":"meta", + "metadata":[ + "meta" + ], "issuer":"my bank", "locale":"fr_FR", "billingEmail":"billing-email@example.com" diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index cf540d1..ff037e1 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Mollie\Test\Message; use GuzzleHttp\Psr7\Request; -use Omnipay\Mollie\Message\RefundRequest; -use Omnipay\Mollie\Message\RefundResponse; +use Omnipay\Mollie\Message\Request\PurchaseRequest; +use Omnipay\Mollie\Message\Request\RefundRequest; +use Omnipay\Mollie\Message\Response\RefundResponse; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase @@ -11,8 +12,7 @@ class RefundRequestTest extends TestCase use AssertRequestTrait; /** - * - * @var \Omnipay\Mollie\Message\PurchaseRequest + * @var PurchaseRequest */ protected $request; @@ -27,6 +27,9 @@ public function setUp() ); } + /** + * @throws \Omnipay\Common\Exception\InvalidRequestException + */ public function testGetData() { $this->request->initialize( @@ -43,6 +46,9 @@ public function testGetData() $this->assertCount(1, $data); } + /** + * @throws \Omnipay\Common\Exception\InvalidRequestException + */ public function testGetDataWithoutAmount() { $this->request->initialize( @@ -69,7 +75,7 @@ public function testSendSuccess() ); - $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); + $this->assertInstanceOf(RefundResponse::class, $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); @@ -87,7 +93,7 @@ public function test401Failure() $this->getMockClient()->getLastRequest() ); - $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); + $this->assertInstanceOf(RefundResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertEquals('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); } @@ -103,7 +109,7 @@ public function test422Failure() $this->getMockClient()->getLastRequest() ); - $this->assertInstanceOf('Omnipay\Mollie\Message\RefundResponse', $response); + $this->assertInstanceOf(RefundResponse::class, $response); $this->assertFalse($response->isSuccessful()); $this->assertEquals('{"status":422,"title":"Unprocessable Entity","detail":"The payment method is invalid","field":"method","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/handling-errors","type":"text\/html"}}}', $response->getMessage()); } diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index 1ec59a6..b34fbf7 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Mollie\Test\Message; -use Omnipay\Mollie\Message\UpdateCustomerRequest; -use Omnipay\Mollie\Message\UpdateCustomerResponse; +use Omnipay\Common\Exception\InvalidRequestException; +use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; +use Omnipay\Mollie\Message\Response\UpdateCustomerResponse; use Omnipay\Tests\TestCase; class UpdateCustomerRequestTest extends TestCase @@ -12,7 +13,7 @@ class UpdateCustomerRequestTest extends TestCase /** * - * @var \Omnipay\Mollie\Message\UpdateCustomerRequest + * @var UpdateCustomerRequest */ protected $request; @@ -30,6 +31,9 @@ public function setUp() )); } + /** + * @throws InvalidRequestException + */ public function testData() { $this->request->initialize(array( From 10254a154c1a0637e4dba141745fbf398b0e3ed6 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 11:36:26 +0200 Subject: [PATCH 12/25] Splitting requests and responses to separate namespases and adding some doc blocks -- second bunch --- src/Message/Response/AbstractResponse.php | 2 +- src/Message/Response/FetchTransactionResponse.php | 4 +++- tests/Message/CompletePurchaseRequestTest.php | 5 ++--- tests/Message/CreateCustomerRequestTest.php | 5 ++++- tests/Message/FetchCustomerRequestTest.php | 5 ++++- tests/Message/FetchIssuersRequestTest.php | 2 +- tests/Message/FetchPaymentMethodsRequestTest.php | 2 +- tests/Message/PurchaseRequestTest.php | 5 ++++- tests/Message/UpdateCustomerRequestTest.php | 5 ++++- 9 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Message/Response/AbstractResponse.php b/src/Message/Response/AbstractResponse.php index 9cd7135..60b5850 100644 --- a/src/Message/Response/AbstractResponse.php +++ b/src/Message/Response/AbstractResponse.php @@ -6,7 +6,7 @@ class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse { public function isSuccessful() { - if(isset($this->data['status']) && isset($this->data['detail'])) { + if (isset($this->data['status']) && isset($this->data['detail'])) { return $this->data['status'] >= 200 && $this->data['status'] < 300; } diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index 05ca873..f88f1ec 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -97,7 +97,9 @@ public function isRefunded() public function isPartialRefunded() { - return $this->isRefunded() && isset($this->data['amountRemaining']) && $this->data['amountRemaining']['value'] > 0; + return $this->isRefunded() + && isset($this->data['amountRemaining']) + && $this->data['amountRemaining']['value'] > 0; } /** diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index f6f887b..e05cfb1 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -2,7 +2,6 @@ namespace Omnipay\Mollie\Test\Message; -use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; @@ -29,7 +28,7 @@ public function setUp() } /** - * @expectedException InvalidRequestException + * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage The transactionReference parameter is required */ public function testGetDataWithoutIDParameter() @@ -42,7 +41,7 @@ public function testGetDataWithoutIDParameter() } /** - * @throws InvalidRequestException + * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function testGetData() { diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 20aefc0..4aa7190 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -75,7 +75,10 @@ public function testSendSuccess() $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); - $this->assertNull($response->getMessage()); + $this->assertJsonStringEqualsJsonString( + '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"John Doe","email":"john@doe.com","locale":"nl_NL","metadata":"Just some meta data.","createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/create-customer","type":"text\/html"}}}', + $response->getMessage() + ); } public function testSendFailure() diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php index bf1aef8..4e41bae 100644 --- a/tests/Message/FetchCustomerRequestTest.php +++ b/tests/Message/FetchCustomerRequestTest.php @@ -50,7 +50,10 @@ public function testSendSuccess() $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); - $this->assertNull($response->getMessage()); + $this->assertJsonStringEqualsJsonString( + '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"John Doe","email":"john@doe.com","locale":"nl_NL","metadata":null,"createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/get-customer","type":"text\/html"}}}', + $response->getMessage() + ); } public function testSendFailure() diff --git a/tests/Message/FetchIssuersRequestTest.php b/tests/Message/FetchIssuersRequestTest.php index 6eee515..5ef6cd0 100644 --- a/tests/Message/FetchIssuersRequestTest.php +++ b/tests/Message/FetchIssuersRequestTest.php @@ -72,7 +72,7 @@ public function testSendFailure() $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); - $this->assertNull($response->getIssuers()); + $this->assertEmpty($response->getIssuers()); } } diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php index f7eec11..a8fbe89 100644 --- a/tests/Message/FetchPaymentMethodsRequestTest.php +++ b/tests/Message/FetchPaymentMethodsRequestTest.php @@ -66,6 +66,6 @@ public function testSendFailure() $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('{"status":401,"title":"Unauthorized Request","detail":"Missing authentication, or failed to authenticate","_links":{"documentation":{"href":"https:\/\/docs.mollie.com\/guides\/authentication","type":"text\/html"}}}', $response->getMessage()); - $this->assertNull($response->getPaymentMethods()); + $this->assertEmpty($response->getPaymentMethods()); } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index ca7d18e..978ac02 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -167,7 +167,10 @@ public function testSendSuccess() $this->assertTrue($response->isOpen()); $this->assertFalse($response->isPaid()); $this->assertNull($response->getCode()); - $this->assertNull($response->getMessage()); + $this->assertJsonStringEqualsJsonString( + '{"resource":"payment","id":"tr_7UhSN1zuXS","mode":"test","createdAt":"2018-03-20T09:13:37+00:00","amount":{"value":"10.00","currency":"EUR"},"description":"My first payment","method":null,"metadata":{"order_id":"12345"},"status":"open","isCancelable":false,"expiresAt":"2018-03-20T09:28:37+00:00","details":null,"profileId":"pfl_QkEhN94Ba","sequenceType":"oneoff","redirectUrl":"https:\/\/webshop.example.org\/order\/12345\/","webhookUrl":"https:\/\/webshop.example.org\/payments\/webhook\/","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/payments\/tr_7UhSN1zuXS","type":"application\/json"},"checkout":{"href":"https:\/\/www.mollie.com\/payscreen\/select-method\/7UhSN1zuXS","type":"text\/html"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/payments-api\/create-payment","type":"text\/html"}}}', + $response->getMessage() + ); } public function testIssuerFailure() diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index b34fbf7..5ca06c8 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -78,7 +78,10 @@ public function testSendSuccess() $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); $this->assertTrue($response->isSuccessful()); - $this->assertNull($response->getMessage()); + $this->assertJsonStringEqualsJsonString( + '{"resource":"customer","id":"cst_bSNBBJBzdG","mode":"test","name":"Jane Doe","email":"john@doe.com","locale":"nl_NL","metadata":"Just some meta data.","createdAt":"2018-07-19T12:58:47+00:00","_links":{"self":{"href":"https:\/\/api.mollie.com\/v2\/customers\/cst_6HUkmjwzBB","type":"application\/hal+json"},"documentation":{"href":"https:\/\/docs.mollie.com\/reference\/v2\/customers-api\/update-customer","type":"text\/html"}}}', + $response->getMessage() + ); } public function testSendFailure() From 36902641baff4f9a0d734c19571f0e045e561cd4 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 11:56:48 +0200 Subject: [PATCH 13/25] Added phplint and phpmd --- composer.json | 5 ++++- grumphp.yml | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 85512d4..ff5df72 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,10 @@ "require-dev": { "omnipay/tests": "^3", "squizlabs/php_codesniffer": "^3", - "phpro/grumphp": "^0.14" + "phpro/grumphp": "^0.14", + "phpmd/phpmd": "@stable", + "overtrue/phplint": "@stable", + "jakub-onderka/php-parallel-lint": "@stable" }, "extra": { "branch-alias": { diff --git a/grumphp.yml b/grumphp.yml index 4b767a0..d643001 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -12,4 +12,11 @@ parameters: warning_severity: ~ ignore_patterns: - tests/ - triggered_by: [php] \ No newline at end of file + triggered_by: [php] + phpmd: + exclude: [] + ruleset: ['cleancode', 'codesize', 'naming'] + triggered_by: ['php'] + phplint: + exclude: [] + triggered_by: ['php', 'phtml', 'php3', 'php4', 'php5'] \ No newline at end of file From fde65f3feca96ff16dbe1b5da56a1aa0e4a88d8a Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 12:04:12 +0200 Subject: [PATCH 14/25] Code style --- src/Message/Response/AbstractResponse.php | 6 ++++++ src/Message/Response/FetchIssuersResponse.php | 14 +++++++------- .../Response/FetchPaymentMethodsResponse.php | 14 +++++++------- src/Message/Response/FetchTransactionResponse.php | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Message/Response/AbstractResponse.php b/src/Message/Response/AbstractResponse.php index 60b5850..da1645c 100644 --- a/src/Message/Response/AbstractResponse.php +++ b/src/Message/Response/AbstractResponse.php @@ -4,6 +4,9 @@ class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse { + /** + * @return bool + */ public function isSuccessful() { if (isset($this->data['status']) && isset($this->data['detail'])) { @@ -13,6 +16,9 @@ public function isSuccessful() return true; } + /** + * @return string + */ public function getMessage() { return json_encode($this->data); diff --git a/src/Message/Response/FetchIssuersResponse.php b/src/Message/Response/FetchIssuersResponse.php index 1d7a5e8..7436cdd 100644 --- a/src/Message/Response/FetchIssuersResponse.php +++ b/src/Message/Response/FetchIssuersResponse.php @@ -15,15 +15,15 @@ class FetchIssuersResponse extends AbstractResponse implements FetchIssuersRespo */ public function getIssuers() { - if (isset($this->data['issuers'])) { - $issuers = []; - foreach ($this->data['issuers'] as $issuer) { - $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); - } + if (isset($this->data['issuers']) === false) { + return []; + } - return $issuers; + $issuers = []; + foreach ($this->data['issuers'] as $issuer) { + $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); } - return []; + return $issuers; } } diff --git a/src/Message/Response/FetchPaymentMethodsResponse.php b/src/Message/Response/FetchPaymentMethodsResponse.php index 0846aa8..a1383ac 100644 --- a/src/Message/Response/FetchPaymentMethodsResponse.php +++ b/src/Message/Response/FetchPaymentMethodsResponse.php @@ -15,15 +15,15 @@ class FetchPaymentMethodsResponse extends AbstractResponse implements FetchPayme */ public function getPaymentMethods() { - if (isset($this->data['_embedded']["methods"])) { - $paymentMethods = []; - foreach ($this->data['_embedded']["methods"] as $method) { - $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); - } + if (isset($this->data['_embedded']["methods"]) === false) { + return []; + } - return $paymentMethods; + $paymentMethods = []; + foreach ($this->data['_embedded']["methods"] as $method) { + $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } - return []; + return $paymentMethods; } } diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index f88f1ec..2d1167f 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -103,7 +103,7 @@ public function isPartialRefunded() } /** - * @return string:null + * @return string|null */ public function getTransactionReference() { From 9d3a4ac9ff0319149a2ce9dcf6320d2dd6d48269 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 14:21:05 +0200 Subject: [PATCH 15/25] Classes descriptions and links to ththe documentation --- src/Message/Request/AbstractMollieRequest.php | 2 ++ .../Request/CompletePurchaseRequest.php | 4 +++- src/Message/Request/CreateCustomerRequest.php | 13 +++++++------ src/Message/Request/FetchCustomerRequest.php | 4 ++-- src/Message/Request/FetchIssuersRequest.php | 11 +++++++++-- .../Request/FetchPaymentMethodsRequest.php | 13 ++++++++++++- .../Request/FetchTransactionRequest.php | 7 +++++-- src/Message/Request/PurchaseRequest.php | 6 +++++- src/Message/Request/RefundRequest.php | 19 ++++++++++++++++++- src/Message/Request/UpdateCustomerRequest.php | 4 ++-- .../Response/CompletePurchaseResponse.php | 3 +++ .../Response/CreateCustomerResponse.php | 3 +++ .../Response/FetchCustomerResponse.php | 3 +++ src/Message/Response/FetchIssuersResponse.php | 3 +++ .../Response/FetchPaymentMethodsResponse.php | 3 +++ .../Response/FetchTransactionResponse.php | 3 +++ src/Message/Response/PurchaseResponse.php | 3 +++ src/Message/Response/RefundResponse.php | 3 +++ .../Response/UpdateCustomerResponse.php | 3 +++ 19 files changed, 92 insertions(+), 18 deletions(-) diff --git a/src/Message/Request/AbstractMollieRequest.php b/src/Message/Request/AbstractMollieRequest.php index 5342928..017c15b 100755 --- a/src/Message/Request/AbstractMollieRequest.php +++ b/src/Message/Request/AbstractMollieRequest.php @@ -6,6 +6,8 @@ /** * This class holds all the common things for all of Mollie requests. + * + * @see https://docs.mollie.com/index */ abstract class AbstractMollieRequest extends AbstractRequest { diff --git a/src/Message/Request/CompletePurchaseRequest.php b/src/Message/Request/CompletePurchaseRequest.php index 2c448e3..f35bb9b 100755 --- a/src/Message/Request/CompletePurchaseRequest.php +++ b/src/Message/Request/CompletePurchaseRequest.php @@ -6,7 +6,9 @@ use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; /** - * Mollie Complete Purchase Request + * Retrieve a single payment object by its payment token. + * + * @see https://docs.mollie.com/reference/v2/payments-api/get-payment * * @method \Omnipay\Mollie\Message\Response\CompletePurchaseResponse send() */ diff --git a/src/Message/Request/CreateCustomerRequest.php b/src/Message/Request/CreateCustomerRequest.php index 99ab8d5..62b03e6 100755 --- a/src/Message/Request/CreateCustomerRequest.php +++ b/src/Message/Request/CreateCustomerRequest.php @@ -1,16 +1,17 @@ sendRequest(self::POST, '/payments/' . $this->getTransactionReference() . '/refunds', $data); + $response = $this->sendRequest( + self::POST, + '/payments/' . $this->getTransactionReference() . '/refunds', + $data + ); return $this->response = new RefundResponse($this, $response); } diff --git a/src/Message/Request/UpdateCustomerRequest.php b/src/Message/Request/UpdateCustomerRequest.php index e504e92..de3802c 100755 --- a/src/Message/Request/UpdateCustomerRequest.php +++ b/src/Message/Request/UpdateCustomerRequest.php @@ -7,9 +7,9 @@ use Omnipay\Mollie\Message\Response\UpdateCustomerResponse; /** - * Mollie Update Customer Request. + * Update an existing customer. * - * URL: https://www.mollie.com/en/docs/reference/customers/update + * @see https://docs.mollie.com/reference/v2/customers-api/update-customer */ class UpdateCustomerRequest extends AbstractMollieRequest { diff --git a/src/Message/Response/CompletePurchaseResponse.php b/src/Message/Response/CompletePurchaseResponse.php index a47df93..11c9412 100644 --- a/src/Message/Response/CompletePurchaseResponse.php +++ b/src/Message/Response/CompletePurchaseResponse.php @@ -2,6 +2,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/payments-api/get-payment + */ class CompletePurchaseResponse extends FetchTransactionResponse { /** diff --git a/src/Message/Response/CreateCustomerResponse.php b/src/Message/Response/CreateCustomerResponse.php index d75aada..f8cd3bc 100644 --- a/src/Message/Response/CreateCustomerResponse.php +++ b/src/Message/Response/CreateCustomerResponse.php @@ -2,6 +2,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/customers-api/create-customer + */ class CreateCustomerResponse extends AbstractResponse { /** diff --git a/src/Message/Response/FetchCustomerResponse.php b/src/Message/Response/FetchCustomerResponse.php index 0b86f73..fd4c84e 100644 --- a/src/Message/Response/FetchCustomerResponse.php +++ b/src/Message/Response/FetchCustomerResponse.php @@ -2,6 +2,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/customers-api/get-customer + */ class FetchCustomerResponse extends AbstractResponse { /** diff --git a/src/Message/Response/FetchIssuersResponse.php b/src/Message/Response/FetchIssuersResponse.php index 7436cdd..98a421a 100644 --- a/src/Message/Response/FetchIssuersResponse.php +++ b/src/Message/Response/FetchIssuersResponse.php @@ -6,6 +6,9 @@ use Omnipay\Common\Issuer as CommonIssuer; use Omnipay\Common\Message\FetchIssuersResponseInterface; +/** + * @see https://docs.mollie.com/reference/v2/methods-api/get-method + */ class FetchIssuersResponse extends AbstractResponse implements FetchIssuersResponseInterface { /** diff --git a/src/Message/Response/FetchPaymentMethodsResponse.php b/src/Message/Response/FetchPaymentMethodsResponse.php index a1383ac..b39ea82 100644 --- a/src/Message/Response/FetchPaymentMethodsResponse.php +++ b/src/Message/Response/FetchPaymentMethodsResponse.php @@ -6,6 +6,9 @@ use Omnipay\Common\PaymentMethod; use Omnipay\Common\PaymentMethod as CommonPaymentMethod; +/** + * @see https://docs.mollie.com/reference/v2/methods-api/list-methods + */ class FetchPaymentMethodsResponse extends AbstractResponse implements FetchPaymentMethodsResponseInterface { /** diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index 2d1167f..4890ba4 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -4,6 +4,9 @@ use Omnipay\Common\Message\RedirectResponseInterface; +/** + * @see https://docs.mollie.com/reference/v2/payments-api/get-payment + */ class FetchTransactionResponse extends AbstractResponse implements RedirectResponseInterface { /** diff --git a/src/Message/Response/PurchaseResponse.php b/src/Message/Response/PurchaseResponse.php index 798fc43..7dbea8e 100644 --- a/src/Message/Response/PurchaseResponse.php +++ b/src/Message/Response/PurchaseResponse.php @@ -2,6 +2,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/payments-api/create-payment + */ class PurchaseResponse extends FetchTransactionResponse { /** diff --git a/src/Message/Response/RefundResponse.php b/src/Message/Response/RefundResponse.php index 318aef5..962ff75 100644 --- a/src/Message/Response/RefundResponse.php +++ b/src/Message/Response/RefundResponse.php @@ -3,6 +3,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/refunds-api/create-refund + */ class RefundResponse extends AbstractResponse { /** diff --git a/src/Message/Response/UpdateCustomerResponse.php b/src/Message/Response/UpdateCustomerResponse.php index 38c4515..4a087f9 100644 --- a/src/Message/Response/UpdateCustomerResponse.php +++ b/src/Message/Response/UpdateCustomerResponse.php @@ -2,6 +2,9 @@ namespace Omnipay\Mollie\Message\Response; +/** + * @see https://docs.mollie.com/reference/v2/customers-api/update-customer + */ class UpdateCustomerResponse extends AbstractResponse { /** From 1acaea3737326654bac87d47c38bcd930dcede88 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Fri, 20 Jul 2018 14:29:20 +0200 Subject: [PATCH 16/25] AbstractResponse -> AbstractMollieResponse --- src/Message/Request/FetchTransactionRequest.php | 3 +-- .../{AbstractResponse.php => AbstractMollieResponse.php} | 4 +++- src/Message/Response/CreateCustomerResponse.php | 2 +- src/Message/Response/FetchCustomerResponse.php | 2 +- src/Message/Response/FetchIssuersResponse.php | 5 ++--- src/Message/Response/FetchPaymentMethodsResponse.php | 7 +++---- src/Message/Response/FetchTransactionResponse.php | 2 +- src/Message/Response/RefundResponse.php | 3 +-- src/Message/Response/UpdateCustomerResponse.php | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) rename src/Message/Response/{AbstractResponse.php => AbstractMollieResponse.php} (81%) diff --git a/src/Message/Request/FetchTransactionRequest.php b/src/Message/Request/FetchTransactionRequest.php index 50f8faf..53215bb 100755 --- a/src/Message/Request/FetchTransactionRequest.php +++ b/src/Message/Request/FetchTransactionRequest.php @@ -5,14 +5,13 @@ use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\FetchTransactionResponse; -use Omnipay\Mollie\Message\Response\FetchTransactionResponse as FetchTransactionMollieResponse; /** * Retrieve a single payment object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-payment * - * @method FetchTransactionMollieResponse send() + * @method FetchTransactionResponse send() */ class FetchTransactionRequest extends AbstractMollieRequest { diff --git a/src/Message/Response/AbstractResponse.php b/src/Message/Response/AbstractMollieResponse.php similarity index 81% rename from src/Message/Response/AbstractResponse.php rename to src/Message/Response/AbstractMollieResponse.php index da1645c..d5a8c03 100644 --- a/src/Message/Response/AbstractResponse.php +++ b/src/Message/Response/AbstractMollieResponse.php @@ -2,7 +2,9 @@ namespace Omnipay\Mollie\Message\Response; -class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse +use Omnipay\Common\Message\AbstractResponse; + +class AbstractMollieResponse extends AbstractResponse { /** * @return bool diff --git a/src/Message/Response/CreateCustomerResponse.php b/src/Message/Response/CreateCustomerResponse.php index f8cd3bc..73b837e 100644 --- a/src/Message/Response/CreateCustomerResponse.php +++ b/src/Message/Response/CreateCustomerResponse.php @@ -5,7 +5,7 @@ /** * @see https://docs.mollie.com/reference/v2/customers-api/create-customer */ -class CreateCustomerResponse extends AbstractResponse +class CreateCustomerResponse extends AbstractMollieResponse { /** * @return string|null diff --git a/src/Message/Response/FetchCustomerResponse.php b/src/Message/Response/FetchCustomerResponse.php index fd4c84e..e794962 100644 --- a/src/Message/Response/FetchCustomerResponse.php +++ b/src/Message/Response/FetchCustomerResponse.php @@ -5,7 +5,7 @@ /** * @see https://docs.mollie.com/reference/v2/customers-api/get-customer */ -class FetchCustomerResponse extends AbstractResponse +class FetchCustomerResponse extends AbstractMollieResponse { /** * @return string|null diff --git a/src/Message/Response/FetchIssuersResponse.php b/src/Message/Response/FetchIssuersResponse.php index 98a421a..400a644 100644 --- a/src/Message/Response/FetchIssuersResponse.php +++ b/src/Message/Response/FetchIssuersResponse.php @@ -3,18 +3,17 @@ namespace Omnipay\Mollie\Message\Response; use Omnipay\Common\Issuer; -use Omnipay\Common\Issuer as CommonIssuer; use Omnipay\Common\Message\FetchIssuersResponseInterface; /** * @see https://docs.mollie.com/reference/v2/methods-api/get-method */ -class FetchIssuersResponse extends AbstractResponse implements FetchIssuersResponseInterface +class FetchIssuersResponse extends AbstractMollieResponse implements FetchIssuersResponseInterface { /** * Return available issuers as an associative array. * - * @return CommonIssuer[] + * @return Issuer[] */ public function getIssuers() { diff --git a/src/Message/Response/FetchPaymentMethodsResponse.php b/src/Message/Response/FetchPaymentMethodsResponse.php index b39ea82..1b615ae 100644 --- a/src/Message/Response/FetchPaymentMethodsResponse.php +++ b/src/Message/Response/FetchPaymentMethodsResponse.php @@ -4,17 +4,16 @@ use Omnipay\Common\Message\FetchPaymentMethodsResponseInterface; use Omnipay\Common\PaymentMethod; -use Omnipay\Common\PaymentMethod as CommonPaymentMethod; /** * @see https://docs.mollie.com/reference/v2/methods-api/list-methods */ -class FetchPaymentMethodsResponse extends AbstractResponse implements FetchPaymentMethodsResponseInterface +class FetchPaymentMethodsResponse extends AbstractMollieResponse implements FetchPaymentMethodsResponseInterface { /** - * Return available paymentmethods as an associative array. + * Return available payment methods as an associative array. * - * @return CommonPaymentMethod[] + * @return PaymentMethod[] */ public function getPaymentMethods() { diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index 4890ba4..ea0e4cb 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -7,7 +7,7 @@ /** * @see https://docs.mollie.com/reference/v2/payments-api/get-payment */ -class FetchTransactionResponse extends AbstractResponse implements RedirectResponseInterface +class FetchTransactionResponse extends AbstractMollieResponse implements RedirectResponseInterface { /** * {@inheritdoc} diff --git a/src/Message/Response/RefundResponse.php b/src/Message/Response/RefundResponse.php index 962ff75..331db6d 100644 --- a/src/Message/Response/RefundResponse.php +++ b/src/Message/Response/RefundResponse.php @@ -1,12 +1,11 @@ Date: Fri, 20 Jul 2018 14:35:47 +0200 Subject: [PATCH 17/25] Gateway docs --- src/Gateway.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index a766eeb..6bcee32 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -16,9 +16,12 @@ use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; /** - * Mollie (iDeal) Gateway + * Mollie Gateway provides a wrapper for Mollie API. + * Please have a look at links below to have a high-level overview and see the API specification + * + * @see https://www.mollie.com/en/developers + * @see https://docs.mollie.com/index * - * @link https://www.mollie.com/en/developers * @method RequestInterface authorize(array $options = array()) * @method RequestInterface completeAuthorize(array $options = array()) * @method RequestInterface capture(array $options = array()) From f8015d1d5ad5270ba2d6d7d589276b879ebea4eb Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Fri, 20 Jul 2018 15:29:08 +0200 Subject: [PATCH 18/25] Add currency to the purchase validation --- src/Message/Request/PurchaseRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/Request/PurchaseRequest.php b/src/Message/Request/PurchaseRequest.php index 44037a0..a2a8ef7 100755 --- a/src/Message/Request/PurchaseRequest.php +++ b/src/Message/Request/PurchaseRequest.php @@ -74,7 +74,7 @@ public function setBillingEmail($value) */ public function getData() { - $this->validate('apiKey', 'amount', 'description', 'returnUrl'); + $this->validate('apiKey', 'amount', 'currency', 'description', 'returnUrl'); $data = []; $data['amount'] = [ From c635a3aad366d75310588ba104c1510967675be6 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Fri, 20 Jul 2018 16:27:04 +0200 Subject: [PATCH 19/25] Some self-review changes --- src/Gateway.php | 11 ----------- src/Message/Request/AbstractMollieRequest.php | 4 ++-- src/Message/Request/CompletePurchaseRequest.php | 2 -- src/Message/Request/CreateCustomerRequest.php | 7 +++---- src/Message/Request/FetchCustomerRequest.php | 11 ++--------- src/Message/Request/FetchIssuersRequest.php | 8 +++----- src/Message/Request/FetchPaymentMethodsRequest.php | 13 +------------ src/Message/Request/FetchTransactionRequest.php | 2 -- src/Message/Request/PurchaseRequest.php | 6 +----- src/Message/Request/RefundRequest.php | 11 ++--------- src/Message/Response/AbstractMollieResponse.php | 2 +- tests/Message/AssertRequestTrait.php | 2 ++ tests/Message/CompletePurchaseRequestTest.php | 5 +++-- tests/Message/CreateCustomerRequestTest.php | 7 ++++--- tests/Message/FetchCustomerRequestTest.php | 5 +++-- tests/Message/FetchPaymentMethodsRequestTest.php | 5 +++-- tests/Message/PurchaseRequestTest.php | 5 +++-- tests/Message/UpdateCustomerRequestTest.php | 5 +++-- 18 files changed, 36 insertions(+), 75 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 6bcee32..e39bfdd 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -147,15 +147,4 @@ public function fetchCustomer(array $parameters = []) { return $this->createRequest(FetchCustomerRequest::class, $parameters); } - - public function __call($name, $arguments) - { - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface authorize(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface completeAuthorize(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface capture(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface void(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface createCard(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface updateCard(array $options = array()) - // TODO: Implement @method \Omnipay\Common\Message\RequestInterface deleteCard(array $options = array()) - } } diff --git a/src/Message/Request/AbstractMollieRequest.php b/src/Message/Request/AbstractMollieRequest.php index 017c15b..d66d7ae 100755 --- a/src/Message/Request/AbstractMollieRequest.php +++ b/src/Message/Request/AbstractMollieRequest.php @@ -69,9 +69,9 @@ protected function sendRequest($method, $endpoint, array $data = null) $response = $this->httpClient->request( $method, $this->baseUrl . $this->apiVersion . $endpoint, - array( + [ 'Authorization' => 'Bearer ' . $this->getApiKey() - ), + ], json_encode($data) ); diff --git a/src/Message/Request/CompletePurchaseRequest.php b/src/Message/Request/CompletePurchaseRequest.php index f35bb9b..f6732d8 100755 --- a/src/Message/Request/CompletePurchaseRequest.php +++ b/src/Message/Request/CompletePurchaseRequest.php @@ -9,8 +9,6 @@ * Retrieve a single payment object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-payment - * - * @method \Omnipay\Mollie\Message\Response\CompletePurchaseResponse send() */ class CompletePurchaseRequest extends FetchTransactionRequest { diff --git a/src/Message/Request/CreateCustomerRequest.php b/src/Message/Request/CreateCustomerRequest.php index 62b03e6..b1385e5 100755 --- a/src/Message/Request/CreateCustomerRequest.php +++ b/src/Message/Request/CreateCustomerRequest.php @@ -2,13 +2,12 @@ namespace Omnipay\Mollie\Message\Request; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\CreateCustomerResponse; /** - * Creates a simple minimal representation of a customer in the Mollie API to use for the Mollie Checkout and Recurring - * features. These customers will appear in your Dashboard where you can manage their details, and also see their - * payments and subscriptions. + * Creates a simple minimal representation of a customer in the Mollie API. * * @see https://docs.mollie.com/reference/v2/customers-api/create-customer */ @@ -79,7 +78,7 @@ public function setMetadata($value) /** * @return array - * @throws \Omnipay\Common\Exception\InvalidRequestException + * @throws InvalidRequestException */ public function getData() { diff --git a/src/Message/Request/FetchCustomerRequest.php b/src/Message/Request/FetchCustomerRequest.php index eda2da0..5c15431 100755 --- a/src/Message/Request/FetchCustomerRequest.php +++ b/src/Message/Request/FetchCustomerRequest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Message\Request; +use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Mollie\Message\Response\FetchCustomerResponse; @@ -31,7 +32,7 @@ public function setCustomerReference($value) /** * @return array - * @throws \Omnipay\Common\Exception\InvalidRequestException + * @throws InvalidRequestException */ public function getData() { @@ -50,12 +51,4 @@ public function sendData($data) return $this->response = new FetchCustomerResponse($this, $response); } - - /** - * @return string - */ - public function getEndpoint() - { - return $this->baseUrl . '/customers'; - } } diff --git a/src/Message/Request/FetchIssuersRequest.php b/src/Message/Request/FetchIssuersRequest.php index ed438fe..942a5df 100755 --- a/src/Message/Request/FetchIssuersRequest.php +++ b/src/Message/Request/FetchIssuersRequest.php @@ -7,17 +7,15 @@ use Psr\Http\Message\ResponseInterface; /** - * Returns issuers available for the payment method (e.g. for iDEAL, KBC/CBC payment button or gift cards). + * Returns issuers available for the ideal payment method. * * @see https://docs.mollie.com/reference/v2/methods-api/get-method - * - * @method FetchIssuersResponse send() */ class FetchIssuersRequest extends AbstractMollieRequest { /** - * This endpoint allows you to include additional information by appending the following values via the include - * query string parameter. + * Since the Issuer endpoint got removed in the Mollie v2 api. + * We now use the include parameter on the get-method endpoint. * * @var string */ diff --git a/src/Message/Request/FetchPaymentMethodsRequest.php b/src/Message/Request/FetchPaymentMethodsRequest.php index 87aff11..24f19ad 100755 --- a/src/Message/Request/FetchPaymentMethodsRequest.php +++ b/src/Message/Request/FetchPaymentMethodsRequest.php @@ -7,20 +7,9 @@ use Omnipay\Mollie\Message\Response\FetchPaymentMethodsResponse; /** - * Retrieve all available payment methods. The results are not paginated. - * - * For test mode, payment methods are returned that are enabled in the Dashboard (or the activation is pending). - * For live mode, payment methods are returned that have been activated on your account and have been enabled in the - * Dashboard. - * When using the first sequence type, methods will be returned if they can be used as a first payment in a recurring - * sequence and if they are enabled in the Dashboard. - * - * When using the recurring sequence type, methods that can be used for recurring payments or subscriptions will be - * returned. Enabling / disabling methods in the dashboard does not affect how they can be used for recurring payments. + * Retrieve all available payment methods. * * @see https://docs.mollie.com/reference/v2/methods-api/list-methods - * - * @method FetchPaymentMethodsResponse send() */ class FetchPaymentMethodsRequest extends AbstractMollieRequest { diff --git a/src/Message/Request/FetchTransactionRequest.php b/src/Message/Request/FetchTransactionRequest.php index 53215bb..8e05042 100755 --- a/src/Message/Request/FetchTransactionRequest.php +++ b/src/Message/Request/FetchTransactionRequest.php @@ -10,8 +10,6 @@ * Retrieve a single payment object by its payment token. * * @see https://docs.mollie.com/reference/v2/payments-api/get-payment - * - * @method FetchTransactionResponse send() */ class FetchTransactionRequest extends AbstractMollieRequest { diff --git a/src/Message/Request/PurchaseRequest.php b/src/Message/Request/PurchaseRequest.php index a2a8ef7..a82f3ca 100755 --- a/src/Message/Request/PurchaseRequest.php +++ b/src/Message/Request/PurchaseRequest.php @@ -7,13 +7,9 @@ use Omnipay\Mollie\Message\Response\PurchaseResponse; /** - * Payment creation is elemental to the Mollie API: this is where most payment implementations start off. Note optional - * parameters are accepted for certain payment methods. To wrap your head around the payment process, an explanation and - * flow charts can be found in the Overview. + * Create a payment with the Mollie API. * * @see https://docs.mollie.com/reference/v2/payments-api/create-payment - * - * @method PurchaseResponse send() */ class PurchaseRequest extends AbstractMollieRequest { diff --git a/src/Message/Request/RefundRequest.php b/src/Message/Request/RefundRequest.php index 213f41d..face214 100755 --- a/src/Message/Request/RefundRequest.php +++ b/src/Message/Request/RefundRequest.php @@ -8,15 +8,8 @@ use Omnipay\Mollie\Message\Response\RefundResponse; /** - * Most payment methods support refunds. This means you can request your payment to be refunded to the consumer. The - * amount of the refund will be withheld from your next settlement. - * - * Refunds are not available at all for Bitcoin, paysafecard and gift cards. If you need to refund direct debit - * payments, please contact our support department. - * - * Refunds support descriptions, which we will show in the Dashboard, your exports and pass to the consumer if possible. - * If you have insufficient balance with Mollie to perform the refund, the refund will be queued. We will automatically - * process the refund once your balance increases. + * Most payment methods support refunds. This means you can request your payment to be refunded to the consumer. + * The amount of the refund will be withheld from your next settlement. * * @see https://docs.mollie.com/reference/v2/refunds-api/create-refund */ diff --git a/src/Message/Response/AbstractMollieResponse.php b/src/Message/Response/AbstractMollieResponse.php index d5a8c03..64b0466 100644 --- a/src/Message/Response/AbstractMollieResponse.php +++ b/src/Message/Response/AbstractMollieResponse.php @@ -12,7 +12,7 @@ class AbstractMollieResponse extends AbstractResponse public function isSuccessful() { if (isset($this->data['status']) && isset($this->data['detail'])) { - return $this->data['status'] >= 200 && $this->data['status'] < 300; + return false; } return true; diff --git a/tests/Message/AssertRequestTrait.php b/tests/Message/AssertRequestTrait.php index 20cc6f3..b74abba 100644 --- a/tests/Message/AssertRequestTrait.php +++ b/tests/Message/AssertRequestTrait.php @@ -10,6 +10,8 @@ abstract function assertJsonStringEqualsJsonString($expected, $actual, $message public function assertEqualRequest(\Psr\Http\Message\RequestInterface $expectedRequest, \Psr\Http\Message\RequestInterface $actualRequest) { + $this->assertEquals($expectedRequest->getMethod(), $actualRequest->getMethod(), "Expected request Method should be equal to actual request method."); + $this->assertEquals($expectedRequest->getUri(), $actualRequest->getUri(), "Expected request Uri should be equal to actual request body."); if(!empty((string) $expectedRequest->getBody())) { diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index e05cfb1..11e4289 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Response\CompletePurchaseResponse; use Omnipay\Tests\TestCase; @@ -56,7 +57,7 @@ public function testSendSuccess() $this->setMockHttpResponse('CompletePurchaseSuccess.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertTrue($response->isSuccessful()); @@ -71,7 +72,7 @@ public function testSendExpired() $this->setMockHttpResponse('CompletePurchaseExpired.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/payments/tr_Qzin4iTWrU"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CompletePurchaseResponse::class, $response); $this->assertFalse($response->isSuccessful()); diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 4aa7190..e0cc3eb 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; use Omnipay\Mollie\Message\Response\CreateCustomerResponse; @@ -57,8 +58,8 @@ public function testSendSuccess() $response = $this->request->send(); $this->assertEqualRequest( - new \GuzzleHttp\Psr7\Request( - "GET", + new Request( + "POST", "https://api.mollie.com/v2/customers", [], '{ @@ -86,7 +87,7 @@ public function testSendFailure() $this->setMockHttpResponse('CreateCustomerFailure.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(CreateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php index 4e41bae..7553382 100644 --- a/tests/Message/FetchCustomerRequestTest.php +++ b/tests/Message/FetchCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\FetchCustomerRequest; use Omnipay\Mollie\Message\Response\FetchCustomerResponse; @@ -44,7 +45,7 @@ public function testSendSuccess() /** @var FetchCustomerResponse $response */ $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertSame('cst_bSNBBJBzdG', $response->getCustomerReference()); @@ -63,7 +64,7 @@ public function testSendFailure() /** @var FetchCustomerResponse $response */ $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php index a8fbe89..1296341 100644 --- a/tests/Message/FetchPaymentMethodsRequestTest.php +++ b/tests/Message/FetchPaymentMethodsRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\PaymentMethod; use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest; @@ -40,7 +41,7 @@ public function testSendSuccess() $this->setMockHttpResponse('FetchPaymentMethodsSuccess.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertTrue($response->isSuccessful()); @@ -59,7 +60,7 @@ public function testSendFailure() $this->setMockHttpResponse('FetchPaymentMethodsFailure.txt'); $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/methods"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(FetchPaymentMethodsResponse::class, $response); $this->assertFalse($response->isSuccessful()); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 978ac02..aac180c 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -1,6 +1,7 @@ request->send(); $this->assertEqualRequest( - new \GuzzleHttp\Psr7\Request( + new Request( "POST", "https://api.mollie.com/v2/payments", [], @@ -179,7 +180,7 @@ public function testIssuerFailure() $response = $this->request->send(); $this->assertEqualRequest( - new \GuzzleHttp\Psr7\Request( + new Request( "POST", "https://api.mollie.com/v2/payments" ), diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index 5ca06c8..71490c0 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -2,6 +2,7 @@ namespace Omnipay\Mollie\Test\Message; +use GuzzleHttp\Psr7\Request; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Mollie\Message\Request\UpdateCustomerRequest; use Omnipay\Mollie\Message\Response\UpdateCustomerResponse; @@ -60,7 +61,7 @@ public function testSendSuccess() $response = $this->request->send(); $this->assertEqualRequest( - new \GuzzleHttp\Psr7\Request( + new Request( "POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG", [], @@ -91,7 +92,7 @@ public function testSendFailure() /** @var UpdateCustomerResponse $response */ $response = $this->request->send(); - $this->assertEqualRequest(new \GuzzleHttp\Psr7\Request("GET", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); + $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG"), $this->getMockClient()->getLastRequest()); $this->assertInstanceOf(UpdateCustomerResponse::class, $response); $this->assertFalse($response->isSuccessful()); From 1618747b86909a94be92c83433d897dacaa65a53 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Mon, 23 Jul 2018 09:16:08 +0200 Subject: [PATCH 20/25] ClAmount fix for Refunds --- src/Message/Request/RefundRequest.php | 13 +++-- .../Response/FetchTransactionResponse.php | 25 ++++++++- tests/GatewayTest.php | 26 +++++++--- tests/Message/FetchTransactionRequestTest.php | 2 +- tests/Message/RefundRequestTest.php | 51 +++++++++++-------- 5 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/Message/Request/RefundRequest.php b/src/Message/Request/RefundRequest.php index face214..58bec51 100755 --- a/src/Message/Request/RefundRequest.php +++ b/src/Message/Request/RefundRequest.php @@ -3,6 +3,7 @@ namespace Omnipay\Mollie\Message\Request; +use function is_string; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Message\ResponseInterface; use Omnipay\Mollie\Message\Response\RefundResponse; @@ -21,11 +22,17 @@ class RefundRequest extends AbstractMollieRequest */ public function getData() { - $this->validate('apiKey', 'transactionReference'); + $this->validate('apiKey', 'transactionReference', 'amount', 'currency'); $data = []; - if ($this->getAmountInteger() > 0) { - $data['amount'] = $this->getAmount(); + + $data['amount'] = [ + "value" => $this->getAmount(), + "currency" => $this->getCurrency() + ]; + + if(is_string($this->getParameter('description'))) { + $data['description'] = $this->getParameter('description'); } return $data; diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index ea0e4cb..43bea45 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -146,8 +146,29 @@ public function getStatus() */ public function getAmount() { - if (isset($this->data['amount'])) { - return $this->data['amount']; + if (is_array($this->data['amount'])) { + /** + * $this->data['amount'] = [ + * "currency" => "EUR", + * "value" => "50", + * ] + */ + return $this->data['amount']['value']; + } + + return null; + } + + public function getCurrency() + { + if (is_array($this->data['amount'])) { + /** + * $this->data['amount'] = [ + * "currency" => "EUR", + * "value" => "50", + * ] + */ + return $this->data['amount']['currency']; } return null; diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 254a4d6..7633261 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -72,25 +72,37 @@ public function testRefund() $request = $this->gateway->refund( array( 'apiKey' => 'key', - 'transactionReference' => 'tr_Qzin4iTWrU' + 'transactionReference' => 'tr_Qzin4iTWrU', + 'amount' => '10.00', + 'currency' => 'EUR' ) ); $this->assertInstanceOf(RefundRequest::class, $request); $data = $request->getData(); - $this->assertFalse(array_key_exists('amount', $data)); + $this->assertSame( + [ + 'value' => '10.00', + 'currency' => 'EUR' + ], + $data['amount'] + ); + } + + /** + * @expectedException \Omnipay\Common\Exception\InvalidRequestException + */ + public function testThatRefundDoesntWorkWithoutAmount() + { $request = $this->gateway->refund( array( 'apiKey' => 'key', - 'transactionReference' => 'tr_Qzin4iTWrU', - 'amount' => '10.00', - 'currency' => 'EUR' + 'transactionReference' => 'tr_Qzin4iTWrU' ) ); $this->assertInstanceOf(RefundRequest::class, $request); - $data = $request->getData(); - $this->assertSame('10.00', $data['amount']); + $request->getData(); } public function testFetchTransaction() diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php index 979abb5..47c9176 100644 --- a/tests/Message/FetchTransactionRequestTest.php +++ b/tests/Message/FetchTransactionRequestTest.php @@ -64,7 +64,7 @@ public function testSendSuccess() $this->assertFalse($response->isPartialRefunded()); $this->assertSame("paid", $response->getStatus()); $this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference()); - $this->assertSame(["value" => "10.00", "currency" => "EUR"], $response->getAmount()); + $this->assertSame("10.00", $response->getAmount()); } public function testSendExpired() diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php index ff037e1..7ba7d8d 100644 --- a/tests/Message/RefundRequestTest.php +++ b/tests/Message/RefundRequestTest.php @@ -19,12 +19,12 @@ class RefundRequestTest extends TestCase public function setUp() { $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); - $this->request->initialize( - array( - 'apiKey' => 'mykey', - 'transactionReference' => 'tr_WDqYK6vllg' - ) - ); + $this->request->initialize([ + 'apiKey' => 'mykey', + 'transactionReference' => 'tr_WDqYK6vllg', + 'amount' => '12.00', + 'currency' => 'EUR', + ]); } /** @@ -32,30 +32,29 @@ public function setUp() */ public function testGetData() { - $this->request->initialize( - array( - 'apiKey' => 'mykey', - 'amount' => '12.00', - 'transactionReference' => 'tr_WDqYK6vllg' - ) - ); + $this->request->initialize([ + 'apiKey' => 'mykey', + 'amount' => '12.00', + 'currency' => 'EUR', + 'transactionReference' => 'tr_WDqYK6vllg' + ]); $data = $this->request->getData(); - $this->assertSame("12.00", $data['amount']); + $this->assertSame(["value" => "12.00", "currency" => "EUR"], $data['amount']); $this->assertCount(1, $data); } /** - * @throws \Omnipay\Common\Exception\InvalidRequestException + * @expectedException \Omnipay\Common\Exception\InvalidRequestException */ public function testGetDataWithoutAmount() { $this->request->initialize( - array( + [ 'apiKey' => 'mykey', - 'transactionReference' => 'tr_WDqYK6vllg' - ) + 'transactionReference' => 'tr_WDqYK6vllg', + ] ); $data = $this->request->getData(); @@ -70,7 +69,12 @@ public function testSendSuccess() $response = $this->request->send(); $this->assertEqualRequest( - new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + new Request( + "POST", + "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", + [], + '{"amount":{"value":"12.00","currency":"EUR"}}' + ), $this->getMockClient()->getLastRequest() ); @@ -89,7 +93,7 @@ public function test401Failure() $response = $this->request->send(); $this->assertEqualRequest( - new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], ''), $this->getMockClient()->getLastRequest() ); @@ -105,7 +109,12 @@ public function test422Failure() $response = $this->request->send(); $this->assertEqualRequest( - new Request("POST", "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", [], '{}'), + new Request( + "POST", + "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds", + [], + '{"amount":{"value":"12.00","currency":"EUR"}}' + ), $this->getMockClient()->getLastRequest() ); From 2cd141ee4cb25d1d2a5ee7a481329d237a6e5d04 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Mon, 23 Jul 2018 09:16:55 +0200 Subject: [PATCH 21/25] Code style --- src/Message/Request/RefundRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/Request/RefundRequest.php b/src/Message/Request/RefundRequest.php index 58bec51..31e791b 100755 --- a/src/Message/Request/RefundRequest.php +++ b/src/Message/Request/RefundRequest.php @@ -31,7 +31,7 @@ public function getData() "currency" => $this->getCurrency() ]; - if(is_string($this->getParameter('description'))) { + if (is_string($this->getParameter('description'))) { $data['description'] = $this->getParameter('description'); } From 3b21459f13ceb828ff228dfc2a11fafb0908260f Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Mon, 23 Jul 2018 10:31:51 +0200 Subject: [PATCH 22/25] Fix failing test --- src/Message/Response/FetchTransactionResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php index 43bea45..56d5598 100644 --- a/src/Message/Response/FetchTransactionResponse.php +++ b/src/Message/Response/FetchTransactionResponse.php @@ -146,7 +146,7 @@ public function getStatus() */ public function getAmount() { - if (is_array($this->data['amount'])) { + if ($this->isSuccessful() && is_array($this->data['amount'])) { /** * $this->data['amount'] = [ * "currency" => "EUR", @@ -161,7 +161,7 @@ public function getAmount() public function getCurrency() { - if (is_array($this->data['amount'])) { + if ($this->isSuccessful() && is_array($this->data['amount'])) { /** * $this->data['amount'] = [ * "currency" => "EUR", From 7a58a27493109b4dc3f6be4344c23fedbbdab1df Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Mon, 23 Jul 2018 13:55:56 +0200 Subject: [PATCH 23/25] Versions for dev libs and some code styling --- composer.json | 10 ++++---- src/Gateway.php | 64 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index ff5df72..274c9de 100755 --- a/composer.json +++ b/composer.json @@ -33,19 +33,19 @@ "psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" } }, "require": { - "omnipay/common": "^3" + "omnipay/common": "^3.0.2" }, "require-dev": { "omnipay/tests": "^3", "squizlabs/php_codesniffer": "^3", "phpro/grumphp": "^0.14", - "phpmd/phpmd": "@stable", - "overtrue/phplint": "@stable", - "jakub-onderka/php-parallel-lint": "@stable" + "phpmd/phpmd": "^2", + "overtrue/phplint": "^1", + "jakub-onderka/php-parallel-lint": "^0" }, "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "5.0.x-dev" } }, "scripts": { diff --git a/src/Gateway.php b/src/Gateway.php index e39bfdd..93a9fd3 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -3,7 +3,6 @@ namespace Omnipay\Mollie; use Omnipay\Common\AbstractGateway; -use Omnipay\Common\Message\AbstractRequest; use Omnipay\Common\Message\RequestInterface; use Omnipay\Mollie\Message\Request\CompletePurchaseRequest; use Omnipay\Mollie\Message\Request\CreateCustomerRequest; @@ -69,82 +68,109 @@ public function setApiKey($value) /** * @param array $parameters - * @return AbstractRequest|FetchIssuersRequest + * @return FetchIssuersRequest */ public function fetchIssuers(array $parameters = []) { - return $this->createRequest(FetchIssuersRequest::class, $parameters); + /** @var FetchIssuersRequest $request */ + $request = $this->createRequest(FetchIssuersRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|FetchPaymentMethodsRequest + * @return FetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = []) { - return $this->createRequest(FetchPaymentMethodsRequest::class, $parameters); + /** @var FetchPaymentMethodsRequest $request */ + $request = $this->createRequest(FetchPaymentMethodsRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|FetchTransactionRequest + * @return FetchTransactionRequest */ public function fetchTransaction(array $parameters = []) { - return $this->createRequest(FetchTransactionRequest::class, $parameters); + /** @var FetchTransactionRequest $request */ + $request = $this->createRequest(FetchTransactionRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|PurchaseRequest + * @return PurchaseRequest */ public function purchase(array $parameters = []) { - return $this->createRequest(PurchaseRequest::class, $parameters); + /** @var PurchaseRequest $request */ + $request = $this->createRequest(PurchaseRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|CompletePurchaseRequest + * @return CompletePurchaseRequest */ public function completePurchase(array $parameters = []) { - return $this->createRequest(CompletePurchaseRequest::class, $parameters); + /** @var CompletePurchaseRequest $request */ + $request = $this->createRequest(CompletePurchaseRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|RefundRequest + * @return RefundRequest */ public function refund(array $parameters = []) { - return $this->createRequest(RefundRequest::class, $parameters); + /** @var RefundRequest $request */ + $request = $this->createRequest(RefundRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest + * @return CreateCustomerRequest */ public function createCustomer(array $parameters = []) { - return $this->createRequest(CreateCustomerRequest::class, $parameters); + /** @var CreateCustomerRequest $request */ + $request = $this->createRequest(CreateCustomerRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|UpdateCustomerRequest + * @return UpdateCustomerRequest */ public function updateCustomer(array $parameters = []) { - return $this->createRequest(UpdateCustomerRequest::class, $parameters); + /** @var UpdateCustomerRequest $request */ + $request = $this->createRequest(UpdateCustomerRequest::class, $parameters); + + return $request; } /** * @param array $parameters - * @return AbstractRequest|FetchCustomerRequest + * @return FetchCustomerRequest */ public function fetchCustomer(array $parameters = []) { - return $this->createRequest(FetchCustomerRequest::class, $parameters); + /** @var FetchCustomerRequest $request */ + $request = $this->createRequest(FetchCustomerRequest::class, $parameters); + + return $request; } } From 5bcc673b30dea1683b33b75d060b1a3305c36a96 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Mon, 23 Jul 2018 14:29:55 +0200 Subject: [PATCH 24/25] Versions update --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 274c9de..cc7f994 100755 --- a/composer.json +++ b/composer.json @@ -33,15 +33,15 @@ "psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" } }, "require": { - "omnipay/common": "^3.0.2" + "omnipay/common": "^3" }, "require-dev": { - "omnipay/tests": "^3", + "omnipay/tests": "^3.1", "squizlabs/php_codesniffer": "^3", "phpro/grumphp": "^0.14", "phpmd/phpmd": "^2", "overtrue/phplint": "^1", - "jakub-onderka/php-parallel-lint": "^0" + "jakub-onderka/php-parallel-lint": "^1" }, "extra": { "branch-alias": { From 5058ad7d47f78b5fe61e74fdb9d9ceacbae52ae4 Mon Sep 17 00:00:00 2001 From: Igor Budasov Date: Mon, 23 Jul 2018 14:52:04 +0200 Subject: [PATCH 25/25] Versions update for omnipay/common --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cc7f994..117e2b9 100755 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" } }, "require": { - "omnipay/common": "^3" + "omnipay/common": "3.0.2" }, "require-dev": { "omnipay/tests": "^3.1",