diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..665cb9d
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: [barryvdh]
\ No newline at end of file
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
new file mode 100644
index 0000000..4a0b3ba
--- /dev/null
+++ b/.github/workflows/run-tests.yml
@@ -0,0 +1,39 @@
+name: Test
+
+on: push
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ php: [ 8.0, 7.4, 7.2 ]
+
+ name: PHP-${{ matrix.php }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ coverage: none
+
+ - name: Cache Dependencies
+ uses: actions/cache@v2
+ with:
+ path: ~/.composer/cache
+ key: php-${{ matrix.php}}-composer-${{ hashFiles('**/composer.json') }}
+ restore-keys: php-${{ matrix.php}}-composer-
+
+ - name: Install Dependencies
+ run: composer install --no-interaction --no-ansi --no-progress
+
+ - name: Coding Standard
+ run: vendor/bin/phpcs --exclude=SlevomatCodingStandard.TypeHints.ReturnTypeHint,SlevomatCodingStandard.TypeHints.DeclareStrictTypes,SlevomatCodingStandard.Operators.DisallowEqualOperators,SlevomatCodingStandard.TypeHints.ParameterTypeHint,Generic.Files.LineLength,SlevomatCodingStandard.Classes.SuperfluousTraitNaming,SlevomatCodingStandard.TypeHints.PropertyTypeHint,SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming,Squiz.Strings.DoubleQuoteUsage,Squiz.Commenting.FunctionComment
+
+ - name: Execute Unit Tests
+ run: composer test
diff --git a/.gitignore b/.gitignore
index a00f07e..4d34a48 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,6 @@ composer.lock
composer.phar
phpunit.xml
/.idea
+.DS_Store
+.phpunit.result.cache
+.phpcs-cache
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100755
index 16716b0..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-language: php
-
-php:
- - 5.6
- - 7.0
- - 7.1
- - 7.2
-
-# This triggers builds to run on the new TravisCI infrastructure.
-# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
-sudo: false
-
-## Cache composer
-cache:
- directories:
- - $HOME/.composer/cache
-
-env:
- global:
- - setup=basic
-
-matrix:
- include:
- - php: 5.6
- env: setup=lowest
-
-install:
- - if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi
- - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
-
-script:
-- composer validate --strict
-- vendor/bin/phpcs --standard=PSR2 src
-- vendor/bin/phpunit --coverage-text
diff --git a/README.md b/README.md
index 24489de..626634a 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
**Mollie driver for the Omnipay PHP payment processing library**
-[![Build Status](https://travis-ci.org/thephpleague/omnipay-mollie.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-mollie)
+[![Unit Tests](https://github.com/thephpleague/omnipay-mollie/actions/workflows/run-tests.yml/badge.svg)](https://github.com/thephpleague/omnipay-mollie/actions/workflows/run-tests.yml)
[![Latest Stable Version](https://poser.pugx.org/omnipay/mollie/version.png)](https://packagist.org/packages/omnipay/mollie)
[![Total Downloads](https://poser.pugx.org/omnipay/mollie/d/total.png)](https://packagist.org/packages/omnipay/mollie)
@@ -189,7 +189,7 @@ If you are having general issues with Omnipay, we suggest posting on
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
-If you want to keep up to date with release anouncements, discuss ideas for the project,
+If you want to keep up to date with release announcements, discuss ideas for the project,
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
you can subscribe to.
diff --git a/composer.json b/composer.json
index 4a351d5..dcb9eca 100755
--- a/composer.json
+++ b/composer.json
@@ -33,19 +33,17 @@
"psr-4": { "Omnipay\\Mollie\\Test\\": "tests/" }
},
"require": {
- "omnipay/common": "^3.0.1"
+ "php": "^7.2|^8.0",
+ "omnipay/common": "^3.1"
},
"require-dev": {
- "omnipay/tests": "^3.1",
- "squizlabs/php_codesniffer": "^3",
- "phpro/grumphp": "^0.14",
- "phpmd/phpmd": "^2",
- "overtrue/phplint": "^1",
- "jakub-onderka/php-parallel-lint": "^1"
+ "omnipay/tests": "^4.1",
+ "vimeo/psalm": "^4.10",
+ "myonlinestore/coding-standard": "^3.1"
},
"extra": {
"branch-alias": {
- "dev-master": "5.1.x-dev"
+ "dev-master": "5.4.x-dev"
}
},
"scripts": {
diff --git a/grumphp.yml b/grumphp.yml
deleted file mode 100644
index d643001..0000000
--- a/grumphp.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-parameters:
- git_dir: .
- bin_dir: vendor/bin
- tasks:
- phpunit:
- config_file: ~
- testsuite: ~
- group: []
- always_execute: false
- phpcs:
- standard: PSR2
- warning_severity: ~
- ignore_patterns:
- - tests/
- 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
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 0000000..d773b99
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+ src
+ tests
+
+
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 535809e..126591a 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,5 +1,6 @@
-
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
+>
./tests/
+
-
- ./src
+
+ src
diff --git a/psalm.xml.dist b/psalm.xml.dist
new file mode 100644
index 0000000..0a6f64d
--- /dev/null
+++ b/psalm.xml.dist
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Gateway.php b/src/Gateway.php
index 4dcba4b..72a1d6e 100644
--- a/src/Gateway.php
+++ b/src/Gateway.php
@@ -16,6 +16,7 @@
use Omnipay\Mollie\Message\Request\FetchIssuersRequest;
use Omnipay\Mollie\Message\Request\FetchOrderRequest;
use Omnipay\Mollie\Message\Request\FetchPaymentMethodsRequest;
+use Omnipay\Mollie\Message\Request\FetchProfileRequest;
use Omnipay\Mollie\Message\Request\FetchTransactionRequest;
use Omnipay\Mollie\Message\Request\PurchaseRequest;
use Omnipay\Mollie\Message\Request\RefundRequest;
@@ -43,7 +44,7 @@ class Gateway extends AbstractGateway
/**
* Version of our gateway.
*/
- const GATEWAY_VERSION = "5.2";
+ public const GATEWAY_VERSION = '5.2';
/**
* @return string
@@ -58,9 +59,9 @@ public function getName()
*/
public function getDefaultParameters()
{
- return array(
+ return [
'apiKey' => '',
- );
+ ];
}
/**
@@ -73,6 +74,7 @@ public function getApiKey()
/**
* @param string $value
+ *
* @return $this
*/
public function setApiKey($value)
@@ -90,6 +92,7 @@ public function getVersionStrings()
/**
* @param string $value
+ *
* @return $this
*/
public function setVersionStrings(array $values)
@@ -99,176 +102,189 @@ public function setVersionStrings(array $values)
/**
* @param string $value
+ *
* @return $this
*/
public function addVersionString($value)
{
$versionStrings = $this->getVersionStrings() ?: [];
- $versionStrings[] = str_replace([" ", "\t", "\n", "\r"], '-', $value);
+ $versionStrings[] = \str_replace([' ', "\t", "\n", "\r"], '-', $value);
return $this->setVersionStrings($versionStrings);
}
/**
* @param array $parameters
+ *
* @return FetchIssuersRequest
*/
public function fetchIssuers(array $parameters = [])
{
- /** @var FetchIssuersRequest $request */
$request = $this->createRequest(FetchIssuersRequest::class, $parameters);
+ \assert($request instanceof FetchIssuersRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return FetchPaymentMethodsRequest
*/
public function fetchPaymentMethods(array $parameters = [])
{
- /** @var FetchPaymentMethodsRequest $request */
$request = $this->createRequest(FetchPaymentMethodsRequest::class, $parameters);
+ \assert($request instanceof FetchPaymentMethodsRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return FetchTransactionRequest
*/
public function fetchTransaction(array $parameters = [])
{
- /** @var FetchTransactionRequest $request */
$request = $this->createRequest(FetchTransactionRequest::class, $parameters);
+ \assert($request instanceof FetchTransactionRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return PurchaseRequest
*/
public function purchase(array $parameters = [])
{
- /** @var PurchaseRequest $request */
$request = $this->createRequest(PurchaseRequest::class, $parameters);
+ \assert($request instanceof PurchaseRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return CompletePurchaseRequest
*/
public function completePurchase(array $parameters = [])
{
- /** @var CompletePurchaseRequest $request */
$request = $this->createRequest(CompletePurchaseRequest::class, $parameters);
+ \assert($request instanceof CompletePurchaseRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return RefundRequest
*/
public function refund(array $parameters = [])
{
- /** @var RefundRequest $request */
$request = $this->createRequest(RefundRequest::class, $parameters);
+ \assert($request instanceof RefundRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return CreateOrderRequest
*/
public function createOrder(array $parameters = [])
{
- /** @var CreateOrderRequest $request */
$request = $this->createRequest(CreateOrderRequest::class, $parameters);
+ \assert($request instanceof CreateOrderRequest);
return $request;
}
-
/**
* @param array $parameters
+ *
* @return FetchOrderRequest
*/
public function fetchOrder(array $parameters = [])
{
- /** @var FetchOrderRequest $request */
$request = $this->createRequest(FetchOrderRequest::class, $parameters);
+ \assert($request instanceof FetchOrderRequest);
return $request;
}
-
/**
* @param array $parameters
+ *
* @return CompleteOrderRequest
*/
public function completeOrder(array $parameters = [])
{
- /** @var CompleteOrderRequest $request */
$request = $this->createRequest(CompleteOrderRequest::class, $parameters);
+ \assert($request instanceof CompleteOrderRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return CreateShipmentRequest
*/
public function createShipment(array $parameters = [])
{
- /** @var CreateShipmentRequest $request */
$request = $this->createRequest(CreateShipmentRequest::class, $parameters);
+ \assert($request instanceof CreateShipmentRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return CreateCustomerRequest
*/
public function createCustomer(array $parameters = [])
{
- /** @var CreateCustomerRequest $request */
$request = $this->createRequest(CreateCustomerRequest::class, $parameters);
+ \assert($request instanceof CreateCustomerRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return UpdateCustomerRequest
*/
public function updateCustomer(array $parameters = [])
{
- /** @var UpdateCustomerRequest $request */
$request = $this->createRequest(UpdateCustomerRequest::class, $parameters);
+ \assert($request instanceof UpdateCustomerRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return FetchCustomerRequest
*/
public function fetchCustomer(array $parameters = [])
{
- /** @var FetchCustomerRequest $request */
$request = $this->createRequest(FetchCustomerRequest::class, $parameters);
+ \assert($request instanceof FetchCustomerRequest);
return $request;
}
/**
* @param array $parameters
+ *
* @return FetchCustomerMandatesRequest
*/
public function fetchCustomerMandates(array $parameters = [])
@@ -278,6 +294,7 @@ public function fetchCustomerMandates(array $parameters = [])
/**
* @param array $parameters
+ *
* @return CreateCustomerMandateRequest
*/
public function createCustomerMandate(array $parameters = [])
@@ -287,6 +304,7 @@ public function createCustomerMandate(array $parameters = [])
/**
* @param array $parameters
+ *
* @return RevokeCustomerMandateRequest
*/
public function revokeCustomerMandate(array $parameters = [])
@@ -294,8 +312,17 @@ public function revokeCustomerMandate(array $parameters = [])
return $this->createRequest(RevokeCustomerMandateRequest::class, $parameters);
}
+ /**
+ * @param array $parameters
+ */
+ public function fetchProfile(array $parameters = []): FetchProfileRequest
+ {
+ return $this->createRequest(FetchProfileRequest::class, $parameters);
+ }
+
/**
* @param array $parameters
+ *
* @return CancelOrderRequest
*/
public function void(array $parameters = [])
diff --git a/src/Item.php b/src/Item.php
index 64802a6..fc21541 100644
--- a/src/Item.php
+++ b/src/Item.php
@@ -9,11 +9,12 @@ class Item extends \Omnipay\Common\Item
*
* @param $key
* @param $value
+ *
* @return $this
*/
protected function setParameter($key, $value)
{
- if (is_array($value) && isset($value['value'])) {
+ if (\is_array($value) && isset($value['value'])) {
$value = $value['value'];
}
@@ -142,7 +143,6 @@ public function setStatus($value)
return $this->setParameter('status', $value);
}
-
public function getIsCancelable()
{
return $this->getParameter('isCancelable');
diff --git a/src/Message/Request/AbstractMollieRequest.php b/src/Message/Request/AbstractMollieRequest.php
index 780bb78..f89b9e6 100755
--- a/src/Message/Request/AbstractMollieRequest.php
+++ b/src/Message/Request/AbstractMollieRequest.php
@@ -2,7 +2,6 @@
namespace Omnipay\Mollie\Message\Request;
-use Omnipay\Common\ItemBag;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Mollie\Gateway;
use Omnipay\Mollie\Item;
@@ -14,18 +13,14 @@
*/
abstract class AbstractMollieRequest extends AbstractRequest
{
- const POST = 'POST';
- const GET = 'GET';
- const DELETE = 'DELETE';
+ public const POST = 'POST';
+ public const GET = 'GET';
+ public const DELETE = 'DELETE';
- /**
- * @var string
- */
- protected $apiVersion = "v2";
+ /** @var string */
+ protected $apiVersion = 'v2';
- /**
- * @var string
- */
+ /** @var string */
protected $baseUrl = 'https://api.mollie.com/';
/**
@@ -38,6 +33,7 @@ public function getApiKey()
/**
* @param string $value
+ *
* @return $this
*/
public function setApiKey($value)
@@ -45,6 +41,16 @@ public function setApiKey($value)
return $this->setParameter('apiKey', $value);
}
+ public function getCardToken(): ?string
+ {
+ return $this->getParameter('cardToken');
+ }
+
+ public function setCardToken(string $cardToken): self
+ {
+ return $this->setParameter('cardToken', $cardToken);
+ }
+
/**
* @return array|null
*/
@@ -55,6 +61,7 @@ public function getVersionStrings()
/**
* @param string $value
+ *
* @return $this
*/
public function setVersionStrings(array $values)
@@ -63,8 +70,7 @@ public function setVersionStrings(array $values)
}
/**
- * @param string $value
- * @return $this
+ * @inheritDoc
*/
public function setTransactionId($value)
{
@@ -72,7 +78,7 @@ public function setTransactionId($value)
}
/**
- * @return string
+ * @inheritDoc
*/
public function getTransactionId()
{
@@ -83,13 +89,14 @@ public function getTransactionId()
* Set the items in this order
*
* @param Item[] $items An array of items in this order
+ *
* @return $this
*/
public function setItems($items)
{
$orderItems = [];
foreach ($items as $item) {
- if (is_array($item)) {
+ if (\is_array($item)) {
$orderItems[] = new Item($item);
} elseif (! ($item instanceof Item)) {
throw new \InvalidArgumentException('Item should be an instance of ' . Item::class);
@@ -102,41 +109,37 @@ public function setItems($items)
/**
* @param string $method
* @param string $endpoint
- * @param array $data
+ * @param array $data
+ *
* @return array
*/
- protected function sendRequest($method, $endpoint, array $data = null)
+ protected function sendRequest($method, $endpoint, ?array $data = null)
{
$versions = [
'Omnipay-Mollie/' . Gateway::GATEWAY_VERSION,
- 'PHP/' . phpversion(),
];
if ($customVersions = $this->getParameter('versionStrings')) {
- $versions = array_merge($versions, $customVersions);
+ $versions = \array_merge($versions, $customVersions);
}
$headers = [
- 'Accept' => "application/json",
+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->getApiKey(),
- 'User-Agent' => implode(' ', $versions),
+ 'User-Agent' => \implode(' ', $versions),
];
- if (function_exists("php_uname")) {
- $headers['X-Mollie-Client-Info'] = php_uname();
- }
-
$response = $this->httpClient->request(
$method,
$this->baseUrl . $this->apiVersion . $endpoint,
$headers,
- ($data === null || $data === []) ? null : json_encode($data)
+ null === $data || [] === $data ? null : \json_encode($data)
);
- return json_decode($response->getBody(), true);
+ return \json_decode($response->getBody(), true);
}
-
protected function createAmountObject($amount)
{
return isset($amount) ? [
diff --git a/src/Message/Request/CancelOrderRequest.php b/src/Message/Request/CancelOrderRequest.php
index aea7915..bbf7039 100755
--- a/src/Message/Request/CancelOrderRequest.php
+++ b/src/Message/Request/CancelOrderRequest.php
@@ -8,6 +8,7 @@
* Cancel an order with the Mollie API.
*
* @see https://docs.mollie.com/reference/v2/orders-api/cancel-order
+ *
* @method CancelOrderResponse send()
*/
final class CancelOrderRequest extends AbstractMollieRequest
@@ -29,7 +30,7 @@ public function sendData($data)
{
return $this->response = new CancelOrderResponse(
$this,
- $this->sendRequest(self::DELETE, '/orders/'.$this->getTransactionReference(), $data)
+ $this->sendRequest(self::DELETE, '/orders/' . $this->getTransactionReference(), $data)
);
}
}
diff --git a/src/Message/Request/CompleteOrderRequest.php b/src/Message/Request/CompleteOrderRequest.php
index 394338e..4ad118d 100755
--- a/src/Message/Request/CompleteOrderRequest.php
+++ b/src/Message/Request/CompleteOrderRequest.php
@@ -9,12 +9,14 @@
* Retrieve a single order object by its payment token.
*
* @see https://docs.mollie.com/reference/v2/payments-api/get-order
+ *
* @method CompleteOrderResponse send()
*/
class CompleteOrderRequest extends FetchOrderRequest
{
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -29,7 +31,7 @@ public function getData()
}
if (empty($data['id'])) {
- throw new InvalidRequestException("The transactionReference parameter is required");
+ throw new InvalidRequestException('The transactionReference parameter is required');
}
return $data;
@@ -37,6 +39,7 @@ public function getData()
/**
* @param array $data
+ *
* @return CompleteOrderResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/CompletePurchaseRequest.php b/src/Message/Request/CompletePurchaseRequest.php
index 2c99e87..bb54a3c 100755
--- a/src/Message/Request/CompletePurchaseRequest.php
+++ b/src/Message/Request/CompletePurchaseRequest.php
@@ -9,12 +9,14 @@
* Retrieve a single payment object by its payment token.
*
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment
+ *
* @method CompletePurchaseResponse send()
*/
class CompletePurchaseRequest extends FetchTransactionRequest
{
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -29,7 +31,7 @@ public function getData()
}
if (empty($data['id'])) {
- throw new InvalidRequestException("The transactionReference parameter is required");
+ throw new InvalidRequestException('The transactionReference parameter is required');
}
return $data;
@@ -37,6 +39,7 @@ public function getData()
/**
* @param array $data
+ *
* @return CompletePurchaseResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/CreateCustomerMandateRequest.php b/src/Message/Request/CreateCustomerMandateRequest.php
index 36374c0..c684415 100644
--- a/src/Message/Request/CreateCustomerMandateRequest.php
+++ b/src/Message/Request/CreateCustomerMandateRequest.php
@@ -10,6 +10,7 @@
* Create a mandate for a specific customer.
*
* @see https://docs.mollie.com/reference/v2/mandates-api/create-mandate
+ *
* @method CreateCustomerMandateResponse send()
*/
class CreateCustomerMandateRequest extends AbstractMollieRequest
@@ -24,6 +25,7 @@ public function getMethod()
/**
* @param string $method
+ *
* @return AbstractRequest
*/
public function setMethod($method)
@@ -41,6 +43,7 @@ public function getConsumerName()
/**
* @param string $consumerName
+ *
* @return AbstractRequest
*/
public function setConsumerName($consumerName)
@@ -58,6 +61,7 @@ public function getConsumerAccount()
/**
* @param string $consumerAccount
+ *
* @return AbstractRequest
*/
public function setConsumerAccount($consumerAccount)
@@ -75,6 +79,7 @@ public function getConsumerBic()
/**
* @param string $consumerBic
+ *
* @return AbstractRequest
*/
public function setConsumerBic($consumerBic)
@@ -92,6 +97,7 @@ public function getSignatureDate()
/**
* @param string $signatureDate
+ *
* @return AbstractRequest
*/
public function setSignatureDate($signatureDate)
@@ -109,6 +115,7 @@ public function getMandateReference()
/**
* @param string $mandateReference
+ *
* @return AbstractRequest
*/
public function setMandateReference($mandateReference)
@@ -126,6 +133,7 @@ public function getCustomerReference()
/**
* @param string $customerReference
+ *
* @return AbstractRequest
*/
public function setCustomerReference($customerReference)
@@ -133,16 +141,16 @@ public function setCustomerReference($customerReference)
return $this->setParameter('customerReference', $customerReference);
}
-
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('apiKey', 'customerReference', 'method', 'consumerName', 'consumerAccount');
- $data = array();
+ $data = [];
$data['method'] = $this->getMethod();
$data['consumerName'] = $this->getConsumerName();
$data['consumerAccount'] = $this->getConsumerAccount();
@@ -164,6 +172,7 @@ public function getData()
/**
* @param array $data
+ *
* @return CreateCustomerMandateResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/CreateCustomerRequest.php b/src/Message/Request/CreateCustomerRequest.php
index 73959a9..e9ea46b 100755
--- a/src/Message/Request/CreateCustomerRequest.php
+++ b/src/Message/Request/CreateCustomerRequest.php
@@ -10,6 +10,7 @@
* Creates a simple minimal representation of a customer in the Mollie API.
*
* @see https://docs.mollie.com/reference/v2/customers-api/create-customer
+ *
* @method CreateCustomerResponse send()
*/
class CreateCustomerRequest extends AbstractMollieRequest
@@ -26,6 +27,7 @@ public function getEmail()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setEmail($value)
@@ -49,6 +51,7 @@ public function getLocale()
* Optional value.
*
* @param string $value
+ *
* @return AbstractRequest
*/
public function setLocale($value)
@@ -70,6 +73,7 @@ public function getMetadata()
* Optional value.
*
* @param array $value
+ *
* @return AbstractRequest
*/
public function setMetadata($value)
@@ -79,6 +83,7 @@ public function setMetadata($value)
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -99,6 +104,7 @@ public function getData()
/**
* @param array $data
+ *
* @return CreateCustomerResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/CreateOrderRequest.php b/src/Message/Request/CreateOrderRequest.php
index 3f66b89..0a0afc6 100755
--- a/src/Message/Request/CreateOrderRequest.php
+++ b/src/Message/Request/CreateOrderRequest.php
@@ -5,7 +5,6 @@
use Omnipay\Common\CreditCard;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\ItemBag;
-use Omnipay\Common\Message\ResponseInterface;
use Omnipay\Mollie\Item;
use Omnipay\Mollie\Message\Response\CreateOrderResponse;
use Omnipay\Mollie\Message\Response\PurchaseResponse;
@@ -14,6 +13,7 @@
* Create an order with the Mollie API.
*
* @see https://docs.mollie.com/reference/v2/orders-api/create-order
+ *
* @method CreateOrderResponse send()
*/
class CreateOrderRequest extends AbstractMollieRequest
@@ -35,6 +35,7 @@ public function getMetadata()
/**
* @param array $value
+ *
* @return $this
*/
public function setMetadata(array $value)
@@ -52,6 +53,7 @@ public function getLocale()
/**
* @param string $value
+ *
* @return $this
*/
public function setLocale($value)
@@ -69,6 +71,7 @@ public function getOrderNumber()
/**
* @param string $value
+ *
* @return $this
*/
public function setOrderNumber($value)
@@ -86,6 +89,7 @@ public function getBillingEmail()
/**
* @param string $value
+ *
* @return $this
*/
public function setBillingEmail($value)
@@ -103,6 +107,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return $this
*/
public function setCustomerReference($value)
@@ -120,6 +125,7 @@ public function getSequenceType()
/**
* @param string $value
+ *
* @return $this
*/
public function setSequenceType($value)
@@ -131,6 +137,7 @@ public function setSequenceType($value)
* Alias for lines
*
* @param $items
+ *
* @return $this
*/
public function setLines($items)
@@ -150,6 +157,7 @@ public function getItems()
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -159,7 +167,7 @@ public function getData()
$data = [];
$data['amount'] = [
'value' => $this->getAmount(),
- 'currency' => $this->getCurrency()
+ 'currency' => $this->getCurrency(),
];
if ($card = $this->getCard()) {
@@ -199,14 +207,18 @@ public function getData()
$data['payment']['sequenceType'] = $sequenceType;
}
- return array_filter($data);
+ if ($cardToken = $this->getCardToken()) {
+ $data['payment']['cardToken'] = $cardToken;
+ }
+
+ return \array_filter($data);
}
protected function getCardData(CreditCard $card)
{
$data = [];
- $data['billingAddress'] = array_filter([
+ $data['billingAddress'] = \array_filter([
'organizationName' => $card->getCompany(),
'streetAndNumber' => $card->getAddress1(),
'streetAdditional' => $card->getAddress2(),
@@ -222,7 +234,7 @@ protected function getCardData(CreditCard $card)
]);
if ($card->getShippingAddress1()) {
- $data['shippingAddress'] = array_filter([
+ $data['shippingAddress'] = \array_filter([
'organizationName' => $card->getCompany(),
'streetAndNumber' => $card->getShippingAddress1(),
'streetAdditional' => $card->getShippingAddress2(),
@@ -254,7 +266,7 @@ protected function getLines(ItemBag $items)
}
if (null === $vatAmount) {
- $vatAmount = round($totalAmount * ($vatRate / (100 + $vatRate)), $this->getCurrencyDecimalPlaces());
+ $vatAmount = \round($totalAmount * $vatRate / (100 + $vatRate), $this->getCurrencyDecimalPlaces());
}
$data = [
@@ -272,7 +284,7 @@ protected function getLines(ItemBag $items)
];
// Strip null values
- $lines[] = array_filter($data);
+ $lines[] = \array_filter($data);
}
return $lines;
@@ -280,7 +292,8 @@ protected function getLines(ItemBag $items)
/**
* @param array $data
- * @return ResponseInterface|PurchaseResponse
+ *
+ * @return PurchaseResponse
*/
public function sendData($data)
{
diff --git a/src/Message/Request/CreateShipmentRequest.php b/src/Message/Request/CreateShipmentRequest.php
index e109ebf..d63c77b 100755
--- a/src/Message/Request/CreateShipmentRequest.php
+++ b/src/Message/Request/CreateShipmentRequest.php
@@ -9,6 +9,7 @@
* Create a shipment with the Mollie API.
*
* @see https://docs.mollie.com/reference/v2/shipments-api/create-shipment
+ *
* @method CreateShipmentResponse send()
*/
class CreateShipmentRequest extends AbstractMollieRequest
@@ -23,6 +24,7 @@ public function getTracking()
/**
* @param array $value
+ *
* @return $this
*/
public function setTracking(array $value)
@@ -30,9 +32,9 @@ public function setTracking(array $value)
return $this->setParameter('tracking', $value);
}
-
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -44,7 +46,7 @@ public function getData()
if ($items = $this->getItems()) {
foreach ($items as $item) {
- $data['lines'][] = array_filter([
+ $data['lines'][] = \array_filter([
'id' => $item->getId(),
'quantity' => $item->getQuantity(),
]);
@@ -60,6 +62,7 @@ public function getData()
/**
* @param array $data
+ *
* @return CreateShipmentResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/FetchCustomerMandatesRequest.php b/src/Message/Request/FetchCustomerMandatesRequest.php
index 986f00e..2ae147b 100644
--- a/src/Message/Request/FetchCustomerMandatesRequest.php
+++ b/src/Message/Request/FetchCustomerMandatesRequest.php
@@ -10,6 +10,7 @@
* Retrieve all mandates for the given customer.
*
* @see https://docs.mollie.com/reference/v2/mandates-api/list-mandates
+ *
* @method FetchCustomerMandatesResponse send()
*/
class FetchCustomerMandatesRequest extends AbstractMollieRequest
@@ -24,6 +25,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setCustomerReference($value)
@@ -33,17 +35,19 @@ public function setCustomerReference($value)
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('apiKey', 'customerReference');
- return array();
+ return [];
}
/**
* @param array $data
+ *
* @return FetchCustomerMandatesResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/FetchCustomerRequest.php b/src/Message/Request/FetchCustomerRequest.php
index 18c9d1a..051f34f 100755
--- a/src/Message/Request/FetchCustomerRequest.php
+++ b/src/Message/Request/FetchCustomerRequest.php
@@ -10,6 +10,7 @@
* Retrieve a single customer by its ID.
*
* @see https://docs.mollie.com/reference/v2/customers-api/get-customer
+ *
* @method FetchCustomerResponse send()
*/
class FetchCustomerRequest extends AbstractMollieRequest
@@ -24,6 +25,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setCustomerReference($value)
@@ -33,6 +35,7 @@ public function setCustomerReference($value)
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -44,6 +47,7 @@ public function getData()
/**
* @param array $data
+ *
* @return FetchCustomerResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/FetchIssuersRequest.php b/src/Message/Request/FetchIssuersRequest.php
index 7550b6c..eb61984 100755
--- a/src/Message/Request/FetchIssuersRequest.php
+++ b/src/Message/Request/FetchIssuersRequest.php
@@ -4,12 +4,12 @@
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Mollie\Message\Response\FetchIssuersResponse;
-use Psr\Http\Message\ResponseInterface;
/**
* 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
@@ -24,6 +24,7 @@ class FetchIssuersRequest extends AbstractMollieRequest
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -35,9 +36,8 @@ public function getData()
/**
* @param array $data
- * @return ResponseInterface|FetchIssuersResponse
*/
- public function sendData($data)
+ public function sendData($data): FetchIssuersResponse
{
$response = $this->sendRequest(self::GET, $this->endpoint);
diff --git a/src/Message/Request/FetchOrderRequest.php b/src/Message/Request/FetchOrderRequest.php
index 52ec63c..7d3ae49 100755
--- a/src/Message/Request/FetchOrderRequest.php
+++ b/src/Message/Request/FetchOrderRequest.php
@@ -9,12 +9,14 @@
* Retrieve a single order object by its payment token.
*
* @see https://docs.mollie.com/reference/v2/payments-api/get-order
+ *
* @method FetchOrderResponse send()
*/
class FetchOrderRequest extends AbstractMollieRequest
{
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -37,6 +39,7 @@ public function hasIncludePayments()
/**
* @param array $data
+ *
* @return FetchOrderResponse
*/
public function sendData($data)
@@ -55,6 +58,7 @@ public function sendData($data)
/**
* @param bool $includePayments
+ *
* @return self
*/
public function setIncludePayments($includePayments)
diff --git a/src/Message/Request/FetchPaymentMethodsRequest.php b/src/Message/Request/FetchPaymentMethodsRequest.php
index b1f34e0..2db4992 100755
--- a/src/Message/Request/FetchPaymentMethodsRequest.php
+++ b/src/Message/Request/FetchPaymentMethodsRequest.php
@@ -3,19 +3,20 @@
namespace Omnipay\Mollie\Message\Request;
use Omnipay\Common\Exception\InvalidRequestException;
-use Omnipay\Common\Message\ResponseInterface;
use Omnipay\Mollie\Message\Response\FetchPaymentMethodsResponse;
/**
* Retrieve all available payment methods.
*
* @see https://docs.mollie.com/reference/v2/methods-api/list-methods
+ *
* @method FetchPaymentMethodsResponse send()
*/
class FetchPaymentMethodsRequest extends AbstractMollieRequest
{
/**
* @param string $billingCountry
+ *
* @return $this
*/
public function setBillingCountry($billingCountry)
@@ -33,6 +34,7 @@ public function getBillingCountry()
/**
* @param string $includeWallets
+ *
* @return $this
*/
public function setIncludeWallets($includeWallets)
@@ -50,6 +52,7 @@ public function getIncludeWallets()
/**
* @param string $locale
+ *
* @return $this
*/
public function setLocale($locale)
@@ -67,6 +70,7 @@ public function getLocale()
/**
* @param string $resource
+ *
* @return $this
*/
public function setResource($resource)
@@ -84,6 +88,7 @@ public function getResource()
/**
* @param $sequenceType
+ *
* @return $this
*/
public function setSequenceType($sequenceType)
@@ -101,6 +106,7 @@ public function getSequenceType()
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -130,11 +136,12 @@ public function getData()
/**
* @param array $data
- * @return ResponseInterface|FetchPaymentMethodsResponse
+ *
+ * @return FetchPaymentMethodsResponse
*/
public function sendData($data)
{
- $query = http_build_query($data);
+ $query = \http_build_query($data);
$response = $this->sendRequest(self::GET, '/methods' . ($query ? '?' . $query : ''));
return $this->response = new FetchPaymentMethodsResponse($this, $response);
diff --git a/src/Message/Request/FetchProfileRequest.php b/src/Message/Request/FetchProfileRequest.php
new file mode 100644
index 0000000..416f539
--- /dev/null
+++ b/src/Message/Request/FetchProfileRequest.php
@@ -0,0 +1,30 @@
+
+ *
+ * @throws InvalidRequestException
+ */
+ public function getData(): array
+ {
+ $this->validate('apiKey');
+
+ return [];
+ }
+
+ public function sendData($data): ResponseInterface
+ {
+ $response = $this->sendRequest(self::GET, '/profiles/me');
+
+ return new FetchProfileResponse($this, $response);
+ }
+}
diff --git a/src/Message/Request/FetchTransactionRequest.php b/src/Message/Request/FetchTransactionRequest.php
index 1042f7e..dc362be 100755
--- a/src/Message/Request/FetchTransactionRequest.php
+++ b/src/Message/Request/FetchTransactionRequest.php
@@ -3,19 +3,20 @@
namespace Omnipay\Mollie\Message\Request;
use Omnipay\Common\Exception\InvalidRequestException;
-use Omnipay\Common\Message\ResponseInterface;
use Omnipay\Mollie\Message\Response\FetchTransactionResponse;
/**
* 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
{
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -30,7 +31,8 @@ public function getData()
/**
* @param array $data
- * @return ResponseInterface|FetchTransactionResponse
+ *
+ * @return FetchTransactionResponse
*/
public function sendData($data)
{
diff --git a/src/Message/Request/PurchaseRequest.php b/src/Message/Request/PurchaseRequest.php
index 54f4f70..f56f202 100755
--- a/src/Message/Request/PurchaseRequest.php
+++ b/src/Message/Request/PurchaseRequest.php
@@ -3,13 +3,13 @@
namespace Omnipay\Mollie\Message\Request;
use Omnipay\Common\Exception\InvalidRequestException;
-use Omnipay\Common\Message\ResponseInterface;
use Omnipay\Mollie\Message\Response\PurchaseResponse;
/**
* 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
@@ -24,6 +24,7 @@ public function getMetadata()
/**
* @param array $value
+ *
* @return $this
*/
public function setMetadata(array $value)
@@ -41,6 +42,7 @@ public function getLocale()
/**
* @param string $value
+ *
* @return $this
*/
public function setLocale($value)
@@ -58,6 +60,7 @@ public function getBillingEmail()
/**
* @param string $value
+ *
* @return $this
*/
public function setBillingEmail($value)
@@ -75,6 +78,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return $this
*/
public function setCustomerReference($value)
@@ -82,6 +86,24 @@ public function setCustomerReference($value)
return $this->setParameter('customerReference', $value);
}
+ /**
+ * @return string
+ */
+ public function getMandateId()
+ {
+ return $this->getParameter('mandateId');
+ }
+
+ /**
+ * @param string $value
+ *
+ * @return $this
+ */
+ public function setMandateId($value)
+ {
+ return $this->setParameter('mandateId', $value);
+ }
+
/**
* @return string
*/
@@ -92,6 +114,7 @@ public function getSequenceType()
/**
* @param string $value
+ *
* @return $this
*/
public function setSequenceType($value)
@@ -99,8 +122,27 @@ public function setSequenceType($value)
return $this->setParameter('sequenceType', $value);
}
+ /**
+ * @return string
+ */
+ public function getInclude()
+ {
+ return $this->getParameter('include');
+ }
+
+ /**
+ * @param string $value
+ *
+ * @return $this
+ */
+ public function setInclude($value)
+ {
+ return $this->setParameter('include', $value);
+ }
+
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -109,8 +151,8 @@ public function getData()
$data = [];
$data['amount'] = [
- "value" => $this->getAmount(),
- "currency" => $this->getCurrency()
+ 'value' => $this->getAmount(),
+ 'currency' => $this->getCurrency(),
];
$data['description'] = $this->getDescription();
$data['redirectUrl'] = $this->getReturnUrl();
@@ -146,16 +188,31 @@ public function getData()
$data['sequenceType'] = $sequenceType;
}
+ if ($mandateId = $this->getMandateId()) {
+ $data['mandateId'] = $mandateId;
+ }
+
+ if ($cardToken = $this->getCardToken()) {
+ $data['cardToken'] = $cardToken;
+ }
+
return $data;
}
/**
* @param array $data
- * @return ResponseInterface|PurchaseResponse
+ *
+ * @return PurchaseResponse
*/
public function sendData($data)
{
- $response = $this->sendRequest(self::POST, '/payments', $data);
+ $endpoint = '/payments';
+
+ if ($include = $this->getInclude()) {
+ $endpoint .= '?include=' . $include;
+ }
+
+ $response = $this->sendRequest(self::POST, $endpoint, $data);
return $this->response = new PurchaseResponse($this, $response);
}
diff --git a/src/Message/Request/RefundRequest.php b/src/Message/Request/RefundRequest.php
index c0c94fe..15572ba 100755
--- a/src/Message/Request/RefundRequest.php
+++ b/src/Message/Request/RefundRequest.php
@@ -1,11 +1,8 @@
$this->getAmount(),
- "currency" => $this->getCurrency()
+ 'value' => $this->getAmount(),
+ 'currency' => $this->getCurrency(),
];
- if (is_string($this->getParameter('description'))) {
+ if (\is_string($this->getParameter('description'))) {
$data['description'] = $this->getParameter('description');
}
@@ -41,7 +40,8 @@ public function getData()
/**
* @param array $data
- * @return ResponseInterface|RefundResponse
+ *
+ * @return RefundResponse
*/
public function sendData($data)
{
diff --git a/src/Message/Request/RevokeCustomerMandateRequest.php b/src/Message/Request/RevokeCustomerMandateRequest.php
index e6de39b..3aa5359 100644
--- a/src/Message/Request/RevokeCustomerMandateRequest.php
+++ b/src/Message/Request/RevokeCustomerMandateRequest.php
@@ -10,6 +10,7 @@
* Revoke a customer's mandate.
*
* @see https://docs.mollie.com/reference/v2/mandates-api/revoke-mandate
+ *
* @method RevokeCustomerMandateResponse send()
*/
class RevokeCustomerMandateRequest extends AbstractMollieRequest
@@ -24,6 +25,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setCustomerReference($value)
@@ -41,6 +43,7 @@ public function getMandateId()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setMandateId($value)
@@ -50,6 +53,7 @@ public function setMandateId($value)
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -61,9 +65,10 @@ public function getData()
return $data;
}
-
+
/**
* @param array $data
+ *
* @return RevokeCustomerMandateResponse
*/
public function sendData($data)
diff --git a/src/Message/Request/UpdateCustomerRequest.php b/src/Message/Request/UpdateCustomerRequest.php
index 123aee1..a7b32ce 100755
--- a/src/Message/Request/UpdateCustomerRequest.php
+++ b/src/Message/Request/UpdateCustomerRequest.php
@@ -10,6 +10,7 @@
* Update an existing customer.
*
* @see https://docs.mollie.com/reference/v2/customers-api/update-customer
+ *
* @method UpdateCustomerResponse send()
*/
class UpdateCustomerRequest extends AbstractMollieRequest
@@ -26,6 +27,7 @@ public function getCustomerReference()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setCustomerReference($value)
@@ -45,6 +47,7 @@ public function getEmail()
/**
* @param string $value
+ *
* @return AbstractRequest
*/
public function setEmail($value)
@@ -68,6 +71,7 @@ public function getLocale()
* Optional value.
*
* @param string $value
+ *
* @return AbstractRequest
*/
public function setLocale($value)
@@ -89,6 +93,7 @@ public function getMetadata()
* Optional value.
*
* @param array $value
+ *
* @return AbstractRequest
*/
public function setMetadata($value)
@@ -98,6 +103,7 @@ public function setMetadata($value)
/**
* @return array
+ *
* @throws InvalidRequestException
*/
public function getData()
@@ -118,6 +124,7 @@ public function getData()
/**
* @param array $data
+ *
* @return UpdateCustomerResponse
*/
public function sendData($data)
diff --git a/src/Message/Response/AbstractMollieResponse.php b/src/Message/Response/AbstractMollieResponse.php
index 64b0466..e6e3b5d 100644
--- a/src/Message/Response/AbstractMollieResponse.php
+++ b/src/Message/Response/AbstractMollieResponse.php
@@ -1,4 +1,5 @@
data['status']) && isset($this->data['detail'])) {
- return false;
- }
-
- return true;
+ return !isset($this->data['status'], $this->data['detail']);
}
- /**
- * @return string
- */
- public function getMessage()
+ public function getMessage(): string
{
- return json_encode($this->data);
+ return \json_encode($this->data);
}
}
diff --git a/src/Message/Response/CancelOrderResponse.php b/src/Message/Response/CancelOrderResponse.php
index 914bc45..7e74310 100644
--- a/src/Message/Response/CancelOrderResponse.php
+++ b/src/Message/Response/CancelOrderResponse.php
@@ -1,4 +1,5 @@
data['status'])) {
return false;
diff --git a/src/Message/Response/CompleteOrderResponse.php b/src/Message/Response/CompleteOrderResponse.php
index dac5c56..b5b5eff 100644
--- a/src/Message/Response/CompleteOrderResponse.php
+++ b/src/Message/Response/CompleteOrderResponse.php
@@ -1,4 +1,5 @@
isPaid();
}
@@ -20,7 +18,7 @@ public function isSuccessful()
*
* {@inheritdoc}
*/
- public function isRedirect()
+ public function isRedirect(): bool
{
return false;
}
diff --git a/src/Message/Response/CompletePurchaseResponse.php b/src/Message/Response/CompletePurchaseResponse.php
index 11c9412..8231acc 100644
--- a/src/Message/Response/CompletePurchaseResponse.php
+++ b/src/Message/Response/CompletePurchaseResponse.php
@@ -1,4 +1,5 @@
isPaid();
}
diff --git a/src/Message/Response/CreateCustomerMandateResponse.php b/src/Message/Response/CreateCustomerMandateResponse.php
index e65f979..0b944f5 100644
--- a/src/Message/Response/CreateCustomerMandateResponse.php
+++ b/src/Message/Response/CreateCustomerMandateResponse.php
@@ -1,4 +1,5 @@
data['id'])) {
- return $this->data['id'];
- }
+ return $this->data['id'] ?? null;
}
- /**
- * @return bool
- */
- public function isSuccessful()
+ public function isSuccessful(): bool
{
return isset($this->data['id']);
}
diff --git a/src/Message/Response/CreateCustomerResponse.php b/src/Message/Response/CreateCustomerResponse.php
index 73b837e..d350609 100644
--- a/src/Message/Response/CreateCustomerResponse.php
+++ b/src/Message/Response/CreateCustomerResponse.php
@@ -1,4 +1,5 @@
data['id'])) {
- return $this->data['id'];
- }
-
- return null;
+ return $this->data['id'] ?? null;
}
}
diff --git a/src/Message/Response/CreateOrderResponse.php b/src/Message/Response/CreateOrderResponse.php
index c56f1f7..1a5c8ac 100644
--- a/src/Message/Response/CreateOrderResponse.php
+++ b/src/Message/Response/CreateOrderResponse.php
@@ -1,4 +1,5 @@
|null
+ */
+ public function getMandates(): ?array
{
- if (isset($this->data['_embedded']['mandates'])) {
- return $this->data['_embedded']['mandates'];
- }
+ return $this->data['_embedded']['mandates'] ?? null;
}
- public function hasValidMandates()
+ public function hasValidMandates(): bool
{
if ($mandates = $this->getMandates()) {
foreach ($mandates as $mandate) {
- if ($mandate['status'] == "valid") {
+ if ('valid' === $mandate['status']) {
return true;
}
}
diff --git a/src/Message/Response/FetchCustomerResponse.php b/src/Message/Response/FetchCustomerResponse.php
index e794962..00fe695 100644
--- a/src/Message/Response/FetchCustomerResponse.php
+++ b/src/Message/Response/FetchCustomerResponse.php
@@ -1,4 +1,5 @@
data['id'])) {
- return $this->data['id'];
- }
-
- return null;
+ return $this->data['id'] ?? null;
}
}
diff --git a/src/Message/Response/FetchIssuersResponse.php b/src/Message/Response/FetchIssuersResponse.php
index 400a644..f8beb15 100644
--- a/src/Message/Response/FetchIssuersResponse.php
+++ b/src/Message/Response/FetchIssuersResponse.php
@@ -1,4 +1,5 @@
data['issuers']) === false) {
+ if (false === isset($this->data['issuers'])) {
return [];
}
diff --git a/src/Message/Response/FetchOrderResponse.php b/src/Message/Response/FetchOrderResponse.php
index 1bc2455..14ab876 100644
--- a/src/Message/Response/FetchOrderResponse.php
+++ b/src/Message/Response/FetchOrderResponse.php
@@ -1,4 +1,5 @@
|null
+ */
+ public function getLines(): ?array
{
- if (isset($this->data['lines'])) {
- return $this->data['lines'];
- }
-
- return null;
+ return $this->data['lines'] ?? null;
}
- public function getItems()
+ public function getItems(): ?ItemBag
{
-
if (isset($this->data['lines'])) {
$items = [];
@@ -31,5 +30,7 @@ public function getItems()
return new ItemBag($items);
}
+
+ return null;
}
}
diff --git a/src/Message/Response/FetchPaymentMethodsResponse.php b/src/Message/Response/FetchPaymentMethodsResponse.php
index 1b615ae..4065684 100644
--- a/src/Message/Response/FetchPaymentMethodsResponse.php
+++ b/src/Message/Response/FetchPaymentMethodsResponse.php
@@ -1,4 +1,5 @@
data['_embedded']["methods"]) === false) {
+ if (false === isset($this->data['_embedded']['methods'])) {
return [];
}
$paymentMethods = [];
- foreach ($this->data['_embedded']["methods"] as $method) {
+ foreach ($this->data['_embedded']['methods'] as $method) {
$paymentMethods[] = new PaymentMethod($method['id'], $method['description']);
}
diff --git a/src/Message/Response/FetchProfileResponse.php b/src/Message/Response/FetchProfileResponse.php
new file mode 100644
index 0000000..b8adcc2
--- /dev/null
+++ b/src/Message/Response/FetchProfileResponse.php
@@ -0,0 +1,18 @@
+data['id'];
+ }
+
+ public function isSuccessful(): bool
+ {
+ return isset($this->data['resource'], $this->data['id'])
+ && 'profile' === $this->data['resource'];
+ }
+}
diff --git a/src/Message/Response/FetchTransactionResponse.php b/src/Message/Response/FetchTransactionResponse.php
index 1042df7..fd8f503 100644
--- a/src/Message/Response/FetchTransactionResponse.php
+++ b/src/Message/Response/FetchTransactionResponse.php
@@ -1,4 +1,5 @@
data['_links']['checkout']['href']);
}
- /**
- * {@inheritdoc}
- */
- public function getRedirectUrl()
+ public function getRedirectUrl(): ?string
{
if ($this->isRedirect()) {
return $this->data['_links']['checkout']['href'];
@@ -40,130 +27,80 @@ public function getRedirectUrl()
/**
* {@inheritdoc}
*/
- public function getRedirectData()
+ public function getRedirectData(): ?array
{
return null;
}
- /**
- * {@inheritdoc}
- */
- public function isSuccessful()
- {
- return parent::isSuccessful();
- }
-
- /**
- * @return boolean
- */
- public function isOpen()
+ public function isOpen(): bool
{
return isset($this->data['status'])
&& ('open' === $this->data['status'] || 'created' === $this->data['status']);
}
- /**
- * @return boolean
- */
- public function isCancelled()
+ public function isCancelled(): bool
{
return isset($this->data['status']) && 'canceled' === $this->data['status'];
}
- /**
- * @return boolean
- */
- public function isPaid()
+ public function isPaid(): bool
{
return isset($this->data['status']) && 'paid' === $this->data['status'];
}
- /**
- * @return boolean
- */
- public function isAuthorized()
+ public function isAuthorized(): bool
{
return isset($this->data['status']) && 'authorized' === $this->data['status'];
}
- /**
- * @return boolean
- */
- public function isPaidOut()
+ public function isPaidOut(): bool
{
return isset($this->data['_links']['settlement']);
}
- /**
- * @return boolean
- */
- public function isExpired()
+ public function isExpired(): bool
{
return isset($this->data['status']) && 'expired' === $this->data['status'];
}
- public function isRefunded()
+ public function isRefunded(): bool
{
return isset($this->data['_links']['refunds']);
}
- public function isPartialRefunded()
+ public function isPartialRefunded(): bool
{
return $this->isRefunded()
&& isset($this->data['amountRemaining'])
&& $this->data['amountRemaining']['value'] > 0;
}
- /**
- * @return boolean
- */
- public function hasChargebacks()
+ public function hasChargebacks(): bool
{
return !empty($this->data['_links']['chargebacks']);
}
- /**
- * @return string|null
- */
- public function getTransactionReference()
+ public function getTransactionReference(): ?string
{
- if (isset($this->data['id'])) {
- return $this->data['id'];
- }
-
- return null;
+ return $this->data['id'] ?? null;
}
- /**
- * @return string|null
- */
- public function getTransactionId()
+ public function getTransactionId(): ?string
{
- if (isset($this->data['metadata']['transactionId'])) {
- return $this->data['metadata']['transactionId'];
- }
-
- return null;
+ return $this->data['metadata']['transactionId'] ?? null;
}
/**
- * @return string|null
+ * @return int|string|null
*/
public function getStatus()
{
- if (isset($this->data['status'])) {
- return $this->data['status'];
- }
-
- return null;
+ return $this->data['status'] ?? null;
}
- /**
- * @return string|null
- */
- public function getAmount()
+ public function getAmount(): ?string
{
- if (isset($this->data['amount']) && is_array($this->data['amount'])) {
+ if (isset($this->data['amount']) && \is_array($this->data['amount'])) {
/**
* $this->data['amount'] = [
* "currency" => "EUR",
@@ -176,9 +113,9 @@ public function getAmount()
return null;
}
- public function getCurrency()
+ public function getCurrency(): ?string
{
- if ($this->isSuccessful() && is_array($this->data['amount'])) {
+ if ($this->isSuccessful() && \is_array($this->data['amount'])) {
/**
* $this->data['amount'] = [
* "currency" => "EUR",
@@ -192,14 +129,10 @@ public function getCurrency()
}
/**
- * @return array|null
+ * @return array|null
*/
- public function getMetadata()
+ public function getMetadata(): ?array
{
- if (isset($this->data['metadata'])) {
- return $this->data['metadata'];
- }
-
- return null;
+ return $this->data['metadata'] ?? null;
}
}
diff --git a/src/Message/Response/PurchaseResponse.php b/src/Message/Response/PurchaseResponse.php
index 7dbea8e..18f7c50 100644
--- a/src/Message/Response/PurchaseResponse.php
+++ b/src/Message/Response/PurchaseResponse.php
@@ -1,4 +1,5 @@
data['paymentId'];
}
- /**
- * @return string
- */
- public function getTransactionId()
+ public function getTransactionId(): string
{
return $this->data['id'];
}
- /**
- * @return bool
- */
- public function isSuccessful()
+ public function isSuccessful(): bool
{
return isset($this->data['id']);
}
diff --git a/src/Message/Response/RevokeCustomerMandateResponse.php b/src/Message/Response/RevokeCustomerMandateResponse.php
index 436112a..ab19d11 100644
--- a/src/Message/Response/RevokeCustomerMandateResponse.php
+++ b/src/Message/Response/RevokeCustomerMandateResponse.php
@@ -1,4 +1,5 @@
data['id'])) {
- return $this->data['id'];
- }
-
- return null;
+ return $this->data['id'] ?? null;
}
}
diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php
index cbd4e41..4e4dfa6 100644
--- a/tests/GatewayTest.php
+++ b/tests/GatewayTest.php
@@ -1,4 +1,5 @@
gateway = new Gateway();
}
- public function testFetchIssuers()
+ public function testFetchIssuers(): void
{
$request = $this->gateway->fetchIssuers();
$this->assertInstanceOf(FetchIssuersRequest::class, $request);
}
- public function testFetchPaymentMethods()
+ public function testFetchPaymentMethods(): void
{
$request = $this->gateway->fetchPaymentMethods();
$this->assertInstanceOf(FetchPaymentMethodsRequest::class, $request);
}
- /**
- * @throws InvalidRequestException
- */
- public function testPurchase()
+ public function testPurchase(): void
{
- $request = $this->gateway->purchase(array('amount' => '10.00', 'currency' => 'EUR'));
+ $request = $this->gateway->purchase(['amount' => '10.00', 'currency' => 'EUR']);
$this->assertInstanceOf(PurchaseRequest::class, $request);
$this->assertSame('10.00', $request->getAmount());
$this->assertSame('EUR', $request->getCurrency());
}
- /**
- * @throws InvalidRequestException
- */
- public function testPurchaseReturn()
+ public function testPurchaseReturn(): void
{
- $request = $this->gateway->completePurchase(array('amount' => '10.00', 'currency' => 'EUR'));
+ $request = $this->gateway->completePurchase(['amount' => '10.00', 'currency' => 'EUR']);
$this->assertInstanceOf(CompletePurchaseRequest::class, $request);
$this->assertSame('10.00', $request->getAmount());
$this->assertSame('EUR', $request->getCurrency());
}
- public function testRefund()
+ public function testRefund(): void
{
$request = $this->gateway->refund(
- array(
+ [
'apiKey' => 'key',
'transactionReference' => 'tr_Qzin4iTWrU',
'amount' => '10.00',
- 'currency' => 'EUR'
- )
+ 'currency' => 'EUR',
+ ]
);
$this->assertInstanceOf(RefundRequest::class, $request);
@@ -90,35 +80,34 @@ public function testRefund()
$this->assertSame(
[
'value' => '10.00',
- 'currency' => 'EUR'
+ 'currency' => 'EUR',
],
$data['amount']
);
}
- /**
- * @expectedException \Omnipay\Common\Exception\InvalidRequestException
- */
- public function testThatRefundDoesntWorkWithoutAmount()
+ public function testThatRefundDoesntWorkWithoutAmount(): void
{
+ $this->expectException(InvalidRequestException::class);
+
$request = $this->gateway->refund(
- array(
+ [
'apiKey' => 'key',
- 'transactionReference' => 'tr_Qzin4iTWrU'
- )
+ 'transactionReference' => 'tr_Qzin4iTWrU',
+ ]
);
$this->assertInstanceOf(RefundRequest::class, $request);
$request->getData();
}
- public function testFetchTransaction()
+ public function testFetchTransaction(): void
{
$request = $this->gateway->fetchTransaction(
- array(
+ [
'apiKey' => 'key',
'transactionReference' => 'tr_Qzin4iTWrU',
- )
+ ]
);
$this->assertInstanceOf(FetchTransactionRequest::class, $request);
@@ -127,31 +116,31 @@ public function testFetchTransaction()
$this->assertSame('tr_Qzin4iTWrU', $data['id']);
}
- public function testCreateCustomer()
+ public function testCreateCustomer(): void
{
$request = $this->gateway->createCustomer(
- array(
+ [
'description' => 'Test name',
'email' => 'test@example.com',
'metadata' => 'Something something something dark side.',
'locale' => 'nl_NL',
- )
+ ]
);
$this->assertInstanceOf(CreateCustomerRequest::class, $request);
}
- public function testUpdateCustomer()
+ public function testUpdateCustomer(): void
{
$request = $this->gateway->updateCustomer(
- array(
+ [
'apiKey' => 'key',
'customerReference' => 'cst_bSNBBJBzdG',
'description' => 'Test name2',
'email' => 'test@example.com',
'metadata' => 'Something something something dark side.',
'locale' => 'nl_NL',
- )
+ ]
);
$this->assertInstanceOf(UpdateCustomerRequest::class, $request);
@@ -161,60 +150,67 @@ public function testUpdateCustomer()
$this->assertSame('Test name2', $data['name']);
}
- public function testFetchCustomer()
+ public function testFetchCustomer(): void
{
$request = $this->gateway->fetchCustomer(
- array(
+ [
'apiKey' => 'key',
'customerReference' => 'cst_bSNBBJBzdG',
- )
+ ]
);
$this->assertInstanceOf(FetchCustomerRequest::class, $request);
}
- public function testFetchCustomerMandates()
+ public function testFetchCustomerMandates(): void
{
$request = $this->gateway->fetchCustomerMandates(
- array(
+ [
'apiKey' => 'key',
'customerReference' => 'cst_bSNBBJBzdG',
- )
+ ]
);
$this->assertInstanceOf(FetchCustomerMandatesRequest::class, $request);
}
- public function testRevokeCustomerMandate()
+ public function testRevokeCustomerMandate(): void
{
$request = $this->gateway->revokeCustomerMandate(
- array(
- 'apiKey' => "key",
- "customerReference" => "cst_bSNBBJBzdG",
- "mandateId" => "mdt_pWUnw6pkBN",
- )
+ [
+ 'apiKey' => 'key',
+ 'customerReference' => 'cst_bSNBBJBzdG',
+ 'mandateId' => 'mdt_pWUnw6pkBN',
+ ]
);
$this->assertInstanceOf(RevokeCustomerMandateRequest::class, $request);
}
- public function testCreateCustomerMandate()
+ public function testCreateCustomerMandate(): void
{
$request = $this->gateway->createCustomerMandate(
- array(
- 'apiKey' => "mykey",
- 'consumerName' => "Customer A",
- 'consumerAccount' => "NL53INGB0000000000",
- "method" => "directdebit",
+ [
+ 'apiKey' => 'mykey',
+ 'consumerName' => 'Customer A',
+ 'consumerAccount' => 'NL53INGB0000000000',
+ 'method' => 'directdebit',
'customerReference' => 'cst_bSNBBJBzdG',
- 'mandateReference' => "YOUR-COMPANY-MD13804",
- )
+ 'mandateReference' => 'YOUR-COMPANY-MD13804',
+ ]
);
$this->assertInstanceOf(CreateCustomerMandateRequest::class, $request);
}
- public function testVoid()
+ public function testFetchProfile(): void
+ {
+ $request = $this->gateway->fetchProfile(['apiKey' => 'myKey']);
+
+ self::assertSame(['apiKey' => 'myKey'], $request->getParameters());
+ }
+
+ public function testVoid(): void
{
$this->assertInstanceOf(CancelOrderRequest::class, $this->gateway->void());
}
diff --git a/tests/Message/AbstractMollieRequestTest.php b/tests/Message/AbstractMollieRequestTest.php
index 6174e00..fb20034 100644
--- a/tests/Message/AbstractMollieRequestTest.php
+++ b/tests/Message/AbstractMollieRequestTest.php
@@ -1,65 +1,59 @@
gateway = new Gateway($this->getHttpClient());
}
-
- public function testVersionString()
+ public function testVersionString(): void
{
$request = $this->gateway->fetchIssuers();
$request->send();
- /** @var \Psr\Http\Message\RequestInterface $httpRequest */
$httpRequest = $this->getMockedRequests()[0];
+ \assert($httpRequest instanceof RequestInterface);
- $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion();
+ $versionString = 'Omnipay-Mollie/' . Gateway::GATEWAY_VERSION;
$this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent'));
}
- public function testCustomVersionStrings()
+ public function testCustomVersionStrings(): void
{
$this->gateway->initialize([
- 'versionStrings' => ['Acme/6.84']
+ 'versionStrings' => ['Acme/6.84'],
]);
$request = $this->gateway->fetchIssuers();
$request->send();
- /** @var \Psr\Http\Message\RequestInterface $httpRequest */
$httpRequest = $this->getMockedRequests()[0];
+ \assert($httpRequest instanceof RequestInterface);
- $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion() . ' Acme/6.84';
+ $versionString = 'Omnipay-Mollie/' . Gateway::GATEWAY_VERSION . ' Acme/6.84';
$this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent'));
}
- public function testAddVersionString()
+ public function testAddVersionString(): void
{
$this->gateway->addVersionString('Acme/6.84');
$request = $this->gateway->fetchIssuers();
$request->send();
- /** @var \Psr\Http\Message\RequestInterface $httpRequest */
$httpRequest = $this->getMockedRequests()[0];
+ \assert($httpRequest instanceof RequestInterface);
- $versionString = 'Omnipay-Mollie/'.Gateway::GATEWAY_VERSION.' PHP/' . phpversion() . ' Acme/6.84';
+ $versionString = 'Omnipay-Mollie/' . Gateway::GATEWAY_VERSION . ' Acme/6.84';
$this->assertEquals($versionString, $httpRequest->getHeaderLine('User-Agent'));
}
}
diff --git a/tests/Message/AssertRequestTrait.php b/tests/Message/AssertRequestTrait.php
index b74abba..6086976 100644
--- a/tests/Message/AssertRequestTrait.php
+++ b/tests/Message/AssertRequestTrait.php
@@ -2,20 +2,20 @@
namespace Omnipay\Mollie\Test\Message;
+use Psr\Http\Message\RequestInterface;
+
trait AssertRequestTrait
{
- abstract function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false);
-
- abstract function assertJsonStringEqualsJsonString($expected, $actual, $message = null);
-
- public function assertEqualRequest(\Psr\Http\Message\RequestInterface $expectedRequest, \Psr\Http\Message\RequestInterface $actualRequest)
+ public function assertEqualRequest(RequestInterface $expectedRequest, RequestInterface $actualRequest)
{
- $this->assertEquals($expectedRequest->getMethod(), $actualRequest->getMethod(), "Expected request Method should be equal to actual request method.");
+ $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.");
+ $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.");
+ if (empty((string) $expectedRequest->getBody())) {
+ return;
}
+
+ $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/CancelOrderRequestTest.php b/tests/Message/CancelOrderRequestTest.php
index 16a4a04..ff8abce 100644
--- a/tests/Message/CancelOrderRequestTest.php
+++ b/tests/Message/CancelOrderRequestTest.php
@@ -2,6 +2,7 @@
namespace Omnipay\Mollie\Test\Message;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Http\ClientInterface;
use Omnipay\Mollie\Message\Request\CancelOrderRequest;
use Omnipay\Mollie\Message\Response\CancelOrderResponse;
@@ -10,17 +11,13 @@
final class CancelOrderRequestTest extends TestCase
{
- /**
- * @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject
- */
+ /** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject */
private $httpClient;
- /**
- * @var CancelOrderRequest
- */
+ /** @var CancelOrderRequest */
private $request;
- public function setUp()
+ public function setUp(): void
{
$this->httpClient = $this->createMock(ClientInterface::class);
$this->request = new CancelOrderRequest($this->httpClient, $this->getHttpRequest());
@@ -46,12 +43,11 @@ public function responseDataProvider()
/**
* @dataProvider insufficientDataProvider
*
- * @expectedException \Omnipay\Common\Exception\InvalidRequestException
- *
* @param array $input
*/
public function testGetDataWillValidateRequiredData(array $input)
{
+ $this->expectException(InvalidRequestException::class);
$this->request->initialize($input);
$this->request->getData();
}
@@ -77,7 +73,9 @@ public function testSendData(array $responseData, $success)
->with(
'DELETE',
'https://api.mollie.com/v2/orders/ord_kEn1PlbGa',
- ['Authorization' => 'Bearer mykey']
+ $this->callback(static function ($headers) {
+ return 'Bearer mykey' == $headers['Authorization'];
+ })
)->willReturn($response);
$this->request->initialize(['apiKey' => 'mykey', 'transactionReference' => 'ord_kEn1PlbGa']);
diff --git a/tests/Message/CompleteOrderRequestTest.php b/tests/Message/CompleteOrderRequestTest.php
index 9b703fa..7bdb06f 100644
--- a/tests/Message/CompleteOrderRequestTest.php
+++ b/tests/Message/CompleteOrderRequestTest.php
@@ -3,39 +3,35 @@
namespace Omnipay\Mollie\Test\Message;
use GuzzleHttp\Psr7\Request;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Mollie\Message\Request\CompleteOrderRequest;
use Omnipay\Mollie\Message\Request\CompletePurchaseRequest;
use Omnipay\Mollie\Message\Response\CompleteOrderResponse;
-use Omnipay\Mollie\Message\Response\CompletePurchaseResponse;
use Omnipay\Tests\TestCase;
class CompleteOrderRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var CompletePurchaseRequest
- */
+ /** @var CompletePurchaseRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new CompleteOrderRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
- ));
+ ]);
- $this->getHttpRequest()->request->replace(array(
+ $this->getHttpRequest()->request->replace([
'id' => 'ord_kEn1PlbGa',
- ));
+ ]);
}
- /**
- * @expectedException \Omnipay\Common\Exception\InvalidRequestException
- * @expectedExceptionMessage The transactionReference parameter is required
- */
public function testGetDataWithoutIDParameter()
{
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The transactionReference parameter is required');
$this->getHttpRequest()->request->remove('id');
$data = $this->request->getData();
@@ -44,23 +40,23 @@ public function testGetDataWithoutIDParameter()
}
/**
- * @throws \Omnipay\Common\Exception\InvalidRequestException
+ * @throws InvalidRequestException
*/
public function testGetData()
{
$data = $this->request->getData();
- $this->assertSame("ord_kEn1PlbGa", $data['id']);
+ $this->assertSame('ord_kEn1PlbGa', $data['id']);
$this->assertCount(1, $data);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CompleteOrderSuccess.txt');
- /** @var CompleteOrderResponse $response */
$response = $this->request->send();
+ \assert($response instanceof CompleteOrderResponse);
- $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/orders/ord_kEn1PlbGa"), $this->getMockClient()->getLastRequest());
+ $this->assertEqualRequest(new Request('GET', 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa'), $this->getMockClient()->getLastRequest());
$this->assertInstanceOf(CompleteOrderResponse::class, $response);
$this->assertFalse($response->isSuccessful());
@@ -69,5 +65,4 @@ public function testSendSuccess()
$this->assertFalse($response->isRedirect());
$this->assertSame('ord_kEn1PlbGa', $response->getTransactionReference());
}
-
}
diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php
index 11e4289..a492348 100644
--- a/tests/Message/CompletePurchaseRequestTest.php
+++ b/tests/Message/CompletePurchaseRequestTest.php
@@ -3,6 +3,7 @@
namespace Omnipay\Mollie\Test\Message;
use GuzzleHttp\Psr7\Request;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Mollie\Message\Request\CompletePurchaseRequest;
use Omnipay\Mollie\Message\Response\CompletePurchaseResponse;
use Omnipay\Tests\TestCase;
@@ -11,29 +12,26 @@ class CompletePurchaseRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var CompletePurchaseRequest
- */
+ /** @var CompletePurchaseRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
- ));
+ ]);
- $this->getHttpRequest()->request->replace(array(
+ $this->getHttpRequest()->request->replace([
'id' => 'tr_Qzin4iTWrU',
- ));
+ ]);
}
- /**
- * @expectedException \Omnipay\Common\Exception\InvalidRequestException
- * @expectedExceptionMessage The transactionReference parameter is required
- */
public function testGetDataWithoutIDParameter()
{
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The transactionReference parameter is required');
+
$this->getHttpRequest()->request->remove('id');
$data = $this->request->getData();
@@ -42,13 +40,13 @@ public function testGetDataWithoutIDParameter()
}
/**
- * @throws \Omnipay\Common\Exception\InvalidRequestException
+ * @throws InvalidRequestException
*/
public function testGetData()
{
$data = $this->request->getData();
- $this->assertSame("tr_Qzin4iTWrU", $data['id']);
+ $this->assertSame('tr_Qzin4iTWrU', $data['id']);
$this->assertCount(1, $data);
}
@@ -57,7 +55,7 @@ public function testSendSuccess()
$this->setMockHttpResponse('CompletePurchaseSuccess.txt');
$response = $this->request->send();
- $this->assertEqualRequest(new 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());
@@ -72,7 +70,7 @@ public function testSendExpired()
$this->setMockHttpResponse('CompletePurchaseExpired.txt');
$response = $this->request->send();
- $this->assertEqualRequest(new 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/CreateCustomerMandateRequestTest.php b/tests/Message/CreateCustomerMandateRequestTest.php
index 91e262b..fe63d28 100644
--- a/tests/Message/CreateCustomerMandateRequestTest.php
+++ b/tests/Message/CreateCustomerMandateRequestTest.php
@@ -12,23 +12,21 @@ class CreateCustomerMandateRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var CreateCustomerMandateRequest
- */
+ /** @var CreateCustomerMandateRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new CreateCustomerMandateRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
- 'apiKey' => "mykey",
- 'consumerName' => "Customer A",
- 'consumerAccount' => "NL53INGB0000000000",
- "method" => "directdebit",
+ $this->request->initialize([
+ 'apiKey' => 'mykey',
+ 'consumerName' => 'Customer A',
+ 'consumerAccount' => 'NL53INGB0000000000',
+ 'method' => 'directdebit',
'customerReference' => 'cst_bSNBBJBzdG',
- 'mandateReference' => "YOUR-COMPANY-MD13804"
- ));
+ 'mandateReference' => 'YOUR-COMPANY-MD13804',
+ ]);
}
/**
@@ -38,9 +36,9 @@ public function testGetData()
{
$data = $this->request->getData();
- $this->assertSame("NL53INGB0000000000", $data['consumerAccount']);
+ $this->assertSame('NL53INGB0000000000', $data['consumerAccount']);
$this->assertSame('directdebit', $data['method']);
- $this->assertSame("YOUR-COMPANY-MD13804", $data['mandateReference']);
+ $this->assertSame('YOUR-COMPANY-MD13804', $data['mandateReference']);
$this->assertCount(4, $data);
}
@@ -49,13 +47,13 @@ public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCustomerMandateSuccess.txt');
- /** @var CreateCustomerMandateResponse $response */
$response = $this->request->send();
+ \assert($response instanceof CreateCustomerMandateResponse);
- $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates"), $this->getMockClient()->getLastRequest());
+ $this->assertEqualRequest(new Request('POST', 'https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates'), $this->getMockClient()->getLastRequest());
$this->assertInstanceOf(CreateCustomerMandateResponse::class, $response);
- $this->assertSame("mdt_h3gAaD5zP", $response->getMandateId());
+ $this->assertSame('mdt_h3gAaD5zP', $response->getMandateId());
$this->assertTrue($response->isSuccessful());
$this->assertJsonStringEqualsJsonString(
diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php
index b4826b2..c277191 100644
--- a/tests/Message/CreateCustomerRequestTest.php
+++ b/tests/Message/CreateCustomerRequestTest.php
@@ -12,23 +12,20 @@ class CreateCustomerRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- *
- * @var CreateCustomerRequest
- */
+ /** @var CreateCustomerRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
'description' => 'John Doe',
'email' => 'john@doe.com',
'locale' => 'nl_NL',
'metadata' => 'Just some meta data.',
- ));
+ ]);
}
/**
@@ -36,15 +33,15 @@ public function setUp()
*/
public function testData()
{
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
'description' => 'John Doe',
'email' => 'john@doe.com',
'metadata' => 'Just some meta data.',
- ));
+ ]);
$data = $this->request->getData();
- $this->assertSame("John Doe", $data['name']);
+ $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,13 +51,13 @@ public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCustomerSuccess.txt');
- /** @var CreateCustomerResponse $response */
$response = $this->request->send();
+ \assert($response instanceof CreateCustomerResponse);
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/customers",
+ 'POST',
+ 'https://api.mollie.com/v2/customers',
[],
'{
"name":"John Doe",
@@ -87,7 +84,7 @@ public function testSendFailure()
$this->setMockHttpResponse('CreateCustomerFailure.txt');
$response = $this->request->send();
- $this->assertEqualRequest(new Request("POST", "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/CreateOrderRequestTest.php b/tests/Message/CreateOrderRequestTest.php
index 38f0bb5..f9e54f3 100644
--- a/tests/Message/CreateOrderRequestTest.php
+++ b/tests/Message/CreateOrderRequestTest.php
@@ -1,113 +1,108 @@
request = new CreateOrderRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
- 'apiKey' => 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
- 'amount' => '1027.99',
- 'currency' => 'EUR',
- 'orderNumber' => '1337',
- 'lines' => [
- [
- 'type' => 'physical',
- 'sku' => '5702016116977',
- 'name' => 'LEGO 42083 Bugatti Chiron',
- 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
- 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
- 'quantity' => 2,
- 'vatRate' => '21.00',
- 'unitPrice' => '399.00',
- 'totalAmount' => '698.00',
- 'discountAmount' => '100.00',
- 'vatAmount' => '121.14',
+ $this->request->initialize(
+ [
+ 'apiKey' => 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
+ 'amount' => '1027.99',
+ 'currency' => 'EUR',
+ 'orderNumber' => '1337',
+ 'lines' => [
+ [
+ 'type' => 'physical',
+ 'sku' => '5702016116977',
+ 'name' => 'LEGO 42083 Bugatti Chiron',
+ 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
+ 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
+ 'quantity' => 2,
+ 'vatRate' => '21.00',
+ 'unitPrice' => '399.00',
+ 'totalAmount' => '698.00',
+ 'discountAmount' => '100.00',
+ 'vatAmount' => '121.14',
+ ],
+ [
+ 'type' => 'physical',
+ 'sku' => '5702015594028',
+ 'name' => 'LEGO 42056 Porsche 911 GT3 RS',
+ 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056',
+ 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
+ 'quantity' => 1,
+ 'vatRate' => '21.00',
+ 'unitPrice' => '329.99',
+ 'totalAmount' => '329.99',
+ 'vatAmount' => '57.27',
+ ],
],
- [
- 'type' => 'physical',
- 'sku' => '5702015594028',
- 'name' => 'LEGO 42056 Porsche 911 GT3 RS',
- 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056',
- 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
- 'quantity' => 1,
- 'vatRate' => '21.00',
- 'unitPrice' => '329.99',
- 'totalAmount' => '329.99',
- 'vatAmount' => '57.27',
+ 'card' => [
+ 'company' => 'Mollie B.V.',
+ 'email' => 'norris@chucknorrisfacts.net',
+ 'birthday' => '1958-01-31',
+ 'billingTitle' => 'Dhr',
+ 'billingFirstName' => 'Piet',
+ 'billingLastName' => 'Mondriaan',
+ 'billingAddress1' => 'Keizersgracht 313',
+ 'billingCity' => 'Amsterdam',
+ 'billingPostcode' => '1234AB',
+ 'billingState' => 'Noord-Holland',
+ 'billingCountry' => 'NL',
+ 'billingPhone' => '+31208202070',
+ 'shippingTitle' => 'Mr',
+ 'shippingFirstName' => 'Chuck',
+ 'shippingLastName' => 'Norris',
+ 'shippingAddress1' => 'Prinsengracht 313',
+ 'shippingAddress2' => '4th floor',
+ 'shippingCity' => 'Haarlem',
+ 'shippingPostcode' => '5678AB',
+ 'shippingState' => 'Noord-Holland',
+ 'shippingCountry' => 'NL',
],
- ],
- 'card' => [
- 'company' => 'Mollie B.V.',
- 'email' => 'norris@chucknorrisfacts.net',
- 'birthday' => '1958-01-31',
- 'billingTitle' => 'Dhr',
- 'billingFirstName' => 'Piet',
- 'billingLastName' => 'Mondriaan',
- 'billingAddress1' => 'Keizersgracht 313',
- 'billingCity' => 'Amsterdam',
- 'billingPostcode' => '1234AB',
- 'billingState' => 'Noord-Holland',
- 'billingCountry' => 'NL',
- 'billingPhone' => '+31208202070',
- 'shippingTitle' => 'Mr',
- 'shippingFirstName' => 'Chuck',
- 'shippingLastName' => 'Norris',
- 'shippingAddress1' => 'Prinsengracht 313',
- 'shippingAddress2' => '4th floor',
- 'shippingCity' => 'Haarlem',
- 'shippingPostcode' => '5678AB',
- 'shippingState' => 'Noord-Holland',
- 'shippingCountry' => 'NL',
- ],
- 'metadata' => [
- 'order_id' => '1337',
- 'description' => 'Lego cars',
- ],
- 'locale' => 'nl_NL',
- 'returnUrl' => 'https://example.org/redirect',
- 'notifyUrl' => 'https://example.org/webhook',
- 'paymentMethod' => 'klarnapaylater',
- 'billingEmail' => 'piet@mondriaan.com',
- ));
+ 'metadata' => [
+ 'order_id' => '1337',
+ 'description' => 'Lego cars',
+ ],
+ 'locale' => 'nl_NL',
+ 'returnUrl' => 'https://example.org/redirect',
+ 'notifyUrl' => 'https://example.org/webhook',
+ 'paymentMethod' => 'klarnapaylater',
+ 'billingEmail' => 'piet@mondriaan.com',
+ 'cardToken' => 'qwe123asd',
+ ]
+ );
}
- /**
- * @throws InvalidRequestException
- */
- public function testGetData()
+ public function testGetData(): void
{
$data = $this->request->getData();
- $this->assertSame(["value" => "1027.99", "currency" => "EUR"], $data['amount']);
+ $this->assertSame(['value' => '1027.99', 'currency' => 'EUR'], $data['amount']);
$this->assertSame('1337', $data['orderNumber']);
$this->assertSame('https://example.org/redirect', $data['redirectUrl']);
$this->assertSame('klarnapaylater', $data['method']);
$this->assertSame('Lego cars', $data['metadata']['description']);
$this->assertSame('nl_NL', $data['locale']);
- $this->assertCount(11, $data);
+ $this->assertCount(12, $data);
}
- public function testGetAddressData()
+ public function testGetAddressData(): void
{
$data = $this->request->getData();
@@ -136,10 +131,9 @@ public function testGetAddressData()
$this->assertSame('Mondriaan', $billingAddress['familyName']);
$this->assertSame('piet@mondriaan.com', $billingAddress['email']);
$this->assertSame('+31208202070', $billingAddress['phone']);
-
}
- public function testGetLines()
+ public function testGetLines(): void
{
$data = $this->request->getData();
@@ -159,30 +153,32 @@ public function testGetLines()
$this->assertSame('121.14', $line['vatAmount']['value']);
}
- public function testDiscountLines()
+ public function testDiscountLines(): void
{
- $this->request->setLines([
+ $this->request->setLines(
[
- 'type' => 'physical',
- 'sku' => '5702016116977',
- 'name' => 'LEGO 42083 Bugatti Chiron',
- 'quantity' => 2,
- 'vatRate' => '21.00',
- 'unitPrice' => '399.00',
- 'totalAmount' => '698.00',
- 'discountAmount' => '100.00',
- 'vatAmount' => '121.14',
- ],
- [
- 'type' => 'discount',
- 'name' => 'Discount 100 EURO',
- 'quantity' => 1,
- 'vatRate' => '21.00',
- 'unitPrice' => '-100.00',
- 'totalAmount' => '-100.00',
- 'vatAmount' => '-17.36',
- ],
- ]);
+ [
+ 'type' => 'physical',
+ 'sku' => '5702016116977',
+ 'name' => 'LEGO 42083 Bugatti Chiron',
+ 'quantity' => 2,
+ 'vatRate' => '21.00',
+ 'unitPrice' => '399.00',
+ 'totalAmount' => '698.00',
+ 'discountAmount' => '100.00',
+ 'vatAmount' => '121.14',
+ ],
+ [
+ 'type' => 'discount',
+ 'name' => 'Discount 100 EURO',
+ 'quantity' => 1,
+ 'vatRate' => '21.00',
+ 'unitPrice' => '-100.00',
+ 'totalAmount' => '-100.00',
+ 'vatAmount' => '-17.36',
+ ],
+ ]
+ );
$this->setMockHttpResponse('CreateOrderSuccess.txt');
$response = $this->request->send();
@@ -190,23 +186,21 @@ public function testDiscountLines()
$this->assertInstanceOf(CreateOrderResponse::class, $response);
}
-
- public function testSendSuccess()
+ public function testSendSuccess(): void
{
$this->setMockHttpResponse('CreateOrderSuccess.txt');
$response = $this->request->send();
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/orders",
+ 'POST',
+ 'https://api.mollie.com/v2/orders',
[],
- file_get_contents(__DIR__ . '/../Mock/CreateOrderRequest.txt')
+ \file_get_contents(__DIR__ . '/../Mock/CreateOrderRequest.txt')
),
$this->getMockClient()->getLastRequest()
);
-
$this->assertInstanceOf(CreateOrderResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
@@ -214,23 +208,29 @@ public function testSendSuccess()
$this->assertSame('https://www.mollie.com/payscreen/order/checkout/pbjz8x', $response->getRedirectUrl());
$this->assertNull($response->getRedirectData());
$this->assertSame('ord_pbjz8x', $response->getTransactionReference());
- $this->assertSame('created' ,$response->getStatus());
+ $this->assertSame('created', $response->getStatus());
$this->assertTrue($response->isOpen());
$this->assertFalse($response->isPaid());
$this->assertNull($response->getCode());
}
- public function testSendFailure()
+ public function testSendFailure(): void
{
$this->setMockHttpResponse('CreateOrderFailure.txt');
$response = $this->request->send();
- $this->assertEqualRequest(new Request("POST", "https://api.mollie.com/v2/orders"), $this->getMockClient()->getLastRequest());
+ $this->assertEqualRequest(
+ new Request('POST', 'https://api.mollie.com/v2/orders'),
+ $this->getMockClient()->getLastRequest()
+ );
$this->assertInstanceOf(CreateOrderResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$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->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/Message/CreateShipmentRequestTest.php b/tests/Message/CreateShipmentRequestTest.php
index dd23c47..a059f89 100644
--- a/tests/Message/CreateShipmentRequestTest.php
+++ b/tests/Message/CreateShipmentRequestTest.php
@@ -7,7 +7,6 @@
use Omnipay\Mollie\Item;
use Omnipay\Mollie\Message\Request\CreateCustomerRequest;
use Omnipay\Mollie\Message\Request\CreateShipmentRequest;
-use Omnipay\Mollie\Message\Response\CreateCustomerResponse;
use Omnipay\Mollie\Message\Response\CreateShipmentResponse;
use Omnipay\Tests\TestCase;
@@ -15,17 +14,14 @@ class CreateShipmentRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- *
- * @var CreateCustomerRequest
- */
+ /** @var CreateCustomerRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new CreateShipmentRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
'transactionReference' => 'ord_xxx',
'items' => [
@@ -35,14 +31,14 @@ public function setUp()
],
[
'id' => 'odl_jp31jz',
- ]
+ ],
],
'tracking' => [
'carrier' => 'PostNL',
'code' => '3SKABA000000000',
'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C',
- ]
- ));
+ ],
+ ]);
}
/**
@@ -52,10 +48,10 @@ public function testData()
{
$data = $this->request->getData();
- $this->assertSame("odl_dgtxyl", $data['lines'][0]['id']);
+ $this->assertSame('odl_dgtxyl', $data['lines'][0]['id']);
$this->assertSame(1, $data['lines'][0]['quantity']);
$this->assertCount(2, $data['lines'][0]);
- $this->assertSame("odl_jp31jz", $data['lines'][1]['id']);
+ $this->assertSame('odl_jp31jz', $data['lines'][1]['id']);
$this->assertCount(1, $data['lines'][1]);
$this->assertSame([
@@ -71,14 +67,14 @@ public function testSendSuccess()
{
$this->setMockHttpResponse('CreateShipmentSuccess.txt');
- /** @var CreateShipmentResponse $response */
$response = $this->request->send();
+ \assert($response instanceof CreateShipmentResponse);
$orderId = $this->request->getTransactionReference();
$this->assertEqualRequest(
new Request(
- "POST",
+ 'POST',
"https://api.mollie.com/v2/orders/{$orderId}/shipments",
[],
'{
@@ -115,16 +111,14 @@ public function testSendSuccess()
$this->assertCount(2, $response->getItems()->all());
- /** @var Item $item */
$item = $response->getItems()->all()[0];
+ \assert($item instanceof Item);
$this->assertSame('5702016116977', $item->getSku());
$this->assertSame(1, $item->getQuantity());
- $this->assertSame('299.00', $item->getTotalAmount());
+ $this->assertSame('299.00', $item->getTotalAmount());
// We cannot parse _links, rest should match
unset($line['_links']);
- $this->assertSame(array_keys($line), array_keys($item->getParameters()));
-
+ $this->assertSame(\array_keys($line), \array_keys($item->getParameters()));
}
-
}
diff --git a/tests/Message/FetchCustomerMandatesRequestTest.php b/tests/Message/FetchCustomerMandatesRequestTest.php
index 1ca0d45..c2cbc15 100644
--- a/tests/Message/FetchCustomerMandatesRequestTest.php
+++ b/tests/Message/FetchCustomerMandatesRequestTest.php
@@ -12,19 +12,17 @@ class FetchCustomerMandatesRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var FetchCustomerMandatesRequest
- */
+ /** @var FetchCustomerMandatesRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchCustomerMandatesRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
- array(
+ [
'apiKey' => 'mykey',
'customerReference' => 'cst_R6JLAuqEgm',
- )
+ ]
);
}
@@ -40,18 +38,18 @@ public function testGetData()
public function testSendSuccess()
{
- $this->setMockHttpResponse("FetchCustomerMandatesSuccess.txt");
+ $this->setMockHttpResponse('FetchCustomerMandatesSuccess.txt');
$response = $this->request->send();
- $this->assertEqualRequest(new Request("GET", "https://api.mollie.com/v2/customers/cst_R6JLAuqEgm/mandates"), $this->getMockClient()->getLastRequest());
+ $this->assertEqualRequest(new Request('GET', 'https://api.mollie.com/v2/customers/cst_R6JLAuqEgm/mandates'), $this->getMockClient()->getLastRequest());
$this->assertInstanceOf(FetchCustomerMandatesResponse::class, $response);
$mandates = $response->getMandates();
- $this->assertSame("mdt_AcQl5fdL4h", $mandates[0]['id']);
- $this->assertSame("directdebit", $mandates[0]['method']);
+ $this->assertSame('mdt_AcQl5fdL4h', $mandates[0]['id']);
+ $this->assertSame('directdebit', $mandates[0]['method']);
$this->assertTrue($response->hasValidMandates());
$this->assertJsonStringEqualsJsonString(
diff --git a/tests/Message/FetchCustomerRequestTest.php b/tests/Message/FetchCustomerRequestTest.php
index 7553382..1f2c0f9 100644
--- a/tests/Message/FetchCustomerRequestTest.php
+++ b/tests/Message/FetchCustomerRequestTest.php
@@ -12,19 +12,17 @@ class FetchCustomerRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var FetchCustomerRequest
- */
+ /** @var FetchCustomerRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
- array(
+ [
'apiKey' => 'mykey',
'customerReference' => 'cst_bSNBBJBzdG',
- )
+ ]
);
}
@@ -42,10 +40,10 @@ public function testSendSuccess()
{
$this->setMockHttpResponse('FetchCustomerSuccess.txt');
- /** @var FetchCustomerResponse $response */
$response = $this->request->send();
+ \assert($response instanceof FetchCustomerResponse);
- $this->assertEqualRequest(new 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());
@@ -61,10 +59,10 @@ public function testSendFailure()
{
$this->setMockHttpResponse('FetchCustomerFailure.txt');
- /** @var FetchCustomerResponse $response */
$response = $this->request->send();
+ \assert($response instanceof FetchCustomerResponse);
- $this->assertEqualRequest(new 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/FetchIssuersRequestTest.php b/tests/Message/FetchIssuersRequestTest.php
index 5ef6cd0..701a43c 100644
--- a/tests/Message/FetchIssuersRequestTest.php
+++ b/tests/Message/FetchIssuersRequestTest.php
@@ -13,17 +13,15 @@ class FetchIssuersRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var FetchIssuersRequest
- */
+ /** @var FetchIssuersRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchIssuersRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
- 'apiKey' => 'mykey'
- ));
+ $this->request->initialize([
+ 'apiKey' => 'mykey',
+ ]);
}
/**
@@ -42,7 +40,7 @@ public function testSendSuccess()
$response = $this->request->send();
$this->assertEqualRequest(
- new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"),
+ new Request('GET', 'https://api.mollie.com/v2/methods/ideal?include=issuers'),
$this->getMockClient()->getLastRequest()
);
@@ -54,7 +52,7 @@ public function testSendSuccess()
$expectedIssuer = new Issuer('ideal_ABNANL2A', 'ABN AMRO', 'ideal');
$expectedIssuer2 = new Issuer('ideal_ASNBNL21', 'ASN Bank', 'ideal');
- $this->assertEquals(array($expectedIssuer, $expectedIssuer2), $response->getIssuers());
+ $this->assertEquals([$expectedIssuer, $expectedIssuer2], $response->getIssuers());
}
public function testSendFailure()
@@ -63,7 +61,7 @@ public function testSendFailure()
$response = $this->request->send();
$this->assertEqualRequest(
- new Request("GET", "https://api.mollie.com/v2/methods/ideal?include=issuers"),
+ new Request('GET', 'https://api.mollie.com/v2/methods/ideal?include=issuers'),
$this->getMockClient()->getLastRequest()
);
@@ -74,5 +72,4 @@ public function testSendFailure()
$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->assertEmpty($response->getIssuers());
}
-
}
diff --git a/tests/Message/FetchOrderRequestTest.php b/tests/Message/FetchOrderRequestTest.php
index d42ea53..b120856 100644
--- a/tests/Message/FetchOrderRequestTest.php
+++ b/tests/Message/FetchOrderRequestTest.php
@@ -16,19 +16,17 @@ class FetchOrderRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var FetchTransactionRequest
- */
+ /** @var FetchTransactionRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchOrderRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
- array(
+ [
'apiKey' => 'mykey',
'transactionReference' => 'ord_kEn1PlbGa',
- )
+ ]
);
}
@@ -39,25 +37,24 @@ public function testGetData()
{
$data = $this->request->getData();
- $this->assertSame("ord_kEn1PlbGa", $data['id']);
+ $this->assertSame('ord_kEn1PlbGa', $data['id']);
$this->assertCount(1, $data);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchOrderSuccess.txt');
- /** @var FetchOrderResponse $response */
$response = $this->request->send();
+ \assert($response instanceof FetchOrderResponse);
$this->assertEqualRequest(
new Request(
- "GET",
- "https://api.mollie.com/v2/orders/ord_kEn1PlbGa"
+ 'GET',
+ 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa'
),
$this->getMockClient()->getLastRequest()
);
-
$this->assertInstanceOf(FetchOrderResponse::class, $response);
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isPaid());
@@ -66,9 +63,9 @@ public function testSendSuccess()
$this->assertTrue($response->isRedirect());
$this->assertFalse($response->isRefunded());
$this->assertFalse($response->isPartialRefunded());
- $this->assertSame("created", $response->getStatus());
+ $this->assertSame('created', $response->getStatus());
$this->assertSame('ord_kEn1PlbGa', $response->getTransactionReference());
- $this->assertSame("1027.99", $response->getAmount());
+ $this->assertSame('1027.99', $response->getAmount());
$this->assertCount(2, $response->getLines());
$line = $response->getLines()[0];
@@ -79,15 +76,15 @@ public function testSendSuccess()
$this->assertCount(2, $response->getItems()->all());
- /** @var Item $item */
$item = $response->getItems()->all()[0];
+ \assert($item instanceof Item);
$this->assertSame('5702016116977', $item->getSku());
$this->assertSame(2, $item->getQuantity());
- $this->assertSame('0.00', $item->getAmountShipped());
+ $this->assertSame('0.00', $item->getAmountShipped());
// We cannot parse _links, rest should match
unset($line['_links']);
- $this->assertSame(array_keys($line), array_keys($item->getParameters()));
+ $this->assertSame(\array_keys($line), \array_keys($item->getParameters()));
}
public function testSendDataWithIncludingPayments()
@@ -105,8 +102,8 @@ public function testSendDataWithIncludingPayments()
->with(
FetchOrderRequest::GET,
'https://api.mollie.com/v2/orders/ord_kEn1PlbGa?embed=payments',
- $this->callback(function ($headers) {
- return $headers['Authorization'] == 'Bearer mykey';
+ $this->callback(static function ($headers) {
+ return 'Bearer mykey' == $headers['Authorization'];
}),
null
)->willReturn($clientResponse);
@@ -122,8 +119,8 @@ public function testSendDataWithIncludingPayments()
$response = $request->sendData(['id' => 'ord_kEn1PlbGa']);
- self::assertInstanceOf(FetchOrderResponse::class, $response);
- self::assertEquals($request, $response->getRequest());
- self::assertEquals($expectedData, $response->getData());
+ $this->assertInstanceOf(FetchOrderResponse::class, $response);
+ $this->assertEquals($request, $response->getRequest());
+ $this->assertEquals($expectedData, $response->getData());
}
}
diff --git a/tests/Message/FetchPaymentMethodsRequestTest.php b/tests/Message/FetchPaymentMethodsRequestTest.php
index d1f48eb..b4cacf4 100644
--- a/tests/Message/FetchPaymentMethodsRequestTest.php
+++ b/tests/Message/FetchPaymentMethodsRequestTest.php
@@ -15,12 +15,10 @@ class FetchPaymentMethodsRequestTest extends TestCase
protected static $expectedRequestUri = 'https://api.mollie.com/v2/methods?amount%5Bvalue%5D=22.56&amount%5Bcurrency%5D=SEK&billingCountry=SE&locale=sv_SE&resource=orders&includeWallets=applepay&sequenceType=oneoff';
- /**
- * @var FetchPaymentMethodsRequest
- */
+ /** @var FetchPaymentMethodsRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchPaymentMethodsRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
@@ -59,7 +57,7 @@ public function testOptionalParameters()
$this->request->initialize([
'apiKey' => 'mykey',
]);
- $this->assertEmpty(array_filter($this->request->getData()));
+ $this->assertEmpty(\array_filter($this->request->getData()));
$this->request->send();
$this->assertEqualRequest(
new Request('GET', 'https://api.mollie.com/v2/methods'),
diff --git a/tests/Message/FetchProfileRequestTest.php b/tests/Message/FetchProfileRequestTest.php
new file mode 100644
index 0000000..542b598
--- /dev/null
+++ b/tests/Message/FetchProfileRequestTest.php
@@ -0,0 +1,61 @@
+request = new FetchProfileRequest($this->getHttpClient(), $this->getHttpRequest());
+ $this->request->initialize(['apiKey' => 'myKey']);
+ }
+
+ public function testGetData(): void
+ {
+ $data = $this->request->getData();
+
+ self::assertCount(0, $data);
+ }
+
+ public function testSendSuccess(): void
+ {
+ $this->setMockHttpResponse('FetchProfileSuccess.txt');
+ $response = $this->request->send();
+
+ $this->assertEqualRequest(
+ new Request('GET', 'https://api.mollie.com/v2/profiles/me'),
+ $this->getMockClient()->getLastRequest()
+ );
+
+ self::assertInstanceOf(FetchProfileResponse::class, $response);
+
+ self::assertTrue($response->isSuccessful());
+ self::assertSame('pfl_dfgh', $response->getProfileReference());
+ }
+
+ public function testSendFailure(): void
+ {
+ $this->setMockHttpResponse('FetchProfileFailure.txt');
+ $response = $this->request->send();
+
+ $this->assertEqualRequest(
+ new Request('GET', 'https://api.mollie.com/v2/profiles/me'),
+ $this->getMockClient()->getLastRequest()
+ );
+
+ self::assertInstanceOf(FetchProfileResponse::class, $response);
+
+ self::assertFalse($response->isSuccessful());
+ }
+}
diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php
index 47c9176..e343bed 100644
--- a/tests/Message/FetchTransactionRequestTest.php
+++ b/tests/Message/FetchTransactionRequestTest.php
@@ -12,19 +12,17 @@ class FetchTransactionRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var FetchTransactionRequest
- */
+ /** @var FetchTransactionRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
- array(
+ [
'apiKey' => 'mykey',
'transactionReference' => 'tr_WDqYK6vllg',
- )
+ ]
);
}
@@ -35,25 +33,24 @@ public function testGetData()
{
$data = $this->request->getData();
- $this->assertSame("tr_WDqYK6vllg", $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();
+ \assert($response instanceof FetchTransactionResponse);
$this->assertEqualRequest(
new Request(
- "GET",
- "https://api.mollie.com/v2/payments/tr_WDqYK6vllg"
+ '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());
@@ -62,9 +59,9 @@ public function testSendSuccess()
$this->assertTrue($response->isRedirect());
$this->assertFalse($response->isRefunded());
$this->assertFalse($response->isPartialRefunded());
- $this->assertSame("paid", $response->getStatus());
+ $this->assertSame('paid', $response->getStatus());
$this->assertSame('tr_WDqYK6vllg', $response->getTransactionReference());
- $this->assertSame("10.00", $response->getAmount());
+ $this->assertSame('10.00', $response->getAmount());
}
public function testSendExpired()
@@ -74,8 +71,8 @@ public function testSendExpired()
$this->assertEqualRequest(
new Request(
- "GET",
- "https://api.mollie.com/v2/payments/tr_WDqYK6vllg"
+ 'GET',
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg'
),
$this->getMockClient()->getLastRequest()
);
@@ -94,8 +91,8 @@ public function testSendFailure()
$this->assertEqualRequest(
new Request(
- "GET",
- "https://api.mollie.com/v2/payments/tr_WDqYK6vllg"
+ 'GET',
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg'
),
$this->getMockClient()->getLastRequest()
);
diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php
index aac180c..263e57c 100644
--- a/tests/Message/PurchaseRequestTest.php
+++ b/tests/Message/PurchaseRequestTest.php
@@ -1,8 +1,9 @@
request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
- 'apiKey' => 'mykey',
- 'amount' => '12.00',
- 'currency' => 'USD',
- 'issuer' => 'my bank',
- 'description' => 'Description',
- 'returnUrl' => 'https://www.example.com/return',
- 'method' => 'ideal',
- 'metadata' => ['meta'],
- 'locale' => 'fr_FR',
- 'billingEmail' => 'billing-email@example.com',
- ));
+ $this->request->initialize(
+ [
+ 'apiKey' => 'mykey',
+ 'amount' => '12.00',
+ 'currency' => 'USD',
+ 'issuer' => 'my bank',
+ 'description' => 'Description',
+ 'returnUrl' => 'https://www.example.com/return',
+ 'method' => 'ideal',
+ 'metadata' => ['meta'],
+ 'locale' => 'fr_FR',
+ 'billingEmail' => 'billing-email@example.com',
+ 'cardToken' => 'qwe123asd',
+ ]
+ );
}
- /**
- * @throws InvalidRequestException
- */
- public function testGetData()
+ public function testGetData(): void
{
- $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',
- ]);
+ $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',
+ 'cardToken' => 'qwe123asd',
+ ]
+ );
$data = $this->request->getData();
- $this->assertSame(["value" => "12.00", "currency" => "USD"], $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,31 +63,31 @@ public function testGetData()
$this->assertSame('my bank', $data['issuer']);
$this->assertSame('fr_FR', $data['locale']);
$this->assertSame('billing-email@example.com', $data['billingEmail']);
- $this->assertCount(8, $data);
+ $this->assertSame('qwe123asd', $data['cardToken']);
+ $this->assertCount(9, $data);
}
- /**
- * @throws InvalidRequestException
- */
- public function testGetDataWithWebhook()
+ public function testGetDataWithWebhook(): void
{
- $this->request->initialize(array(
- 'apiKey' => 'mykey',
- 'amount' => '12.00',
- 'currency' => 'EUR',
- 'description' => 'Description',
- 'returnUrl' => 'https://www.example.com/return',
- 'paymentMethod' => 'ideal',
- 'metadata' => ['meta'],
- 'issuer' => 'my bank',
- 'locale' => 'fr_FR',
- 'billingEmail' => 'billing-email@example.com',
- 'notifyUrl' => 'https://www.example.com/hook',
- ));
+ $this->request->initialize(
+ [
+ 'apiKey' => 'mykey',
+ 'amount' => '12.00',
+ 'currency' => 'EUR',
+ 'description' => 'Description',
+ 'returnUrl' => 'https://www.example.com/return',
+ 'paymentMethod' => 'ideal',
+ 'metadata' => ['meta'],
+ 'issuer' => 'my bank',
+ 'locale' => 'fr_FR',
+ 'billingEmail' => 'billing-email@example.com',
+ 'notifyUrl' => 'https://www.example.com/hook',
+ ]
+ );
$data = $this->request->getData();
- $this->assertSame(["value" => "12.00", "currency" => "EUR"], $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']);
@@ -97,27 +99,26 @@ public function testGetDataWithWebhook()
$this->assertCount(9, $data);
}
- /**
- * @throws InvalidRequestException
- */
- public function testNoIssuer()
+ public function testNoIssuer(): void
{
- $this->request->initialize(array(
- 'apiKey' => 'mykey',
- 'amount' => '12.00',
- 'currency' => 'SEK',
- 'description' => 'Description',
- 'returnUrl' => 'https://www.example.com/return',
- 'paymentMethod' => 'ideal',
- 'metadata' => ['meta'],
- 'locale' => 'fr_FR',
- 'billingEmail' => 'billing-email@example.com',
- 'notifyUrl' => 'https://www.example.com/hook',
- ));
+ $this->request->initialize(
+ [
+ 'apiKey' => 'mykey',
+ 'amount' => '12.00',
+ 'currency' => 'SEK',
+ 'description' => 'Description',
+ 'returnUrl' => 'https://www.example.com/return',
+ 'paymentMethod' => 'ideal',
+ 'metadata' => ['meta'],
+ 'locale' => 'fr_FR',
+ 'billingEmail' => 'billing-email@example.com',
+ 'notifyUrl' => 'https://www.example.com/hook',
+ ]
+ );
$data = $this->request->getData();
- $this->assertSame(["value" => "12.00", "currency" => "SEK"], $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']);
@@ -128,15 +129,15 @@ public function testNoIssuer()
$this->assertCount(8, $data);
}
- public function testSendSuccess()
+ public function testSendSuccess(): void
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
$response = $this->request->send();
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/payments",
+ 'POST',
+ 'https://api.mollie.com/v2/payments',
[],
'{
"amount":{
@@ -151,13 +152,13 @@ public function testSendSuccess()
],
"issuer":"my bank",
"locale":"fr_FR",
- "billingEmail":"billing-email@example.com"
+ "billingEmail":"billing-email@example.com",
+ "cardToken": "qwe123asd"
}'
),
$this->getMockClient()->getLastRequest()
);
-
$this->assertInstanceOf(PurchaseResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
@@ -174,15 +175,50 @@ public function testSendSuccess()
);
}
- public function testIssuerFailure()
+ public function testSendSuccessWithQrcode(): void
+ {
+ $this->setMockHttpResponse('PurchaseSuccess.txt');
+ $response = $this->request->setInclude('details.qrCode')->send();
+
+ $this->assertEqualRequest(
+ new Request(
+ 'POST',
+ 'https://api.mollie.com/v2/payments?include=details.qrCode',
+ [],
+ '{
+ "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",
+ "cardToken": "qwe123asd"
+ }'
+ ),
+ $this->getMockClient()->getLastRequest()
+ );
+
+ $this->assertInstanceOf(PurchaseResponse::class, $response);
+ $this->assertFalse($response->isSuccessful());
+ $this->assertTrue($response->isRedirect());
+ }
+
+ public function testIssuerFailure(): void
{
$this->setMockHttpResponse('PurchaseIssuerFailure.txt');
$response = $this->request->send();
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/payments"
+ 'POST',
+ 'https://api.mollie.com/v2/payments'
),
$this->getMockClient()->getLastRequest()
);
@@ -193,6 +229,9 @@ public function testIssuerFailure()
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getRedirectUrl());
$this->assertNull($response->getRedirectData());
- $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());
+ $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/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php
index 7ba7d8d..01514f3 100644
--- a/tests/Message/RefundRequestTest.php
+++ b/tests/Message/RefundRequestTest.php
@@ -1,7 +1,9 @@
request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
@@ -28,7 +28,7 @@ public function setUp()
}
/**
- * @throws \Omnipay\Common\Exception\InvalidRequestException
+ * @throws InvalidRequestException
*/
public function testGetData()
{
@@ -36,20 +36,19 @@ public function testGetData()
'apiKey' => 'mykey',
'amount' => '12.00',
'currency' => 'EUR',
- 'transactionReference' => 'tr_WDqYK6vllg'
+ 'transactionReference' => 'tr_WDqYK6vllg',
]);
$data = $this->request->getData();
- $this->assertSame(["value" => "12.00", "currency" => "EUR"], $data['amount']);
+ $this->assertSame(['value' => '12.00', 'currency' => 'EUR'], $data['amount']);
$this->assertCount(1, $data);
}
- /**
- * @expectedException \Omnipay\Common\Exception\InvalidRequestException
- */
public function testGetDataWithoutAmount()
{
+ $this->expectException(InvalidRequestException::class);
+
$this->request->initialize(
[
'apiKey' => 'mykey',
@@ -65,20 +64,19 @@ public function testGetDataWithoutAmount()
public function testSendSuccess()
{
$this->setMockHttpResponse('RefundSuccess.txt');
- /** @var RefundResponse $response */
$response = $this->request->send();
+ \assert($response instanceof RefundResponse);
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds",
+ 'POST',
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds',
[],
'{"amount":{"value":"12.00","currency":"EUR"}}'
),
$this->getMockClient()->getLastRequest()
);
-
$this->assertInstanceOf(RefundResponse::class, $response);
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
@@ -89,11 +87,11 @@ public function testSendSuccess()
public function test401Failure()
{
$this->setMockHttpResponse('Refund401Failure.txt');
- /** @var RefundResponse $response */
$response = $this->request->send();
+ \assert($response instanceof RefundResponse);
$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,13 +103,13 @@ public function test401Failure()
public function test422Failure()
{
$this->setMockHttpResponse('Refund422Failure.txt');
- /** @var RefundResponse $response */
$response = $this->request->send();
+ \assert($response instanceof RefundResponse);
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds",
+ 'POST',
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds',
[],
'{"amount":{"value":"12.00","currency":"EUR"}}'
),
diff --git a/tests/Message/RevokeCustomerMandateRequestTest.php b/tests/Message/RevokeCustomerMandateRequestTest.php
index 9f655a9..a85ed11 100644
--- a/tests/Message/RevokeCustomerMandateRequestTest.php
+++ b/tests/Message/RevokeCustomerMandateRequestTest.php
@@ -12,19 +12,17 @@ class RevokeCustomerMandateRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- * @var RevokeCustomerMandateRequest
- */
+ /** @var RevokeCustomerMandateRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new RevokeCustomerMandateRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
- 'apiKey' => "mykey",
+ 'apiKey' => 'mykey',
'customerReference' => 'cst_bSNBBJBzdG',
- 'mandateId' => "mdt_pWUnw6pkBN",
+ 'mandateId' => 'mdt_pWUnw6pkBN',
]);
}
@@ -34,24 +32,24 @@ public function setUp()
public function testData()
{
$this->request->initialize([
- 'apiKey' => "mykey",
+ 'apiKey' => 'mykey',
'customerReference' => 'cst_bSNBBJBzdG',
- 'mandateId' => "mdt_pWUnw6pkBN",
+ 'mandateId' => 'mdt_pWUnw6pkBN',
]);
$data = $this->request->getData();
- $this->assertSame("cst_bSNBBJBzdG", $data['customerReference']);
- $this->assertSame("mdt_pWUnw6pkBN", $data['mandateId']);
+ $this->assertSame('cst_bSNBBJBzdG', $data['customerReference']);
+ $this->assertSame('mdt_pWUnw6pkBN', $data['mandateId']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('RevokeCustomerMandateSuccess.txt');
- /** @var RevokeCustomerMandateResponse $response */
$response = $this->request->send();
+ \assert($response instanceof RevokeCustomerMandateResponse);
- $this->assertEqualRequest(new Request("DELETE", "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates/mdt_pWUnw6pkBN"), $this->getMockClient()->getLastRequest());
+ $this->assertEqualRequest(new Request('DELETE', 'https://api.mollie.com/v2/customers/cst_bSNBBJBzdG/mandates/mdt_pWUnw6pkBN'), $this->getMockClient()->getLastRequest());
$this->assertInstanceOf(RevokeCustomerMandateResponse::class, $response);
diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php
index 71490c0..5cafbdb 100644
--- a/tests/Message/UpdateCustomerRequestTest.php
+++ b/tests/Message/UpdateCustomerRequestTest.php
@@ -12,24 +12,21 @@ class UpdateCustomerRequestTest extends TestCase
{
use AssertRequestTrait;
- /**
- *
- * @var UpdateCustomerRequest
- */
+ /** @var UpdateCustomerRequest */
protected $request;
- public function setUp()
+ public function setUp(): void
{
$this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
'customerReference' => 'cst_bSNBBJBzdG',
'description' => 'Jane Doe',
'email' => 'john@doe.com',
'locale' => 'nl_NL',
'metadata' => 'Just some meta data.',
- ));
+ ]);
}
/**
@@ -37,17 +34,17 @@ public function setUp()
*/
public function testData()
{
- $this->request->initialize(array(
+ $this->request->initialize([
'apiKey' => 'mykey',
'customerReference' => 'cst_bSNBBJBzdG',
'description' => 'Jane Doe',
'email' => 'john@doe.com',
'metadata' => 'Just some meta data.',
- ));
+ ]);
$data = $this->request->getData();
- $this->assertSame("Jane Doe", $data['name']);
+ $this->assertSame('Jane Doe', $data['name']);
$this->assertSame('john@doe.com', $data['email']);
$this->assertSame('Just some meta data.', $data['metadata']);
$this->assertCount(4, $data);
@@ -57,13 +54,13 @@ public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateCustomerSuccess.txt');
- /** @var UpdateCustomerResponse $response */
$response = $this->request->send();
+ \assert($response instanceof UpdateCustomerResponse);
$this->assertEqualRequest(
new Request(
- "POST",
- "https://api.mollie.com/v2/customers/cst_bSNBBJBzdG",
+ 'POST',
+ 'https://api.mollie.com/v2/customers/cst_bSNBBJBzdG',
[],
'{
"name": "Jane Doe",
@@ -89,10 +86,10 @@ public function testSendFailure()
{
$this->setMockHttpResponse('UpdateCustomerFailure.txt');
- /** @var UpdateCustomerResponse $response */
$response = $this->request->send();
+ \assert($response instanceof UpdateCustomerResponse);
- $this->assertEqualRequest(new Request("POST", "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());
diff --git a/tests/Mock/CreateOrderRequest.txt b/tests/Mock/CreateOrderRequest.txt
index d97cbeb..1b330eb 100644
--- a/tests/Mock/CreateOrderRequest.txt
+++ b/tests/Mock/CreateOrderRequest.txt
@@ -36,6 +36,9 @@
"consumerDateOfBirth": "1958-01-31",
"locale": "nl_NL",
"orderNumber": "1337",
+ "payment": {
+ "cardToken": "qwe123asd"
+ },
"redirectUrl": "https://example.org/redirect",
"webhookUrl": "https://example.org/webhook",
"method": "klarnapaylater",
@@ -87,4 +90,4 @@
}
}
]
- }
\ No newline at end of file
+ }
diff --git a/tests/Mock/FetchProfileFailure.txt b/tests/Mock/FetchProfileFailure.txt
new file mode 100644
index 0000000..b3e3c99
--- /dev/null
+++ b/tests/Mock/FetchProfileFailure.txt
@@ -0,0 +1,14 @@
+HTTP/1.1 403 Forbidden
+Content-Type: application/hal+json
+
+{
+ "status": 403,
+ "title": "Forbidden",
+ "detail": "This API endpoint is only available with an OAuth access token and cannot be accessed with an API key.",
+ "_links": {
+ "documentation": {
+ "href": "https://docs.mollie.com/overview/handling-errors",
+ "type": "text/html"
+ }
+ }
+}
diff --git a/tests/Mock/FetchProfileSuccess.txt b/tests/Mock/FetchProfileSuccess.txt
new file mode 100644
index 0000000..1bf8d7a
--- /dev/null
+++ b/tests/Mock/FetchProfileSuccess.txt
@@ -0,0 +1,50 @@
+HTTP/1.1 200 OK
+Content-Type: application/hal+json
+
+{
+ "resource": "profile",
+ "id": "pfl_dfgh",
+ "mode": "live",
+ "name": "F. Bar",
+ "website": "http://foo.bar/",
+ "email": "foo@bar.nl",
+ "phone": "+31612345678",
+ "categoryCode": 5732,
+ "businessCategory": null,
+ "status": "verified",
+ "createdAt": "2010-06-01T13:08:53+00:00",
+ "_links": {
+ "self": {
+ "href": "https://api.mollie.com/v2/profiles/pfl_dfgh?testmode=true",
+ "type": "application/hal+json"
+ },
+ "dashboard": {
+ "href": "https://www.mollie.com/dashboard/org_789/settings/profiles/pfl_dfgh",
+ "type": "text/html"
+ },
+ "chargebacks": {
+ "href": "https://api.mollie.com/v2/chargebacks",
+ "type": "application/hal+json"
+ },
+ "methods": {
+ "href": "https://api.mollie.com/v2/methods",
+ "type": "application/hal+json"
+ },
+ "payments": {
+ "href": "https://api.mollie.com/v2/payments",
+ "type": "application/hal+json"
+ },
+ "refunds": {
+ "href": "https://api.mollie.com/v2/refunds",
+ "type": "application/hal+json"
+ },
+ "checkoutPreviewUrl": {
+ "href": "https://www.mollie.com/payscreen/preview/pfl_dfgh",
+ "type": "text/html"
+ },
+ "documentation": {
+ "href": "https://docs.mollie.com/reference/v2/profiles-api/get-profile-me",
+ "type": "text/html"
+ }
+ }
+}