From 26c1660405b76b8069551eeed447ef43172a5c24 Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 27 Feb 2024 15:14:58 +0000 Subject: [PATCH 01/17] Bump dependencies for Laravel 11 --- composer.json | 170 +++++++++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/composer.json b/composer.json index ba8a5f7..80d3142 100644 --- a/composer.json +++ b/composer.json @@ -1,88 +1,88 @@ { - "name": "mollie/laravel-mollie", - "description": "Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite", - "homepage": "https://github.com/mollie/laravel-mollie", - "license": "BSD-2-Clause", - "authors": [ - { - "name": "Mollie B.V.", - "email": "info@mollie.com" - } - ], - "keywords": [ - "mollie", - "payment", - "service", - "ideal", - "creditcard", - "apple pay", - "mistercash", - "bancontact", - "sofort", - "sofortbanking", - "sepa", - "paypal", - "paysafecard", - "podiumcadeaukaart", - "banktransfer", - "direct debit", - "belfius", - "belfius direct net", - "przelewy24", - "refunds", - "api", - "payments", - "gateway", - "subscriptions", - "recurring", - "charges", - "laravel", - "lumen", - "socialite" - ], - "require": { - "php": "^8.0", - "mollie/mollie-api-php": "^2.60", - "illuminate/support": "^9.0|^10.0", - "ext-json": "*" - }, - "require-dev": { - "mockery/mockery": "^1.4", - "orchestra/testbench": "^7.18|^8.0", - "phpunit/phpunit": "^9.0|^10.0", - "laravel/socialite": "^5.5", - "laravel/pint": "^1.1" - }, - "suggest": { - "laravel/socialite": "Use Mollie Connect (OAuth) to authenticate via Laravel Socialite with the Mollie API. This is needed for some endpoints." - }, - "autoload": { - "psr-4": { - "Mollie\\Laravel\\": "src/" + "name": "mollie/laravel-mollie", + "description": "Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite", + "homepage": "https://github.com/mollie/laravel-mollie", + "license": "BSD-2-Clause", + "authors": [ + { + "name": "Mollie B.V.", + "email": "info@mollie.com" + } + ], + "keywords": [ + "mollie", + "payment", + "service", + "ideal", + "creditcard", + "apple pay", + "mistercash", + "bancontact", + "sofort", + "sofortbanking", + "sepa", + "paypal", + "paysafecard", + "podiumcadeaukaart", + "banktransfer", + "direct debit", + "belfius", + "belfius direct net", + "przelewy24", + "refunds", + "api", + "payments", + "gateway", + "subscriptions", + "recurring", + "charges", + "laravel", + "lumen", + "socialite" + ], + "require": { + "php": "^8.0", + "mollie/mollie-api-php": "^2.60", + "illuminate/support": "^9.0|^10.0|^11.0", + "ext-json": "*" }, - "files": [ - "src/helpers.php" - ] - }, - "autoload-dev": { - "psr-4": { - "Mollie\\Laravel\\Tests\\": "tests/" - } - }, - "extra": { - "laravel": { - "providers": [ - "Mollie\\Laravel\\MollieServiceProvider" - ], - "aliases": { - "Mollie": "Mollie\\Laravel\\Facades\\Mollie" - } - } - }, - "scripts": { - "test": "./vendor/bin/phpunit tests", - "format": "./vendor/bin/pint" - }, - "minimum-stability": "dev", - "prefer-stable": true + "require-dev": { + "mockery/mockery": "^1.4", + "orchestra/testbench": "^7.18|^8.0|^9.0", + "phpunit/phpunit": "^9.0|^10.0", + "laravel/socialite": "^5.5", + "laravel/pint": "^1.1" + }, + "suggest": { + "laravel/socialite": "Use Mollie Connect (OAuth) to authenticate via Laravel Socialite with the Mollie API. This is needed for some endpoints." + }, + "autoload": { + "psr-4": { + "Mollie\\Laravel\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Mollie\\Laravel\\Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Mollie\\Laravel\\MollieServiceProvider" + ], + "aliases": { + "Mollie": "Mollie\\Laravel\\Facades\\Mollie" + } + } + }, + "scripts": { + "test": "./vendor/bin/phpunit tests", + "format": "./vendor/bin/pint" + }, + "minimum-stability": "dev", + "prefer-stable": true } From 4067b0e77e8a5cf28704dfb72d17139319952645 Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 27 Feb 2024 15:14:58 +0000 Subject: [PATCH 02/17] Update GitHub Actions for Laravel 11 --- .github/workflows/tests.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3824e48..38d88d6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,5 @@ name: tests + on: push: pull_request: @@ -7,16 +8,20 @@ on: jobs: tests: - runs-on: ubuntu-latest + strategy: fail-fast: true matrix: php: ['8.0', '8.1', '8.2', '8.3'] - laravel: ['9.0', '10.0'] + laravel: ['9.0', '10.0', '11.0'] exclude: - laravel: '10.0' php: '8.0' + - laravel: '11.0' + php: '8.0' + - laravel: '11.0' + php: '8.1' name: P${{ matrix.php }} - L${{ matrix.laravel }} From 6dbb3b4549362bfb27d8103e9c32014fc396cba0 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 1 Mar 2024 13:25:18 +0100 Subject: [PATCH 03/17] wip --- .github/workflows/pint.yml | 4 +- .github/workflows/tests.yml | 18 +- README.md | 3 - composer.json | 169 +++++----- src/Facades/Mollie.php | 4 +- src/MollieManager.php | 4 +- src/MollieServiceProvider.php | 80 +---- src/Wrappers/MollieApiWrapper.php | 526 +++++++++--------------------- src/helpers.php | 11 - tests/Facades/MollieTest.php | 2 +- tests/HelpersTest.php | 13 - tests/TempHelpers/FacadeTrait.php | 15 - 12 files changed, 271 insertions(+), 578 deletions(-) delete mode 100644 src/helpers.php delete mode 100644 tests/HelpersTest.php diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 987c9b6..aadc6bb 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} @@ -22,6 +22,6 @@ jobs: run: pint - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Fix styling diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 38d88d6..2936c92 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" jobs: tests: @@ -13,21 +13,19 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.0', '8.1', '8.2', '8.3'] - laravel: ['9.0', '10.0', '11.0'] + php: ["8.1", "8.2", "8.3"] + laravel: ["10.0", "11.0"] exclude: - - laravel: '10.0' - php: '8.0' - - laravel: '11.0' - php: '8.0' - - laravel: '11.0' - php: '8.1' + - laravel: "11.0" + php: "8.0" + - laravel: "11.0" + php: "8.1" name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index 8194fca..51b11ef 100644 --- a/README.md +++ b/README.md @@ -118,9 +118,6 @@ For your convencience we've added the global `mollie()` helper function. It's an ```php // Using facade accessor $payment = \Mollie\Laravel\Facades\Mollie::api()->payments->get($payment_id); - -// Using global helper function -$payment = mollie()->payments->get($payment_id); ``` ## Other examples diff --git a/composer.json b/composer.json index 80d3142..372a639 100644 --- a/composer.json +++ b/composer.json @@ -1,88 +1,85 @@ { - "name": "mollie/laravel-mollie", - "description": "Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite", - "homepage": "https://github.com/mollie/laravel-mollie", - "license": "BSD-2-Clause", - "authors": [ - { - "name": "Mollie B.V.", - "email": "info@mollie.com" - } - ], - "keywords": [ - "mollie", - "payment", - "service", - "ideal", - "creditcard", - "apple pay", - "mistercash", - "bancontact", - "sofort", - "sofortbanking", - "sepa", - "paypal", - "paysafecard", - "podiumcadeaukaart", - "banktransfer", - "direct debit", - "belfius", - "belfius direct net", - "przelewy24", - "refunds", - "api", - "payments", - "gateway", - "subscriptions", - "recurring", - "charges", - "laravel", - "lumen", - "socialite" - ], - "require": { - "php": "^8.0", - "mollie/mollie-api-php": "^2.60", - "illuminate/support": "^9.0|^10.0|^11.0", - "ext-json": "*" - }, - "require-dev": { - "mockery/mockery": "^1.4", - "orchestra/testbench": "^7.18|^8.0|^9.0", - "phpunit/phpunit": "^9.0|^10.0", - "laravel/socialite": "^5.5", - "laravel/pint": "^1.1" - }, - "suggest": { - "laravel/socialite": "Use Mollie Connect (OAuth) to authenticate via Laravel Socialite with the Mollie API. This is needed for some endpoints." - }, - "autoload": { - "psr-4": { - "Mollie\\Laravel\\": "src/" - }, - "files": [ - "src/helpers.php" - ] - }, - "autoload-dev": { - "psr-4": { - "Mollie\\Laravel\\Tests\\": "tests/" - } - }, - "extra": { - "laravel": { - "providers": [ - "Mollie\\Laravel\\MollieServiceProvider" - ], - "aliases": { - "Mollie": "Mollie\\Laravel\\Facades\\Mollie" - } - } - }, - "scripts": { - "test": "./vendor/bin/phpunit tests", - "format": "./vendor/bin/pint" - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "mollie/laravel-mollie", + "description": "Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite", + "homepage": "https://github.com/mollie/laravel-mollie", + "license": "BSD-2-Clause", + "authors": [ + { + "name": "Mollie B.V.", + "email": "info@mollie.com" + } + ], + "keywords": [ + "mollie", + "payment", + "service", + "ideal", + "creditcard", + "apple pay", + "mistercash", + "bancontact", + "sofort", + "sofortbanking", + "sepa", + "paypal", + "paysafecard", + "podiumcadeaukaart", + "banktransfer", + "direct debit", + "belfius", + "belfius direct net", + "przelewy24", + "refunds", + "api", + "payments", + "gateway", + "subscriptions", + "recurring", + "charges", + "laravel", + "lumen", + "socialite" + ], + "require": { + "php": "^8.1|^8.2", + "mollie/mollie-api-php": "^2.60", + "illuminate/support": "^10.0|^11.0", + "ext-json": "*" + }, + "require-dev": { + "mockery/mockery": "^1.4", + "orchestra/testbench": "^8.0|^9.0", + "phpunit/phpunit": "^10.0", + "laravel/socialite": "^5.5", + "laravel/pint": "^1.1" + }, + "suggest": { + "laravel/socialite": "Use Mollie Connect (OAuth) to authenticate via Laravel Socialite with the Mollie API. This is needed for some endpoints." + }, + "autoload": { + "psr-4": { + "Mollie\\Laravel\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Mollie\\Laravel\\Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Mollie\\Laravel\\MollieServiceProvider" + ], + "aliases": { + "Mollie": "Mollie\\Laravel\\Facades\\Mollie" + } + } + }, + "scripts": { + "test": "./vendor/bin/phpunit tests", + "format": "./vendor/bin/pint" + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Facades/Mollie.php b/src/Facades/Mollie.php index 8ce97af..c8dd2cb 100644 --- a/src/Facades/Mollie.php +++ b/src/Facades/Mollie.php @@ -1,4 +1,5 @@ app['mollie.api']; + return $this->app->make(MollieApiWrapper::class); } } diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index 58ac478..6dc5687 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -1,4 +1,5 @@ app instanceof LaravelApplication && $this->app->runningInConsole()) { @@ -84,8 +85,8 @@ protected function setupConfig() */ protected function extendSocialite() { - if (interface_exists('Laravel\Socialite\Contracts\Factory')) { - $socialite = $this->app->make('Laravel\Socialite\Contracts\Factory'); + if (interface_exists($socialiteFactoryClass = \Laravel\Socialite\Contracts\Factory::class)) { + $socialite = $this->app->make($socialiteFactoryClass); $socialite->extend('mollie', function (Container $app) use ($socialite) { $config = $app['config']['services.mollie']; @@ -102,67 +103,14 @@ protected function extendSocialite() */ public function register() { - $this->registerApiClient(); - $this->registerApiAdapter(); - $this->registerManager(); - } - - /** - * Register the Mollie API adapter class. - * - * @return void - */ - protected function registerApiAdapter() - { - $this->app->singleton('mollie.api', function (Container $app) { - $config = $app['config']; - - return new MollieApiWrapper($config, $app['mollie.api.client']); - }); - - $this->app->alias('mollie.api', MollieApiWrapper::class); - } - - /** - * Register the Mollie API Client. - * - * @return void - */ - protected function registerApiClient() - { - $this->app->singleton('mollie.api.client', function () { - return (new MollieApiClient(new MollieLaravelHttpClientAdapter)) - ->addVersionString('MollieLaravel/'.self::PACKAGE_VERSION); - }); - - $this->app->alias('mollie.api.client', MollieApiClient::class); - } - - /** - * Register the manager class. - * - * @return void - */ - public function registerManager() - { - $this->app->singleton('mollie', function (Container $app) { - return new MollieManager($app); - }); - - $this->app->alias('mollie', MollieManager::class); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return [ - 'mollie', - 'mollie.api', - 'mollie.api.client', - ]; + $this->app->singleton(MollieManager::class); + $this->app->singleton(MollieApiWrapper::class); + $this->app->singleton( + MollieApiClient::class, + function () { + return (new MollieApiClient(new MollieLaravelHttpClientAdapter)) + ->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION); + } + ); } } diff --git a/src/Wrappers/MollieApiWrapper.php b/src/Wrappers/MollieApiWrapper.php index 6351465..a71b748 100644 --- a/src/Wrappers/MollieApiWrapper.php +++ b/src/Wrappers/MollieApiWrapper.php @@ -35,14 +35,105 @@ namespace Mollie\Laravel\Wrappers; use Illuminate\Contracts\Config\Repository; -use Mollie\Api\Exceptions\ApiException; +use Illuminate\Support\Traits\ForwardsCalls; use Mollie\Api\MollieApiClient; /** * Class MollieApiWrapper. + * + * @property-read \Mollie\Api\Endpoints\BalanceEndpoint $balanceReports + * @property-read \Mollie\Api\Endpoints\BalanceEndpoint $balances + * @property-read \Mollie\Api\Endpoints\BalanceTransactionEndpoint $balanceTransactions + * @property-read \Mollie\Api\Endpoints\ChargebackEndpoint $chargebacks + * @property-read \Mollie\Api\Endpoints\ClientLinkEndpoint $clientLinks + * @property-read \Mollie\Api\Endpoints\ClientEndpoint $clients + * @property-read \Mollie\Api\Endpoints\CustomerPaymentEndpoint $customerPayments + * @property-read \Mollie\Api\Endpoints\CustomerEndpoint $customers + * @property-read \Mollie\Api\Endpoints\InvoiceEndpoint $invoices + * @property-read \Mollie\Api\Endpoints\OnboardingEndpoint $onboarding + * @property-read \Mollie\Api\Endpoints\OrderLineEndpoint $orderLines + * @property-read \Mollie\Api\Endpoints\OrderPaymentEndpoint $orderPayments + * @property-read \Mollie\Api\Endpoints\OrderRefundEndpoint $orderRefunds + * @property-read \Mollie\Api\Endpoints\OrderEndpoint $orders + * @property-read \Mollie\Api\Endpoints\OrganizationPartnerEndpoint $organizationPartners + * @property-read \Mollie\Api\Endpoints\OrganizationEndpoint $organizations + * @property-read \Mollie\Api\Endpoints\PaymentCaptureEndpoint $paymentCaptures + * @property-read \Mollie\Api\Endpoints\PaymentChargebackEndpoint $paymentChargebacks + * @property-read \Mollie\Api\Endpoints\PaymentLinkEndpoint $paymentLinks + * @property-read \Mollie\Api\Endpoints\PaymentRefundEndpoint $paymentRefunds + * @property-read \Mollie\Api\Endpoints\PaymentRouteEndpoint $paymentRoutes + * @property-read \Mollie\Api\Endpoints\PaymentEndpoint $payments + * @property-read \Mollie\Api\Endpoints\PermissionEndpoint $permissions + * @property-read \Mollie\Api\Endpoints\ProfileMethodEndpoint $profileMethods + * @property-read \Mollie\Api\Endpoints\ProfileEndpoint $profiles + * @property-read \Mollie\Api\Endpoints\MandateEndpoint $mandates + * @property-read \Mollie\Api\Endpoints\MethodEndpoint $methods + * @property-read \Mollie\Api\Endpoints\RefundEndpoint $refunds + * @property-read \Mollie\Api\Endpoints\SettlementCaptureEndpoint $settlementCaptures + * @property-read \Mollie\Api\Endpoints\SettlementChargebackEndpoint $settlementChargebacks + * @property-read \Mollie\Api\Endpoints\SettlementPaymentEndpoint $settlementPayments + * @property-read \Mollie\Api\Endpoints\SettlementRefundEndpoint $settlementRefunds + * @property-read \Mollie\Api\Endpoints\SettlementEndpoint $settlements + * @property-read \Mollie\Api\Endpoints\ShipmentEndpoint $shipments + * @property-read \Mollie\Api\Endpoints\SubscriptionEndpoint $subscriptions + * @property-read \Mollie\Api\Endpoints\TerminalEndpoint $terminals + * @property-read \Mollie\Api\Endpoints\WalletEndpoint $wallets + * @method \Mollie\Api\Endpoints\BalanceEndpoint balanceReports() + * @method \Mollie\Api\Endpoints\BalanceEndpoint balances() + * @method \Mollie\Api\Endpoints\BalanceTransactionEndpoint balanceTransactions() + * @method \Mollie\Api\Endpoints\ChargebackEndpoint chargebacks() + * @method \Mollie\Api\Endpoints\ClientLinkEndpoint clientLinks() + * @method \Mollie\Api\Endpoints\ClientEndpoint clients() + * @method \Mollie\Api\Endpoints\CustomerPaymentEndpoint customerPayments() + * @method \Mollie\Api\Endpoints\CustomerEndpoint customers() + * @method \Mollie\Api\Endpoints\InvoiceEndpoint invoices() + * @method \Mollie\Api\Endpoints\OnboardingEndpoint onboarding() + * @method \Mollie\Api\Endpoints\OrderLineEndpoint orderLines() + * @method \Mollie\Api\Endpoints\OrderPaymentEndpoint orderPayments() + * @method \Mollie\Api\Endpoints\OrderRefundEndpoint orderRefunds() + * @method \Mollie\Api\Endpoints\OrderEndpoint orders() + * @method \Mollie\Api\Endpoints\OrganizationPartnerEndpoint organizationPartners() + * @method \Mollie\Api\Endpoints\OrganizationEndpoint organizations() + * @method \Mollie\Api\Endpoints\PaymentCaptureEndpoint paymentCaptures() + * @method \Mollie\Api\Endpoints\PaymentChargebackEndpoint paymentChargebacks() + * @method \Mollie\Api\Endpoints\PaymentLinkEndpoint paymentLinks() + * @method \Mollie\Api\Endpoints\PaymentRefundEndpoint paymentRefunds() + * @method \Mollie\Api\Endpoints\PaymentRouteEndpoint paymentRoutes() + * @method \Mollie\Api\Endpoints\PaymentEndpoint payments() + * @method \Mollie\Api\Endpoints\PermissionEndpoint permissions() + * @method \Mollie\Api\Endpoints\ProfileMethodEndpoint profileMethods() + * @method \Mollie\Api\Endpoints\ProfileEndpoint profiles() + * @method \Mollie\Api\Endpoints\MandateEndpoint mandates() + * @method \Mollie\Api\Endpoints\MethodEndpoint methods() + * @method \Mollie\Api\Endpoints\RefundEndpoint refunds() + * @method \Mollie\Api\Endpoints\SettlementCaptureEndpoint settlementCaptures() + * @method \Mollie\Api\Endpoints\SettlementChargebackEndpoint settlementChargebacks() + * @method \Mollie\Api\Endpoints\SettlementPaymentEndpoint settlementPayments() + * @method \Mollie\Api\Endpoints\SettlementRefundEndpoint settlementRefunds() + * @method \Mollie\Api\Endpoints\SettlementEndpoint settlements() + * @method \Mollie\Api\Endpoints\ShipmentEndpoint shipments() + * @method \Mollie\Api\Endpoints\SubscriptionEndpoint subscriptions() + * @method \Mollie\Api\Endpoints\TerminalEndpoint terminals() + * @method \Mollie\Api\Endpoints\WalletEndpoint wallets() + * @method MollieApiWrapper setApiEndpoint(string $url) + * @method string getApiEndpoint() + * @method string getVersionStrings() + * @method MollieApiWrapper setApiKey(string $apiKey) + * @method MollieApiWrapper setAccessToken(string $accessToken) + * @method ?bool usesOAuth() + * @method MollieApiWrapper addVersionString(string $versionString) + * @method void enableDebugging() + * @method void disableDebugging() + * @method MollieApiWrapper setIdempotencyKey(string $key) + * @method string getIdempotencyKey() + * @method MollieApiWrapper resetIdempotencyKey() + * @method MollieApiWrapper setIdempotencyKeyGenerator(\Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator) + * @method MollieApiWrapper clearIdempotencyKeyGenerator() */ class MollieApiWrapper { + use ForwardsCalls; + /** * @var Repository */ @@ -53,6 +144,46 @@ class MollieApiWrapper */ protected $client; + protected static $supportedClientEndpoints = [ + 'balanceReports', + 'balances', + 'balanceTransactions', + 'chargebacks', + 'clientLinks', + 'clients', + 'customerPayments', + 'customers', + 'invoices', + 'onboarding', + 'orderLines', + 'orderPayments', + 'orderRefunds', + 'orders', + 'organizationPartners', + 'organizations', + 'paymentCaptures', + 'paymentChargebacks', + 'paymentLinks', + 'paymentRefunds', + 'paymentRoutes', + 'payments', + 'permissions', + 'profileMethods', + 'profiles', + 'mandates', + 'methods', + 'refunds', + 'settlementCaptures', + 'settlementChargebacks', + 'settlementPayments', + 'settlementRefunds', + 'settlements', + 'shipments', + 'subscriptions', + 'terminals', + 'wallets', + ]; + /** * MollieApiWrapper constructor. * @@ -67,393 +198,50 @@ public function __construct(Repository $config, MollieApiClient $client) $key = $this->config->get('mollie.key'); - if (! empty($key)) { - $this->setApiKey($key); + if (!empty($key)) { + $this->client->setApiKey($key); } } /** - * @param string $url - */ - public function setApiEndpoint($url) - { - $this->client->setApiEndpoint($url); - } - - /** - * @return string - */ - public function getApiEndpoint() - { - return $this->client->getApiEndpoint(); - } - - /** - * @param string $api_key The Mollie API key, starting with 'test_' or 'live_' - * - * @throws ApiException - */ - public function setApiKey($api_key) - { - $this->client->setApiKey($api_key); - } - - /** - * @param string $access_token OAuth access token, starting with 'access_' + * Handle dynamic property calls. * - * @throws ApiException - */ - public function setAccessToken($access_token) - { - $this->client->setAccessToken($access_token); - } - - /** - * @return bool - */ - public function usesOAuth() - { - return $this->client->usesOAuth(); - } - - /** - * @return \Mollie\Laravel\Wrappers\MollieApiWrapper - */ - public function addVersionString($version_string) - { - $this->client->addVersionString($version_string); - - return $this; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentEndpoint - */ - public function payments() - { - return $this->client->payments; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentRefundEndpoint - */ - public function paymentRefunds() - { - return $this->client->paymentRefunds; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentRouteEndpoint - */ - public function paymentRoutes() - { - return $this->client->paymentRoutes; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentCaptureEndpoint - */ - public function paymentCaptures() - { - return $this->client->paymentCaptures; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentLinkEndpoint - */ - public function paymentLinks() - { - return $this->client->paymentLinks; - } - - /** - * @return \Mollie\Api\Endpoints\TerminalEndpoint - */ - public function terminals() - { - return $this->client->terminals; - } - - /** - * @return \Mollie\Api\Endpoints\MethodEndpoint - */ - public function methods() - { - return $this->client->methods; - } - - /** - * @return \Mollie\Api\Endpoints\ProfileMethodEndpoint - */ - public function profileMethods() - { - return $this->client->profileMethods; - } - - /** - * @return \Mollie\Api\Endpoints\CustomerEndpoint - */ - public function customers() - { - return $this->client->customers; - } - - /** - * @return \Mollie\Api\Endpoints\BalanceEndpoint - */ - public function balances() - { - return $this->client->balances; - } - - /** - * @return \Mollie\Api\Endpoints\BalanceTransactionEndpoint - */ - public function balanceTransactions() - { - return $this->client->balanceTransactions; - } - - /** - * @return \Mollie\Api\Endpoints\BalanceReportEndpoint - */ - public function balanceReports() - { - return $this->client->balanceReports; - } - - /** - * @return \Mollie\Api\Endpoints\SettlementsEndpoint - */ - public function settlements() - { - return $this->client->settlements; - } - - /** - * @return \Mollie\Api\Endpoints\SettlementPaymentEndpoint - */ - public function settlementPayments() - { - return $this->client->settlementPayments; - } - - /** - * @return \Mollie\Api\Endpoints\SubscriptionEndpoint - */ - public function subscriptions() - { - return $this->client->subscriptions; - } - - /** - * @return \Mollie\Api\Endpoints\CustomerPaymentsEndpoint - */ - public function customerPayments() - { - return $this->client->customerPayments; - } - - /** - * @return \Mollie\Api\Endpoints\MandateEndpoint - */ - public function mandates() - { - return $this->client->mandates; - } - - /** - * @return \Mollie\Api\Endpoints\OrganizationEndpoint - */ - public function organizations() - { - return $this->client->organizations; - } - - /** - * @return \Mollie\Api\Endpoints\PermissionEndpoint - */ - public function permissions() - { - return $this->client->permissions; - } - - /** - * @return \Mollie\Api\Endpoints\InvoiceEndpoint - */ - public function invoices() - { - return $this->client->invoices; - } - - /** - * @return \Mollie\Api\Endpoints\ProfileEndpoint - */ - public function profiles() - { - return $this->client->profiles; - } - - /** - * @return \Mollie\Api\Endpoints\ShipmentEndpoint - */ - public function shipments() - { - return $this->client->shipments; - } - - /** - * @return \Mollie\Api\Endpoints\RefundEndpoint - */ - public function refunds() - { - return $this->client->refunds; - } - - /** - * @return \Mollie\Api\Endpoints\ChargebackEndpoint - */ - public function chargebacks() - { - return $this->client->chargebacks; - } - - /** - * @return \Mollie\Api\Endpoints\PaymentChargebackEndpoint - */ - public function paymentChargebacks() - { - return $this->client->paymentChargebacks; - } - - /** - * @return \Mollie\Api\Endpoints\OrderEndpoint - */ - public function orders() - { - return $this->client->orders; - } - - /** - * @return \Mollie\Api\Endpoints\OrderLineEndpoint - */ - public function orderLines() - { - return $this->client->orderLines; - } - - /** - * @return \Mollie\Api\Endpoints\OrderPaymentEndpoint - */ - public function orderPayments() - { - return $this->client->orderPayments; - } - - /** - * @return \Mollie\Api\Endpoints\OrderRefundEndpoint - */ - public function orderRefunds() - { - return $this->client->orderRefunds; - } - - /** - * @return \Mollie\Api\Endpoints\OnboardingEndpoint - */ - public function onboarding() - { - return $this->client->onboarding; - } - - /** - * @return \Mollie\Api\Endpoints\WalletEndpoint - */ - public function wallets() - { - return $this->client->wallets; - } - - /** - * @return \Mollie\Api\Endpoints\ClientEndpoint + * @param string $property + * @return mixed */ - public function clients() + public function __get($property) { - return $this->client->clients; - } + if ($this->endpointPropertyExists($property)) { + return $this->client->{$property}; + } - /** - * @return \Mollie\Api\Endpoints\ClientLinkEndpoint - */ - public function clientLinks() - { - return $this->client->clientLinks; - } + $message = '%s has no endpoint "%s".'; - /** - * @return \Mollie\Api\Endpoints\OrganizationPartnerEndpoint - */ - public function organizationPartners() - { - return $this->client->organizationPartners; + throw new \Error( + sprintf($message, static::class, $property) + ); } /** - * @return void + * Handle dynamic method calls into the Mollie API client. * - * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException - */ - public function enableDebugging() - { - $this->client->enableDebugging(); - } - - /** - * @return void + * @param string $method + * @param array $parameters + * @return mixed * - * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException + * @throws \Mollie\Api\Exceptions\ApiException */ - public function disableDebugging() - { - $this->client->disableDebugging(); - } - - public function setIdempotencyKey(string $key) + public function __call($method, $parameters) { - return $this->client->setIdempotencyKey($key); - } - - public function resetIdempotencyKey() - { - return $this->client->resetIdempotencyKey(); - } - - public function setIdempotencyKeyGenerator($generator) - { - return $this->client->setIdempotencyKeyGenerator($generator); - } + if ($this->endpointPropertyExists($method)) { + return $this->client->{$method}; + } - public function clearIdempotencyKeyGenerator() - { - return $this->client->clearIdempotencyKeyGenerator(); + return $this->forwardDecoratedCallTo($this->client, $method, $parameters); } - /** - * Handle dynamic property calls. - * - * @param string $property - * @return mixed - */ - public function __get($property) + private function endpointPropertyExists(string $property): bool { - if (method_exists($this, $property)) { - return call_user_func([$this, $property]); - } - - $message = '%s has no property or method "%s".'; - - throw new \Error( - sprintf($message, static::class, $property) - ); + return in_array($property, static::$supportedClientEndpoints); } } diff --git a/src/helpers.php b/src/helpers.php deleted file mode 100644 index c972e59..0000000 --- a/src/helpers.php +++ /dev/null @@ -1,11 +0,0 @@ -assertTrue(function_exists('mollie')); - - $this->assertInstanceOf('\Mollie\Laravel\Wrappers\MollieApiWrapper', mollie()); - } -} diff --git a/tests/TempHelpers/FacadeTrait.php b/tests/TempHelpers/FacadeTrait.php index 5eb6466..2640d6f 100644 --- a/tests/TempHelpers/FacadeTrait.php +++ b/tests/TempHelpers/FacadeTrait.php @@ -73,19 +73,4 @@ public function testFacadeRoot() $this->assertInstanceOf($root, $method->invoke(null), $msg); } - - public function testServiceProvider() - { - $accessor = $this->getFacadeAccessor(); - $provider = $this->getServiceProviderClass($this->app); - - if ($provider) { - $reflection = new ReflectionClass($provider); - $method = $reflection->getMethod('provides'); - $method->setAccessible(true); - - $msg = "Expected class '$provider' to provide '$accessor'."; - $this->assertContains($accessor, $method->invoke(new $provider($this->app)), $msg); - } - } } From 4a3a46b3abcd0a262a256908466fb7b322e42c88 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 7 Mar 2024 10:52:45 +0100 Subject: [PATCH 04/17] drop lumen support --- src/MollieServiceProvider.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index 6dc5687..6a2620e 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -35,9 +35,7 @@ namespace Mollie\Laravel; use Illuminate\Contracts\Container\Container; -use Illuminate\Foundation\Application as LaravelApplication; use Illuminate\Support\ServiceProvider; -use Laravel\Lumen\Application as LumenApplication; use Mollie\Api\MollieApiClient; use Mollie\Laravel\Wrappers\MollieApiWrapper; @@ -68,11 +66,8 @@ protected function setupConfig() { $source = realpath(__DIR__ . '/../config/mollie.php'); - // Check if the application is a Laravel OR Lumen instance to properly merge the configuration file. - if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { + if ($this->app->runningInConsole()) { $this->publishes([$source => config_path('mollie.php')]); - } elseif ($this->app instanceof LumenApplication) { - $this->app->configure('mollie'); } $this->mergeConfigFrom($source, 'mollie'); From 24c14e4993b9737aa3a2832841f1a8ed85de6f31 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 7 Mar 2024 12:37:13 +0100 Subject: [PATCH 05/17] wip --- UPGRADE.md | 21 ++ src/Facades/Mollie.php | 57 +++- src/MollieConnectProvider.php | 69 +---- src/MollieLaravelHttpClientAdapter.php | 20 +- src/MollieManager.php | 67 ----- src/MollieServiceProvider.php | 13 +- src/Wrappers/MollieApiWrapper.php | 247 ------------------ tests/Facades/MollieTest.php | 46 ---- tests/MollieApiClientTest.php | 49 ++++ tests/MollieConnectProviderTest.php | 73 ------ ...=> MollieLaravelHttpClientAdapterTest.php} | 6 +- tests/MollieManagerTest.php | 37 --- tests/MollieServiceProviderTest.php | 31 --- tests/TempHelpers/FacadeTrait.php | 76 ------ tests/TempHelpers/LaravelTrait.php | 67 ----- tests/TempHelpers/MockeryTrait.php | 30 --- tests/TempHelpers/ServiceProviderTrait.php | 44 ---- tests/TestCase.php | 12 - tests/Wrappers/MollieApiWrapperTest.php | 230 ---------------- 19 files changed, 144 insertions(+), 1051 deletions(-) create mode 100644 UPGRADE.md delete mode 100644 src/MollieManager.php delete mode 100644 src/Wrappers/MollieApiWrapper.php delete mode 100644 tests/Facades/MollieTest.php create mode 100644 tests/MollieApiClientTest.php delete mode 100644 tests/MollieConnectProviderTest.php rename tests/{Wrappers/MollieApiLaravelClientTest.php => MollieLaravelHttpClientAdapterTest.php} (89%) delete mode 100644 tests/MollieManagerTest.php delete mode 100644 tests/MollieServiceProviderTest.php delete mode 100644 tests/TempHelpers/FacadeTrait.php delete mode 100644 tests/TempHelpers/LaravelTrait.php delete mode 100644 tests/TempHelpers/MockeryTrait.php delete mode 100644 tests/TempHelpers/ServiceProviderTrait.php delete mode 100644 tests/Wrappers/MollieApiWrapperTest.php diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..a9d0346 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,21 @@ +![Mollie](https://www.mollie.nl/files/Mollie-Logo-Style-Small.png) + +# Migrating from Laravel-Mollie v2.x to v3 + +### Step 1: Update composer dependencies + +Update `composer.json` to match this: + +```json +"require": { + "mollie/laravel-mollie": "^3.0" +} +``` + +Then run `composer update mollie/laravel-mollie`. + +### Step 2: + + +## Stuck? +Feel free to open an [issue](https://github.com/mollie/laravel-mollie/issues). diff --git a/src/Facades/Mollie.php b/src/Facades/Mollie.php index c8dd2cb..aa96cbe 100644 --- a/src/Facades/Mollie.php +++ b/src/Facades/Mollie.php @@ -35,13 +35,62 @@ namespace Mollie\Laravel\Facades; use Illuminate\Support\Facades\Facade; -use Mollie\Laravel\MollieManager; -use Mollie\Laravel\Wrappers\MollieApiWrapper; +use Mollie\Api\MollieApiClient; /** * (Facade) Class Mollie. * - * @method static MollieApiWrapper api() + * @method \Mollie\Api\Endpoints\BalanceEndpoint balanceReports() + * @method \Mollie\Api\Endpoints\BalanceEndpoint balances() + * @method \Mollie\Api\Endpoints\BalanceTransactionEndpoint balanceTransactions() + * @method \Mollie\Api\Endpoints\ChargebackEndpoint chargebacks() + * @method \Mollie\Api\Endpoints\ClientLinkEndpoint clientLinks() + * @method \Mollie\Api\Endpoints\ClientEndpoint clients() + * @method \Mollie\Api\Endpoints\CustomerPaymentEndpoint customerPayments() + * @method \Mollie\Api\Endpoints\CustomerEndpoint customers() + * @method \Mollie\Api\Endpoints\InvoiceEndpoint invoices() + * @method \Mollie\Api\Endpoints\OnboardingEndpoint onboarding() + * @method \Mollie\Api\Endpoints\OrderLineEndpoint orderLines() + * @method \Mollie\Api\Endpoints\OrderPaymentEndpoint orderPayments() + * @method \Mollie\Api\Endpoints\OrderRefundEndpoint orderRefunds() + * @method \Mollie\Api\Endpoints\OrderEndpoint orders() + * @method \Mollie\Api\Endpoints\OrganizationPartnerEndpoint organizationPartners() + * @method \Mollie\Api\Endpoints\OrganizationEndpoint organizations() + * @method \Mollie\Api\Endpoints\PaymentCaptureEndpoint paymentCaptures() + * @method \Mollie\Api\Endpoints\PaymentChargebackEndpoint paymentChargebacks() + * @method \Mollie\Api\Endpoints\PaymentLinkEndpoint paymentLinks() + * @method \Mollie\Api\Endpoints\PaymentRefundEndpoint paymentRefunds() + * @method \Mollie\Api\Endpoints\PaymentRouteEndpoint paymentRoutes() + * @method \Mollie\Api\Endpoints\PaymentEndpoint payments() + * @method \Mollie\Api\Endpoints\PermissionEndpoint permissions() + * @method \Mollie\Api\Endpoints\ProfileMethodEndpoint profileMethods() + * @method \Mollie\Api\Endpoints\ProfileEndpoint profiles() + * @method \Mollie\Api\Endpoints\MandateEndpoint mandates() + * @method \Mollie\Api\Endpoints\MethodEndpoint methods() + * @method \Mollie\Api\Endpoints\RefundEndpoint refunds() + * @method \Mollie\Api\Endpoints\SettlementCaptureEndpoint settlementCaptures() + * @method \Mollie\Api\Endpoints\SettlementChargebackEndpoint settlementChargebacks() + * @method \Mollie\Api\Endpoints\SettlementPaymentEndpoint settlementPayments() + * @method \Mollie\Api\Endpoints\SettlementRefundEndpoint settlementRefunds() + * @method \Mollie\Api\Endpoints\SettlementEndpoint settlements() + * @method \Mollie\Api\Endpoints\ShipmentEndpoint shipments() + * @method \Mollie\Api\Endpoints\SubscriptionEndpoint subscriptions() + * @method \Mollie\Api\Endpoints\TerminalEndpoint terminals() + * @method \Mollie\Api\Endpoints\WalletEndpoint wallets() + * @method MollieApiClient setApiEndpoint(string $url) + * @method string getApiEndpoint() + * @method string getVersionStrings() + * @method MollieApiClient setApiKey(string $apiKey) + * @method MollieApiClient setAccessToken(string $accessToken) + * @method ?bool usesOAuth() + * @method MollieApiClient addVersionString(string $versionString) + * @method void enableDebugging() + * @method void disableDebugging() + * @method MollieApiClient setIdempotencyKey(string $key) + * @method string getIdempotencyKey() + * @method MollieApiClient resetIdempotencyKey() + * @method MollieApiClient setIdempotencyKeyGenerator(\Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator) + * @method MollieApiClient clearIdempotencyKeyGenerator() */ class Mollie extends Facade { @@ -52,6 +101,6 @@ class Mollie extends Facade */ protected static function getFacadeAccessor() { - return MollieManager::class; + return MollieApiClient::class; } } diff --git a/src/MollieConnectProvider.php b/src/MollieConnectProvider.php index dd35e3a..6ccdfad 100644 --- a/src/MollieConnectProvider.php +++ b/src/MollieConnectProvider.php @@ -1,4 +1,5 @@ buildAuthUrlFromBase(static::MOLLIE_WEB_URL.'/oauth2/authorize', $state); + return $this->buildAuthUrlFromBase(static::MOLLIE_WEB_URL . '/oauth2/authorize', $state); } /** @@ -89,66 +89,7 @@ protected function getAuthUrl($state) */ protected function getTokenUrl() { - return static::MOLLIE_API_URL.'/oauth2/tokens'; - } - - /** - * Get the access token for the given code. - * - * @param string $code - * @return string - */ - public function getAccessToken($code) - { - $response = $this->getHttpClient()->post($this->getTokenUrl(), [ - 'headers' => ['Authorization' => 'Basic '.base64_encode($this->clientId.':'.$this->clientSecret)], - 'form_params' => $this->getTokenFields($code), - ]); - - return $this->parseAccessToken($response->getBody()); - } - - /** - * Get the access token with a refresh token. - * - * @param string $refresh_token - * @return array - */ - public function getRefreshTokenResponse($refresh_token) - { - $response = $this->getHttpClient()->post($this->getTokenUrl(), [ - 'headers' => ['Accept' => 'application/json'], - 'form_params' => $this->getRefreshTokenFields($refresh_token), - ]); - - return json_decode($response->getBody(), true); - } - - /** - * Get the refresh tokenfields with a refresh token. - * - * @param string $refresh_token - * @return array - */ - protected function getRefreshTokenFields($refresh_token) - { - return [ - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'grant_type' => 'refresh_token', - 'refresh_token' => $refresh_token, - ]; - } - - /** - * Get the POST fields for the token request. - * - * @param string $code - * @return array - */ - public function getTokenFields($code) - { - return Arr::add(parent::getTokenFields($code), 'grant_type', 'authorization_code'); + return static::MOLLIE_API_URL . '/oauth2/tokens'; } /** @@ -159,8 +100,8 @@ public function getTokenFields($code) */ protected function getUserByToken($token) { - $response = $this->getHttpClient()->get(static::MOLLIE_API_URL.'/v2/organizations/me', [ - 'headers' => ['Authorization' => 'Bearer '.$token], + $response = $this->getHttpClient()->get(static::MOLLIE_API_URL . '/v2/organizations/me', [ + 'headers' => ['Authorization' => 'Bearer ' . $token], ]); return json_decode($response->getBody(), true); diff --git a/src/MollieLaravelHttpClientAdapter.php b/src/MollieLaravelHttpClientAdapter.php index cbd87ef..d52ffb3 100644 --- a/src/MollieLaravelHttpClientAdapter.php +++ b/src/MollieLaravelHttpClientAdapter.php @@ -9,8 +9,6 @@ class MollieLaravelHttpClientAdapter implements MollieHttpAdapterInterface { - private const HTTP_NO_CONTENT = 204; - public function send($httpMethod, $url, $headers, $httpBody): ?object { $contentType = $headers['Content-Type'] ?? 'application/json'; @@ -20,19 +18,17 @@ public function send($httpMethod, $url, $headers, $httpBody): ?object ->withHeaders($headers) ->send($httpMethod, $url); - return $this->parseResponseBody($response); + return match (true) { + $response->noContent() => null, + $response->failed() => throw ApiException::createFromResponse($response->toPsrResponse(), null), + empty($response->body()) => throw new ApiException("Mollie response body is empty."), + default => $this->parseResponseBody($response), + }; } private function parseResponseBody(Response $response): ?object { $body = $response->body(); - if (empty($body)) { - if ($response->status() === self::HTTP_NO_CONTENT) { - return null; - } - - throw new ApiException('No response body found.'); - } $object = @json_decode($body); @@ -40,10 +36,6 @@ private function parseResponseBody(Response $response): ?object throw new ApiException("Unable to decode Mollie response: '{$body}'."); } - if ($response->status() >= 400) { - throw ApiException::createFromResponse($response->toPsrResponse(), null); - } - return $object; } diff --git a/src/MollieManager.php b/src/MollieManager.php deleted file mode 100644 index e5f47a9..0000000 --- a/src/MollieManager.php +++ /dev/null @@ -1,67 +0,0 @@ - - * @copyright Mollie B.V. - * - * @link https://www.mollie.com - */ - -namespace Mollie\Laravel; - -use Illuminate\Contracts\Container\Container; -use Mollie\Laravel\Wrappers\MollieApiWrapper; - -/** - * Class MollieManager. - */ -class MollieManager -{ - /** - * @var Container - */ - protected $app; - - /** - * MollieManager constructor. - * - * @return void - */ - public function __construct(Container $app) - { - $this->app = $app; - } - - /** - * @return mixed - */ - public function api() - { - return $this->app->make(MollieApiWrapper::class); - } -} diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index 6a2620e..db9dce0 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -37,7 +37,6 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Support\ServiceProvider; use Mollie\Api\MollieApiClient; -use Mollie\Laravel\Wrappers\MollieApiWrapper; /** * Class MollieServiceProvider. @@ -98,13 +97,17 @@ protected function extendSocialite() */ public function register() { - $this->app->singleton(MollieManager::class); - $this->app->singleton(MollieApiWrapper::class); $this->app->singleton( MollieApiClient::class, - function () { - return (new MollieApiClient(new MollieLaravelHttpClientAdapter)) + function (Container $app) { + $client = (new MollieApiClient(new MollieLaravelHttpClientAdapter)) ->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION); + + if (!empty($apiKey = $app['config']['mollie.key'])) { + $client->setApiKey($apiKey); + } + + return $client; } ); } diff --git a/src/Wrappers/MollieApiWrapper.php b/src/Wrappers/MollieApiWrapper.php deleted file mode 100644 index a71b748..0000000 --- a/src/Wrappers/MollieApiWrapper.php +++ /dev/null @@ -1,247 +0,0 @@ - - * @copyright Mollie B.V. - * - * @link https://www.mollie.com - */ - -namespace Mollie\Laravel\Wrappers; - -use Illuminate\Contracts\Config\Repository; -use Illuminate\Support\Traits\ForwardsCalls; -use Mollie\Api\MollieApiClient; - -/** - * Class MollieApiWrapper. - * - * @property-read \Mollie\Api\Endpoints\BalanceEndpoint $balanceReports - * @property-read \Mollie\Api\Endpoints\BalanceEndpoint $balances - * @property-read \Mollie\Api\Endpoints\BalanceTransactionEndpoint $balanceTransactions - * @property-read \Mollie\Api\Endpoints\ChargebackEndpoint $chargebacks - * @property-read \Mollie\Api\Endpoints\ClientLinkEndpoint $clientLinks - * @property-read \Mollie\Api\Endpoints\ClientEndpoint $clients - * @property-read \Mollie\Api\Endpoints\CustomerPaymentEndpoint $customerPayments - * @property-read \Mollie\Api\Endpoints\CustomerEndpoint $customers - * @property-read \Mollie\Api\Endpoints\InvoiceEndpoint $invoices - * @property-read \Mollie\Api\Endpoints\OnboardingEndpoint $onboarding - * @property-read \Mollie\Api\Endpoints\OrderLineEndpoint $orderLines - * @property-read \Mollie\Api\Endpoints\OrderPaymentEndpoint $orderPayments - * @property-read \Mollie\Api\Endpoints\OrderRefundEndpoint $orderRefunds - * @property-read \Mollie\Api\Endpoints\OrderEndpoint $orders - * @property-read \Mollie\Api\Endpoints\OrganizationPartnerEndpoint $organizationPartners - * @property-read \Mollie\Api\Endpoints\OrganizationEndpoint $organizations - * @property-read \Mollie\Api\Endpoints\PaymentCaptureEndpoint $paymentCaptures - * @property-read \Mollie\Api\Endpoints\PaymentChargebackEndpoint $paymentChargebacks - * @property-read \Mollie\Api\Endpoints\PaymentLinkEndpoint $paymentLinks - * @property-read \Mollie\Api\Endpoints\PaymentRefundEndpoint $paymentRefunds - * @property-read \Mollie\Api\Endpoints\PaymentRouteEndpoint $paymentRoutes - * @property-read \Mollie\Api\Endpoints\PaymentEndpoint $payments - * @property-read \Mollie\Api\Endpoints\PermissionEndpoint $permissions - * @property-read \Mollie\Api\Endpoints\ProfileMethodEndpoint $profileMethods - * @property-read \Mollie\Api\Endpoints\ProfileEndpoint $profiles - * @property-read \Mollie\Api\Endpoints\MandateEndpoint $mandates - * @property-read \Mollie\Api\Endpoints\MethodEndpoint $methods - * @property-read \Mollie\Api\Endpoints\RefundEndpoint $refunds - * @property-read \Mollie\Api\Endpoints\SettlementCaptureEndpoint $settlementCaptures - * @property-read \Mollie\Api\Endpoints\SettlementChargebackEndpoint $settlementChargebacks - * @property-read \Mollie\Api\Endpoints\SettlementPaymentEndpoint $settlementPayments - * @property-read \Mollie\Api\Endpoints\SettlementRefundEndpoint $settlementRefunds - * @property-read \Mollie\Api\Endpoints\SettlementEndpoint $settlements - * @property-read \Mollie\Api\Endpoints\ShipmentEndpoint $shipments - * @property-read \Mollie\Api\Endpoints\SubscriptionEndpoint $subscriptions - * @property-read \Mollie\Api\Endpoints\TerminalEndpoint $terminals - * @property-read \Mollie\Api\Endpoints\WalletEndpoint $wallets - * @method \Mollie\Api\Endpoints\BalanceEndpoint balanceReports() - * @method \Mollie\Api\Endpoints\BalanceEndpoint balances() - * @method \Mollie\Api\Endpoints\BalanceTransactionEndpoint balanceTransactions() - * @method \Mollie\Api\Endpoints\ChargebackEndpoint chargebacks() - * @method \Mollie\Api\Endpoints\ClientLinkEndpoint clientLinks() - * @method \Mollie\Api\Endpoints\ClientEndpoint clients() - * @method \Mollie\Api\Endpoints\CustomerPaymentEndpoint customerPayments() - * @method \Mollie\Api\Endpoints\CustomerEndpoint customers() - * @method \Mollie\Api\Endpoints\InvoiceEndpoint invoices() - * @method \Mollie\Api\Endpoints\OnboardingEndpoint onboarding() - * @method \Mollie\Api\Endpoints\OrderLineEndpoint orderLines() - * @method \Mollie\Api\Endpoints\OrderPaymentEndpoint orderPayments() - * @method \Mollie\Api\Endpoints\OrderRefundEndpoint orderRefunds() - * @method \Mollie\Api\Endpoints\OrderEndpoint orders() - * @method \Mollie\Api\Endpoints\OrganizationPartnerEndpoint organizationPartners() - * @method \Mollie\Api\Endpoints\OrganizationEndpoint organizations() - * @method \Mollie\Api\Endpoints\PaymentCaptureEndpoint paymentCaptures() - * @method \Mollie\Api\Endpoints\PaymentChargebackEndpoint paymentChargebacks() - * @method \Mollie\Api\Endpoints\PaymentLinkEndpoint paymentLinks() - * @method \Mollie\Api\Endpoints\PaymentRefundEndpoint paymentRefunds() - * @method \Mollie\Api\Endpoints\PaymentRouteEndpoint paymentRoutes() - * @method \Mollie\Api\Endpoints\PaymentEndpoint payments() - * @method \Mollie\Api\Endpoints\PermissionEndpoint permissions() - * @method \Mollie\Api\Endpoints\ProfileMethodEndpoint profileMethods() - * @method \Mollie\Api\Endpoints\ProfileEndpoint profiles() - * @method \Mollie\Api\Endpoints\MandateEndpoint mandates() - * @method \Mollie\Api\Endpoints\MethodEndpoint methods() - * @method \Mollie\Api\Endpoints\RefundEndpoint refunds() - * @method \Mollie\Api\Endpoints\SettlementCaptureEndpoint settlementCaptures() - * @method \Mollie\Api\Endpoints\SettlementChargebackEndpoint settlementChargebacks() - * @method \Mollie\Api\Endpoints\SettlementPaymentEndpoint settlementPayments() - * @method \Mollie\Api\Endpoints\SettlementRefundEndpoint settlementRefunds() - * @method \Mollie\Api\Endpoints\SettlementEndpoint settlements() - * @method \Mollie\Api\Endpoints\ShipmentEndpoint shipments() - * @method \Mollie\Api\Endpoints\SubscriptionEndpoint subscriptions() - * @method \Mollie\Api\Endpoints\TerminalEndpoint terminals() - * @method \Mollie\Api\Endpoints\WalletEndpoint wallets() - * @method MollieApiWrapper setApiEndpoint(string $url) - * @method string getApiEndpoint() - * @method string getVersionStrings() - * @method MollieApiWrapper setApiKey(string $apiKey) - * @method MollieApiWrapper setAccessToken(string $accessToken) - * @method ?bool usesOAuth() - * @method MollieApiWrapper addVersionString(string $versionString) - * @method void enableDebugging() - * @method void disableDebugging() - * @method MollieApiWrapper setIdempotencyKey(string $key) - * @method string getIdempotencyKey() - * @method MollieApiWrapper resetIdempotencyKey() - * @method MollieApiWrapper setIdempotencyKeyGenerator(\Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator) - * @method MollieApiWrapper clearIdempotencyKeyGenerator() - */ -class MollieApiWrapper -{ - use ForwardsCalls; - - /** - * @var Repository - */ - protected $config; - - /** - * @var MollieApiClient - */ - protected $client; - - protected static $supportedClientEndpoints = [ - 'balanceReports', - 'balances', - 'balanceTransactions', - 'chargebacks', - 'clientLinks', - 'clients', - 'customerPayments', - 'customers', - 'invoices', - 'onboarding', - 'orderLines', - 'orderPayments', - 'orderRefunds', - 'orders', - 'organizationPartners', - 'organizations', - 'paymentCaptures', - 'paymentChargebacks', - 'paymentLinks', - 'paymentRefunds', - 'paymentRoutes', - 'payments', - 'permissions', - 'profileMethods', - 'profiles', - 'mandates', - 'methods', - 'refunds', - 'settlementCaptures', - 'settlementChargebacks', - 'settlementPayments', - 'settlementRefunds', - 'settlements', - 'shipments', - 'subscriptions', - 'terminals', - 'wallets', - ]; - - /** - * MollieApiWrapper constructor. - * - * @return void - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function __construct(Repository $config, MollieApiClient $client) - { - $this->config = $config; - $this->client = $client; - - $key = $this->config->get('mollie.key'); - - if (!empty($key)) { - $this->client->setApiKey($key); - } - } - - /** - * Handle dynamic property calls. - * - * @param string $property - * @return mixed - */ - public function __get($property) - { - if ($this->endpointPropertyExists($property)) { - return $this->client->{$property}; - } - - $message = '%s has no endpoint "%s".'; - - throw new \Error( - sprintf($message, static::class, $property) - ); - } - - /** - * Handle dynamic method calls into the Mollie API client. - * - * @param string $method - * @param array $parameters - * @return mixed - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function __call($method, $parameters) - { - if ($this->endpointPropertyExists($method)) { - return $this->client->{$method}; - } - - return $this->forwardDecoratedCallTo($this->client, $method, $parameters); - } - - private function endpointPropertyExists(string $property): bool - { - return in_array($property, static::$supportedClientEndpoints); - } -} diff --git a/tests/Facades/MollieTest.php b/tests/Facades/MollieTest.php deleted file mode 100644 index 76e9b36..0000000 --- a/tests/Facades/MollieTest.php +++ /dev/null @@ -1,46 +0,0 @@ -assertInstanceOf( + MollieLaravelHttpClientAdapter::class, + $this->getUnaccessiblePropertyValue('httpClient') + ); + } + + public function testApiKeyIsSetOnResolvingApiClient() + { + config(['mollie.key' => 'test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxyz']); + + $this->assertEquals( + 'test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxyz', + $this->getUnaccessiblePropertyValue('apiKey') + ); + } + + public function testDoesNotSetApiKeyIfKeyIsEmpty() + { + config(['mollie.key' => '']); + + $this->assertEquals( + null, + $this->getUnaccessiblePropertyValue('apiKey') + ); + } + + private function getUnaccessiblePropertyValue(string $propertyName): mixed + { + $resolvedInstance = resolve(MollieApiClient::class); + + $reflection = new ReflectionClass($resolvedInstance); + $property = $reflection->getProperty($propertyName); + $property->setAccessible(true); + + return $property->getValue($resolvedInstance); + } +} diff --git a/tests/MollieConnectProviderTest.php b/tests/MollieConnectProviderTest.php deleted file mode 100644 index b1a3cf7..0000000 --- a/tests/MollieConnectProviderTest.php +++ /dev/null @@ -1,73 +0,0 @@ -markTestSkipped('Laravel Socialite must be present.'); - } - } - - public function testRedirectGeneratesTheProperSymfonyRedirectResponse() - { - $request = Request::create('foo'); - $request->setSession($session = m::mock('Symfony\Component\HttpFoundation\Session\SessionInterface')); - $session->shouldReceive('put')->once(); - $provider = new MollieConnectProvider($request, 'client_id', 'client_secret', 'redirect'); - $response = $provider->redirect(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); - $this->assertStringStartsWith( - 'https://www.mollie.com/oauth2/authorize?client_id=client_id&redirect_uri=redirect&scope=organizations.read&response_type=code&state=', - $response->getTargetUrl() - ); - } - - public function testExceptionIsThrownIfStateIsInvalid() - { - $this->expectException(\Laravel\Socialite\Two\InvalidStateException::class); - $request = Request::create('foo', 'GET', ['state' => str_repeat('B', 40), 'code' => 'code']); - $request->setSession($session = m::mock('Symfony\Component\HttpFoundation\Session\SessionInterface')); - $session->shouldReceive('pull')->once()->with('state')->andReturn(str_repeat('A', 40)); - $provider = new MollieConnectProvider($request, 'client_id', 'client_secret', 'redirect'); - $user = $provider->user(); - } - - public function testExceptionIsThrownIfStateIsNotSet() - { - $this->expectException(\Laravel\Socialite\Two\InvalidStateException::class); - $request = Request::create('foo', 'GET', ['state' => 'state', 'code' => 'code']); - $request->setSession($session = m::mock('Symfony\Component\HttpFoundation\Session\SessionInterface')); - $session->shouldReceive('pull')->once()->with('state'); - $provider = new MollieConnectProvider($request, 'client_id', 'client_secret', 'redirect'); - $user = $provider->user(); - } - - public function testGetTokenFields() - { - $request = Request::create('foo'); - $provider = new MollieConnectProvider($request, 'client_id', 'client_secret', 'redirect'); - $this->assertEquals( - [ - 'client_id' => 'client_id', - 'client_secret' => 'client_secret', - 'code' => 'dummy_code', - 'redirect_uri' => 'redirect', - 'grant_type' => 'authorization_code', - ], - $provider->getTokenFields('dummy_code') - ); - } -} diff --git a/tests/Wrappers/MollieApiLaravelClientTest.php b/tests/MollieLaravelHttpClientAdapterTest.php similarity index 89% rename from tests/Wrappers/MollieApiLaravelClientTest.php rename to tests/MollieLaravelHttpClientAdapterTest.php index 60b730f..f0bbecc 100644 --- a/tests/Wrappers/MollieApiLaravelClientTest.php +++ b/tests/MollieLaravelHttpClientAdapterTest.php @@ -1,6 +1,6 @@ Http::response(json_encode($payment)), ]); - $client->setApiKey('test_nawruSyCR7UE84EhtVmMmDGdRswBqj'); $returnedPayment = $client->payments->create([ 'redirectUrl' => 'https://google.com/redirect', 'description' => 'test', @@ -53,7 +52,6 @@ public function testGetRequest() 'https://api.mollie.com/v2/payments/'.$payment->id => Http::response(json_encode($payment)), ]); - $client->setApiKey('test_nawruSyCR7UE84EhtVmMmDGdRswBqj'); $returnedPayment = $client->payments->get($payment->id); $this->assertEquals($payment->id, $returnedPayment->id); diff --git a/tests/MollieManagerTest.php b/tests/MollieManagerTest.php deleted file mode 100644 index b1ab634..0000000 --- a/tests/MollieManagerTest.php +++ /dev/null @@ -1,37 +0,0 @@ -setUpManagerInstance(); - $this->assertInstanceOf(MollieManager::class, $this->manager); - } - - public function testApiMethod() - { - $this->setUpManagerInstance(); - $this->assertInstanceOf(MollieApiWrapper::class, $this->manager->api()); - $this->assertSame($this->app['mollie.api'], $this->manager->api()); - } - - public function setUpManagerInstance() - { - $this->manager = new MollieManager($this->app); - } -} diff --git a/tests/MollieServiceProviderTest.php b/tests/MollieServiceProviderTest.php deleted file mode 100644 index 2fdffa0..0000000 --- a/tests/MollieServiceProviderTest.php +++ /dev/null @@ -1,31 +0,0 @@ -assertIsInjectable(MollieManager::class); - } - - public function testMollieApiWrapperIsInjectable() - { - $this->assertIsInjectable(MollieApiWrapper::class); - } - - public function testMollieApiClientIsInjectable() - { - $this->assertIsInjectable(MollieApiClient::class); - } -} diff --git a/tests/TempHelpers/FacadeTrait.php b/tests/TempHelpers/FacadeTrait.php deleted file mode 100644 index 2640d6f..0000000 --- a/tests/TempHelpers/FacadeTrait.php +++ /dev/null @@ -1,76 +0,0 @@ -getFacadeClass(); - $reflection = new ReflectionClass($class); - $facade = new ReflectionClass(Facade::class); - - $msg = "Expected class '$class' to be a facade."; - - $this->assertTrue($reflection->isSubclassOf($facade), $msg); - } - - public function testFacadeAccessor() - { - $accessor = $this->getFacadeAccessor(); - $class = $this->getFacadeClass(); - $reflection = new ReflectionClass($class); - $method = $reflection->getMethod('getFacadeAccessor'); - $method->setAccessible(true); - - $msg = "Expected class '$class' to have an accessor of '$accessor'."; - - $this->assertSame($accessor, $method->invoke(null), $msg); - } - - public function testFacadeRoot() - { - $root = $this->getFacadeRoot(); - $class = $this->getFacadeClass(); - $reflection = new ReflectionClass($class); - $method = $reflection->getMethod('getFacadeRoot'); - $method->setAccessible(true); - - $msg = "Expected class '$class' to have a root of '$root'."; - - $this->assertInstanceOf($root, $method->invoke(null), $msg); - } -} diff --git a/tests/TempHelpers/LaravelTrait.php b/tests/TempHelpers/LaravelTrait.php deleted file mode 100644 index e27a49c..0000000 --- a/tests/TempHelpers/LaravelTrait.php +++ /dev/null @@ -1,67 +0,0 @@ -makeInjectableClass($name); - $this->assertInstanceOf($name, $class->getInjectedObject()); - } catch (Exception $e) { - $injectable = false; - if ($msg = $e->getMessage()) { - $message .= " $msg"; - } - } - - $this->assertTrue($injectable, $message); - } - - /** - * Register and make a stub class to inject into. - * - * - * @return object - */ - protected function makeInjectableClass(string $name) - { - do { - $class = 'testBenchStub'.Str::random(); - } while (class_exists($class)); - - eval(" - class $class - { - protected \$object; - - public function __construct(\\$name \$object) - { - \$this->object = \$object; - } - - public function getInjectedObject() - { - return \$this->object; - } - } - "); - - return $this->app->make($class); - } -} diff --git a/tests/TempHelpers/MockeryTrait.php b/tests/TempHelpers/MockeryTrait.php deleted file mode 100644 index 51f6598..0000000 --- a/tests/TempHelpers/MockeryTrait.php +++ /dev/null @@ -1,30 +0,0 @@ -addToAssertionCount($container->mockery_getExpectationCount()); - } - - Mockery::close(); - } - } -} diff --git a/tests/TempHelpers/ServiceProviderTrait.php b/tests/TempHelpers/ServiceProviderTrait.php deleted file mode 100644 index 20624a4..0000000 --- a/tests/TempHelpers/ServiceProviderTrait.php +++ /dev/null @@ -1,44 +0,0 @@ -getServiceProviderClass($this->app); - - $reflection = new ReflectionClass($class); - - $provider = new ReflectionClass(ServiceProvider::class); - - $msg = "Expected class '$class' to be a service provider."; - - $this->assertTrue($reflection->isSubclassOf($provider), $msg); - } - - public function testProvides() - { - $class = $this->getServiceProviderClass($this->app); - $reflection = new ReflectionClass($class); - - $method = $reflection->getMethod('provides'); - $method->setAccessible(true); - - $msg = "Expected class '$class' to provide a valid list of services."; - - $this->assertIsArray($method->invoke(new $class($this->app)), $msg); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index a51058a..0f9dbe4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,18 +10,6 @@ */ abstract class TestCase extends \Orchestra\Testbench\TestCase { - use LaravelTrait; - - /** - * Get the service provider class. - * - * @return string - */ - protected function getServiceProviderClass() - { - return MollieServiceProvider::class; - } - /** * Get package providers. * diff --git a/tests/Wrappers/MollieApiWrapperTest.php b/tests/Wrappers/MollieApiWrapperTest.php deleted file mode 100644 index 37fd851..0000000 --- a/tests/Wrappers/MollieApiWrapperTest.php +++ /dev/null @@ -1,230 +0,0 @@ -api = $this->getMockBuilder(MollieApiClient::class) - ->disableOriginalConstructor() - ->getMock(); - } - - public function testConstruct() - { - $wrapper = new MollieApiWrapper($this->app['config'], $this->app[MollieApiClient::class]); - $this->assertInstanceOf(MollieApiWrapper::class, $wrapper); - } - - public function testApiEndpoint() - { - $this->api->expects($this->once())->method('setApiEndpoint'); - $this->api->expects($this->once())->method('getApiEndpoint')->willReturn('/test'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - - $wrapper->setApiEndpoint('/test'); - $this->assertSame('/test', $wrapper->getApiEndpoint()); - } - - public function testSetGoodApiKey() - { - $this->api->expects($this->atLeastOnce())->method('setApiKey')->with('test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - $wrapper->setApiKey('test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); - } - - public function testSetBadApiKey() - { - $this->expectException(\Mollie\Api\Exceptions\ApiException::class); - $this->expectExceptionMessage("Invalid API key: 'live_'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); - $wrapper = new MollieApiWrapper($this->app['config'], $this->app[MollieApiClient::class]); - $wrapper->setApiKey('live_'); - } - - public function testDoesNotSetKeyWhenEmpty() - { - config(['mollie.key' => '']); - $this->assertEmpty($this->app['config']['mollie']['key']); - $this->api->expects($this->never())->method('setApiKey'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - } - - public function testSetGoodToken() - { - $this->api->expects($this->once())->method('setAccessToken')->with('access_xxx'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - $wrapper->setAccessToken('access_xxx'); - } - - public function testSetBadToken() - { - $this->expectException(\Mollie\Api\Exceptions\ApiException::class); - $this->expectExceptionMessage("Invalid OAuth access token: 'BAD'. An access token must start with 'access_'."); - $wrapper = new MollieApiWrapper($this->app['config'], $this->app[MollieApiClient::class]); - $wrapper->setAccessToken('BAD'); - } - - public function testEnableDebugging() - { - $this->api->expects($this->once())->method('enableDebugging'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - $wrapper->enableDebugging(); - } - - public function testDisableDebugging() - { - $this->api->expects($this->once())->method('disableDebugging'); - - $wrapper = new MollieApiWrapper($this->app['config'], $this->api); - $wrapper->disableDebugging(); - } - - public function testWrappedEndpoints() - { - $client = $this->app[MollieApiClient::class]; - $wrapper = new MollieApiWrapper( - $this->app['config'], - $client - ); - - foreach ($this->endpoints as $endpoint) { - $this->assertWrappedEndpoint($client, $wrapper, $endpoint); - } - } - - public function testWrappedPropertyEndpoints() - { - $client = $this->app[MollieApiClient::class]; - $wrapper = new MollieApiWrapper( - $this->app['config'], - $client - ); - - foreach ($this->endpoints as $endpoint) { - $this->assertWrappedPropertyEndpoint($client, $wrapper, $endpoint); - } - } - - public function testUnknownWrappedEndpoint() - { - $client = $this->app[MollieApiClient::class]; - $wrapper = new MollieApiWrapper( - $this->app['config'], - $client - ); - - $this->expectException(\Error::class); - $this->expectExceptionMessage('Call to undefined method Mollie\Laravel\Wrappers\MollieApiWrapper::unknown()'); - - $wrapper->unknown(); - } - - public function testUnknownWrappedPropertyEndpoint() - { - $client = $this->app[MollieApiClient::class]; - $wrapper = new MollieApiWrapper( - $this->app['config'], - $client - ); - - $this->expectException(\Error::class); - $this->expectExceptionMessage('Mollie\Laravel\Wrappers\MollieApiWrapper has no property or method "unknown".'); - - $wrapper->unknown; - } - - /** - * Asserts that the referenced wrapper method matches the client attribute - * I.e. $wrapper->payments() returns the same as $client->payments. - * - * @param MollieApiClient $client - * @param MollieApiWrapper $wrapper - * @param string $reference - * @return null - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - protected function assertWrappedEndpoint($client, $wrapper, $reference) - { - $this->assertEquals($client->$reference, $wrapper->$reference()); - } - - /** - * Asserts that the referenced wrapper property matches the client attribute - * I.e. $wrapper->payments returns the same as $client->payments. - * - * @param MollieApiClient $client - * @param MollieApiWrapper $wrapper - * @param string $reference - * @return null - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - protected function assertWrappedPropertyEndpoint($client, $wrapper, $reference) - { - $this->assertEquals($client->$reference, $wrapper->$reference); - } -} From e8c0206bf25d9719a7c2e37f55692fd7a51149e7 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 7 Mar 2024 13:02:40 +0100 Subject: [PATCH 06/17] wip --- UPGRADE.md | 63 ++++++++++++++++++++++++- docs/migration_instructions_v1_to_v2.md | 52 -------------------- docs/mollie_connect.md | 5 +- docs/recurring_and_direct_charge.md | 8 ++-- docs/roadmap.md | 22 +-------- docs/webhook.md | 4 +- 6 files changed, 70 insertions(+), 84 deletions(-) delete mode 100644 docs/migration_instructions_v1_to_v2.md diff --git a/UPGRADE.md b/UPGRADE.md index a9d0346..cf7499b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,7 +2,7 @@ # Migrating from Laravel-Mollie v2.x to v3 -### Step 1: Update composer dependencies +## Update composer dependencies Update `composer.json` to match this: @@ -14,8 +14,67 @@ Update `composer.json` to match this: Then run `composer update mollie/laravel-mollie`. -### Step 2: +## Review Changes +### Updating Dependencies +Laravel-Mollie now requires PHP 8.1.0 or greater. +If you are using the mollie connect feature, make sure to checkout the upgrade instructions for [Laravel-Socialite](https://github.com/laravel/socialite/blob/5.x/UPGRADE.md) + +#### Lumen support dropped +The Laravel team has added a note a while ago on the [Lumen Repository](https://github.com/laravel/lumen?tab=readme-ov-file) as well as the official [Lumen documentation](https://lumen.laravel.com/docs/master#installation) that they discourage starting a new project with Lumen. Therefore we dropped the Lumen support for this package. + +### Removed Classes +In order to enhance maintainability the following classes were removed: + +- `MollieApiWrapper` +- `MollieManager` + +Instead the `MollieApiClient` is now directly resolved and provided through the container without any abstractions. This change means you can directly access the newest API features that are added to the underlying [mollie/mollie-api-php](https://github.com/mollie/mollie-api-php) client without having to wait on this repository being updated. + +### Change in calling API endpoints +Previous versions of Laravel-Mollie forced you to call our endpoints through a static `api()` call. This has been removed to be in line with the mollie-api-php sdk. This also means that you can inject the `MollieApiClient` anywhere you like and it will already have the api key set for you. + +```php +// before +Mollie::api()->payments()->create(); + +// now +Mollie::payments()->create(); +``` + +Another small change we introduce is accessing endpoints through methods instead of properties. Previous versions would allow both. Going forward we will only support accessing endpoints through methods as this makes maintainability much easier. + +```php +// before +$client->payments->create(); + +// now +$client->payments()->create(); +``` + +### No more global helper function +The `mollie()` helper function was deleted. If you rely on the helper function, either consider switching to +- injecting or resolving the `MollieApiClient` from the container, or +- use the `Mollie` facade + +If none of these are an option for you, you can create your own `helpers.php` file and insert the code for the `mollie()` function yourself. + +```php +// app/helpers.php +permissions()` -- `Mollie::api()->organizations()` -- `Mollie::api()->issuers()` - -These methods were renamed: - -- `Mollie::api()->customerMandates()` into `Mollie::api()->mandates()` -- `Mollie::api()->customersPayments()` into `Mollie::api()->customerPayments()` -- `Mollie::api()->customerSubscriptions()` into `Mollie::api()->subscriptions()` -- `Mollie::api()->paymentsRefunds()` into `Mollie::api()->refunds()` - -Also, this method was added: - -- `Mollie::api()->invoices()` - -### Step 4: Other changes - -More breaking changes were introduced with the new Mollie API. Read about it here in the [official migration docs](https://docs.mollie.com/migrating-v1-to-v2). - -## Stuck? -Feel free to open an [issue](https://github.com/mollie/laravel-mollie/issues). diff --git a/docs/mollie_connect.md b/docs/mollie_connect.md index f5cd6ba..a866f84 100644 --- a/docs/mollie_connect.md +++ b/docs/mollie_connect.md @@ -44,9 +44,8 @@ Route::get('login', function () { Route::get('login_callback', function () { $user = Socialite::with('mollie')->user(); - Mollie::api()->setAccessToken($user->token); + Mollie::setAccessToken($user->token); - return Mollie::api()->profiles()->page(); // Retrieve payment profiles available on the obtained Mollie account + return Mollie::profiles()->page(); // Retrieve payment profiles available on the obtained Mollie account }); ``` - diff --git a/docs/recurring_and_direct_charge.md b/docs/recurring_and_direct_charge.md index 0499865..e546ed2 100644 --- a/docs/recurring_and_direct_charge.md +++ b/docs/recurring_and_direct_charge.md @@ -9,7 +9,7 @@ Here you can see an example of how easy it is to use [Mollie recurring](https:// First of all you need to [create a new customer](https://docs.mollie.com/payments/recurring#payments-recurring-first-payment) (step 1), this is pretty straight forward ```php -$customer = Mollie::api()->customers()->create([ +$customer = Mollie::customers()->create([ 'name' => 'John Doe', 'email' => 'john@doe.com', ]); @@ -20,7 +20,7 @@ $customer = Mollie::api()->customers()->create([ After creating the user, you can [start a payment](https://docs.mollie.com/payments/recurring#payments-recurring-first-payment) (step 3), it's important to set `sequenceType` to `first`, this will generate a mandate on Mollie's end that can be used to do direct charges. Without setting the `method` the payment screen of Mollie will display your methods that support recurring payments. ```php -$payment = Mollie::api()->payments()->create([ +$payment = Mollie::payments()->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '25.00', // You must send the correct number of decimals, thus we enforce the use of strings @@ -41,14 +41,14 @@ return redirect($payment->getCheckoutUrl(), 303); After doing the initial payment, you may [charge the users card/account directly](https://docs.mollie.com/payments/recurring#payments-recurring-charging-on-demand). Make sure there's a valid mandate connected to the customer. In case there are multiple mandates at least one should have `status` set to `valid`. Checking mandates is easy: ```php -$mandates = Mollie::api()->mandates()->listFor($customer); +$mandates = Mollie::mandates()->listFor($customer); ``` If any of the mandates is valid, charging the user is a piece of cake. Make sure `sequenceType` is set to `recurring`. ```php - $payment = Mollie::api()->payments()->create([ + $payment = Mollie::payments()->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '25.00', // You must send the correct number of decimals, thus we enforce the use of strings diff --git a/docs/roadmap.md b/docs/roadmap.md index fccaea2..7f8d5d4 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -9,29 +9,9 @@ Please submit an [issue](https://github.com/mollie/laravel-mollie/issues) if you ## Planned for next major release ### Provide default webhook -The Laravel-Mollie package makes it easy to set up a new Mollie payment in your Laravel application. But right now, you'll need to implement the webhook yourself. We plan on providing a default webhook, which will trigger an Event when a payment status has been updated. This way, you'll only need to listen for the PaymentUpdatedEvent. +The Laravel-Mollie package makes it easy to set up a new Mollie payment in your Laravel application. But right now, you'll need to implement the webhook yourself. We plan on providing a default webhook, which will trigger an Event when a payment status has been updated. This way, you'll only need to listen for the PaymentUpdatedEvent. Another solution may be to provide a default overridable controller, like Cashier has. Or to implement both events and the controller. ### Switch to MIT license Currently, the Laravel Mollie client has a *BSD 2-Clause "Simplified" License*. We're discussing switching to a *MIT* license, which is most common in Laravel packages. - -## Other Laravel packages by Mollie -Besides the Laravel-Mollie package, we're looking for other options to support you integrating Mollie in your Laravel applications. - -### Explore Laravel Cashier support ("Laravel/Cashier-Mollie") -Laravel Cashier is a very popular package for easily adding recurring payments to your Laravel application. We are exploring whether it's possible for Laravel Cashier to support Mollie. You can join the discussion [here](https://github.com/mollie/laravel-mollie/issues/41). - -### Explore Laravel Spark support -[Laravel Spark](https://spark.laravel.com/) is a commercial SAAS starter kit. By adding Cashier-Mollie support, new SAAS projects can be built rapidly on top of Mollie's subscription services. - -Laravel Spark leverages Laravel Cashier for subscription billing. - -When/If Cashier-Mollie is implemented, support for Laravel Spark would be a logical next topic for exploration. - -### Explore Laravel Nova plugin options -[Laravel Nova](https://nova.laravel.com/) is a powerful Laravel and Vue based CMS (commercial license). Launch of this new CMS is scheduled August 2018. - -Adoption rate is expected to be high; [Sander](https://github.com/sandervanhooft) expects Nova is going to blow a hole in other Laravel and PHP CMSes' market shares. - -A Laravel Nova plugin for Mollie could for example list and manage payments, and include a few dashboard cards. diff --git a/docs/webhook.md b/docs/webhook.md index dff9f03..4d3265e 100644 --- a/docs/webhook.md +++ b/docs/webhook.md @@ -6,7 +6,7 @@ A webhook is a URL Mollie will call when an object’s status changes, for examp To implement the webhook in your Laravel application you need to provide a `webhookUrl` parameter when creating a payment (or subscription): ```php -$payment = Mollie::api()->payments()->create([ +$payment = Mollie::payments()->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings @@ -34,7 +34,7 @@ class MollieWebhookController extends Controller { return; } - $payment = Mollie::api()->payments()->get($request->id); + $payment = Mollie::payments()->get($request->id); if ($payment->isPaid()) { // do your thing... From 15bbcbb508cddbfcdcc1caeb74f4d698a3b9f7cd Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 7 Mar 2024 13:18:19 +0100 Subject: [PATCH 07/17] wip --- README.md | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 51b11ef..f6cca68 100644 --- a/README.md +++ b/README.md @@ -16,20 +16,18 @@ Accepting [iDEAL](https://www.mollie.com/en/payments/ideal/), [Apple Pay](https: [![Latest Stable Version](https://poser.pugx.org/mollie/laravel-mollie/v/stable)](https://packagist.org/packages/mollie/laravel-mollie) [![Total Downloads](https://poser.pugx.org/mollie/laravel-mollie/downloads)](https://packagist.org/packages/mollie/laravel-mollie) -## Requirements +## **Requirements** * Get yourself a free [Mollie account](https://www.mollie.com/signup). No sign up costs. * Now you're ready to use the Mollie API client in test mode. * Follow [a few steps](https://www.mollie.com/dashboard/?modal=onboarding) to enable payment methods in live mode, and let us handle the rest. * Up-to-date OpenSSL (or other SSL/TLS toolkit) -* PHP >= 7.0 -* [Laravel](https://www.laravel.com) (or [Lumen](https://lumen.laravel.com)) >= 5.5 -* [Laravel Socialite](https://github.com/laravel/socialite) >= 3.0 (if you intend on using [Mollie Connect](https://docs.mollie.com/oauth/overview)) +* PHP >= 8.1 +* [Laravel](https://www.laravel.com) >= 10.0 +* [Laravel Socialite](https://github.com/laravel/socialite) >= 5.0 (if you intend on using [Mollie Connect](https://docs.mollie.com/oauth/overview)) -## Upgrading from v1.x? -To support the enhanced Mollie API, some breaking changes were introduced. Make sure to follow the instructions in the [package migration guide](docs/migration_instructions_v1_to_v2.md). - -Not ready to upgrade? The Laravel-Mollie client v1 will remain supported for now. +## Upgrading from v2.x? +To support the enhanced Mollie API, some breaking changes were introduced. Make sure to follow the instructions in the [upgrade guide](UPGRADE.md). Fresh install? Continue with the installation guide below. @@ -45,19 +43,12 @@ Or add it to `composer.json` manually: ```json "require": { - "mollie/laravel-mollie": "^2.0" + "mollie/laravel-mollie": "^3.0" } ``` Laravel-Mollie's service providers will be automatically registered using Laravel's auto-discovery feature. -Note: For Lumen you have to add the Mollie facade and service provider manually to: `bootstrap/app.php` : -```php -$app->withFacades(true, ['Mollie\Laravel\Facades\Mollie' => 'Mollie']); - -$app->register(Mollie\Laravel\MollieServiceProvider::class); -``` - ## Configuration You'll only need to add the `MOLLIE_KEY` variable to your `.env` file. @@ -77,7 +68,7 @@ use Mollie\Laravel\Facades\Mollie; public function preparePayment() { - $payment = Mollie::api()->payments->create([ + $payment = Mollie::payments->create([ "amount" => [ "currency" => "EUR", "value" => "10.00" // You must send the correct number of decimals, thus we enforce the use of strings @@ -102,7 +93,7 @@ public function preparePayment() */ public function handleWebhookNotification(Request $request) { $paymentId = $request->input('id'); - $payment = Mollie::api()->payments->get($paymentId); + $payment = Mollie::payments->get($paymentId); if ($payment->isPaid()) { @@ -112,14 +103,6 @@ public function handleWebhookNotification(Request $request) { } ``` -### Global helper method -For your convencience we've added the global `mollie()` helper function. It's an easy shortcut to the `Mollie::api()` facade accessor. - -```php -// Using facade accessor -$payment = \Mollie\Laravel\Facades\Mollie::api()->payments->get($payment_id); -``` - ## Other examples - [Process realtime status updates with a webhook](docs/webhook.md) @@ -144,6 +127,6 @@ But how would you like to contribute to a [technology oriented organization](htt Contact: [www.mollie.com](https://www.mollie.com) — info@mollie.com — +31 20-612 88 55 -* [More information about Mollie Connect](https://www.mollie.com/en/connect) -* [Documentation for the Mollie API](https://www.mollie.com/en/docs/overview) -* [Documentation for Mollie OAuth](https://www.mollie.com/en/docs/oauth/overview) +* [More information about Mollie Connect](https://www.mollie.com/products/connect) +* [Documentation for the Mollie API](https://docs.mollie.com/) +* [Documentation for Mollie OAuth](https://docs.mollie.com/connect/getting-started) From a7fbf3abcf874b731aed25408ee72640522edaa4 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 7 Mar 2024 13:19:49 +0100 Subject: [PATCH 08/17] wip --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6cca68..b23ea85 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ You can find the latest development roadmap for this package [here](docs/roadmap Want to help us make our Laravel module even better? We take [pull requests](https://github.com/mollie/laravel-mollie/pulls?utf8=%E2%9C%93&q=is%3Apr), sure. But how would you like to contribute to a [technology oriented organization](https://www.mollie.com/nl/blog/post/werken-bij-mollie-als-developer/)? Mollie is hiring developers and system engineers. -[Check out our vacancies](https://www.mollie.com/nl/jobs) or [get in touch](mailto:personeel@mollie.com). +[Check out our vacancies](https://jobs.mollie.com/) or [get in touch](mailto:personeel@mollie.com). ## License From b47d0ae2a08096346a6b54d7c268b088448b1e72 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 12 Mar 2024 14:51:07 +0100 Subject: [PATCH 09/17] wip --- LICENSE | 8 --- README.md | 4 +- UPGRADE.md | 14 +---- docs/mollie_connect.md | 4 +- docs/recurring_and_direct_charge.md | 8 +-- docs/webhook.md | 4 +- src/Facades/Mollie.php | 87 +---------------------------- src/MollieConnectProvider.php | 32 ----------- src/MollieManager.php | 18 ++++++ src/MollieServiceProvider.php | 35 ------------ 10 files changed, 33 insertions(+), 181 deletions(-) delete mode 100644 LICENSE create mode 100644 src/MollieManager.php diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 6d1f587..0000000 --- a/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -Copyright (c) 2016, Mollie B.V. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index b23ea85..22e308c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ use Mollie\Laravel\Facades\Mollie; public function preparePayment() { - $payment = Mollie::payments->create([ + $payment = Mollie::api()->payments->create([ "amount" => [ "currency" => "EUR", "value" => "10.00" // You must send the correct number of decimals, thus we enforce the use of strings @@ -93,7 +93,7 @@ public function preparePayment() */ public function handleWebhookNotification(Request $request) { $paymentId = $request->input('id'); - $payment = Mollie::payments->get($paymentId); + $payment = Mollie::api()->payments->get($paymentId); if ($payment->isPaid()) { diff --git a/UPGRADE.md b/UPGRADE.md index cf7499b..d2bb85d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -32,24 +32,14 @@ In order to enhance maintainability the following classes were removed: Instead the `MollieApiClient` is now directly resolved and provided through the container without any abstractions. This change means you can directly access the newest API features that are added to the underlying [mollie/mollie-api-php](https://github.com/mollie/mollie-api-php) client without having to wait on this repository being updated. ### Change in calling API endpoints -Previous versions of Laravel-Mollie forced you to call our endpoints through a static `api()` call. This has been removed to be in line with the mollie-api-php sdk. This also means that you can inject the `MollieApiClient` anywhere you like and it will already have the api key set for you. +Earlier versions of Laravel-Mollie provided access to endpoints via both methods and properties. Moving forward, access to endpoints will be exclusively through properties, aligning with the practices of the mollie-api-php SDK.**** ```php // before Mollie::api()->payments()->create(); // now -Mollie::payments()->create(); -``` - -Another small change we introduce is accessing endpoints through methods instead of properties. Previous versions would allow both. Going forward we will only support accessing endpoints through methods as this makes maintainability much easier. - -```php -// before -$client->payments->create(); - -// now -$client->payments()->create(); +Mollie::api()->payments->create(); ``` ### No more global helper function diff --git a/docs/mollie_connect.md b/docs/mollie_connect.md index a866f84..89e2e01 100644 --- a/docs/mollie_connect.md +++ b/docs/mollie_connect.md @@ -44,8 +44,8 @@ Route::get('login', function () { Route::get('login_callback', function () { $user = Socialite::with('mollie')->user(); - Mollie::setAccessToken($user->token); + Mollie::api()->setAccessToken($user->token); - return Mollie::profiles()->page(); // Retrieve payment profiles available on the obtained Mollie account + return Mollie::api()->profiles()->page(); // Retrieve payment profiles available on the obtained Mollie account }); ``` diff --git a/docs/recurring_and_direct_charge.md b/docs/recurring_and_direct_charge.md index e546ed2..dfbb35c 100644 --- a/docs/recurring_and_direct_charge.md +++ b/docs/recurring_and_direct_charge.md @@ -9,7 +9,7 @@ Here you can see an example of how easy it is to use [Mollie recurring](https:// First of all you need to [create a new customer](https://docs.mollie.com/payments/recurring#payments-recurring-first-payment) (step 1), this is pretty straight forward ```php -$customer = Mollie::customers()->create([ +$customer = Mollie::api()->customers->create([ 'name' => 'John Doe', 'email' => 'john@doe.com', ]); @@ -20,7 +20,7 @@ $customer = Mollie::customers()->create([ After creating the user, you can [start a payment](https://docs.mollie.com/payments/recurring#payments-recurring-first-payment) (step 3), it's important to set `sequenceType` to `first`, this will generate a mandate on Mollie's end that can be used to do direct charges. Without setting the `method` the payment screen of Mollie will display your methods that support recurring payments. ```php -$payment = Mollie::payments()->create([ +$payment = Mollie::api()->payments->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '25.00', // You must send the correct number of decimals, thus we enforce the use of strings @@ -41,14 +41,14 @@ return redirect($payment->getCheckoutUrl(), 303); After doing the initial payment, you may [charge the users card/account directly](https://docs.mollie.com/payments/recurring#payments-recurring-charging-on-demand). Make sure there's a valid mandate connected to the customer. In case there are multiple mandates at least one should have `status` set to `valid`. Checking mandates is easy: ```php -$mandates = Mollie::mandates()->listFor($customer); +$mandates = Mollie::api()->mandates->listFor($customer); ``` If any of the mandates is valid, charging the user is a piece of cake. Make sure `sequenceType` is set to `recurring`. ```php - $payment = Mollie::payments()->create([ + $payment = Mollie::api()->payments->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '25.00', // You must send the correct number of decimals, thus we enforce the use of strings diff --git a/docs/webhook.md b/docs/webhook.md index 4d3265e..f23546b 100644 --- a/docs/webhook.md +++ b/docs/webhook.md @@ -6,7 +6,7 @@ A webhook is a URL Mollie will call when an object’s status changes, for examp To implement the webhook in your Laravel application you need to provide a `webhookUrl` parameter when creating a payment (or subscription): ```php -$payment = Mollie::payments()->create([ +$payment = Mollie::api()->payments->create([ 'amount' => [ 'currency' => 'EUR', 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings @@ -34,7 +34,7 @@ class MollieWebhookController extends Controller { return; } - $payment = Mollie::payments()->get($request->id); + $payment = Mollie::api()->payments->get($request->id); if ($payment->isPaid()) { // do your thing... diff --git a/src/Facades/Mollie.php b/src/Facades/Mollie.php index aa96cbe..ed8c992 100644 --- a/src/Facades/Mollie.php +++ b/src/Facades/Mollie.php @@ -1,96 +1,15 @@ - * @copyright Mollie B.V. - * - * @link https://www.mollie.com - */ - namespace Mollie\Laravel\Facades; use Illuminate\Support\Facades\Facade; use Mollie\Api\MollieApiClient; +use Mollie\Laravel\MollieManager; /** * (Facade) Class Mollie. * - * @method \Mollie\Api\Endpoints\BalanceEndpoint balanceReports() - * @method \Mollie\Api\Endpoints\BalanceEndpoint balances() - * @method \Mollie\Api\Endpoints\BalanceTransactionEndpoint balanceTransactions() - * @method \Mollie\Api\Endpoints\ChargebackEndpoint chargebacks() - * @method \Mollie\Api\Endpoints\ClientLinkEndpoint clientLinks() - * @method \Mollie\Api\Endpoints\ClientEndpoint clients() - * @method \Mollie\Api\Endpoints\CustomerPaymentEndpoint customerPayments() - * @method \Mollie\Api\Endpoints\CustomerEndpoint customers() - * @method \Mollie\Api\Endpoints\InvoiceEndpoint invoices() - * @method \Mollie\Api\Endpoints\OnboardingEndpoint onboarding() - * @method \Mollie\Api\Endpoints\OrderLineEndpoint orderLines() - * @method \Mollie\Api\Endpoints\OrderPaymentEndpoint orderPayments() - * @method \Mollie\Api\Endpoints\OrderRefundEndpoint orderRefunds() - * @method \Mollie\Api\Endpoints\OrderEndpoint orders() - * @method \Mollie\Api\Endpoints\OrganizationPartnerEndpoint organizationPartners() - * @method \Mollie\Api\Endpoints\OrganizationEndpoint organizations() - * @method \Mollie\Api\Endpoints\PaymentCaptureEndpoint paymentCaptures() - * @method \Mollie\Api\Endpoints\PaymentChargebackEndpoint paymentChargebacks() - * @method \Mollie\Api\Endpoints\PaymentLinkEndpoint paymentLinks() - * @method \Mollie\Api\Endpoints\PaymentRefundEndpoint paymentRefunds() - * @method \Mollie\Api\Endpoints\PaymentRouteEndpoint paymentRoutes() - * @method \Mollie\Api\Endpoints\PaymentEndpoint payments() - * @method \Mollie\Api\Endpoints\PermissionEndpoint permissions() - * @method \Mollie\Api\Endpoints\ProfileMethodEndpoint profileMethods() - * @method \Mollie\Api\Endpoints\ProfileEndpoint profiles() - * @method \Mollie\Api\Endpoints\MandateEndpoint mandates() - * @method \Mollie\Api\Endpoints\MethodEndpoint methods() - * @method \Mollie\Api\Endpoints\RefundEndpoint refunds() - * @method \Mollie\Api\Endpoints\SettlementCaptureEndpoint settlementCaptures() - * @method \Mollie\Api\Endpoints\SettlementChargebackEndpoint settlementChargebacks() - * @method \Mollie\Api\Endpoints\SettlementPaymentEndpoint settlementPayments() - * @method \Mollie\Api\Endpoints\SettlementRefundEndpoint settlementRefunds() - * @method \Mollie\Api\Endpoints\SettlementEndpoint settlements() - * @method \Mollie\Api\Endpoints\ShipmentEndpoint shipments() - * @method \Mollie\Api\Endpoints\SubscriptionEndpoint subscriptions() - * @method \Mollie\Api\Endpoints\TerminalEndpoint terminals() - * @method \Mollie\Api\Endpoints\WalletEndpoint wallets() - * @method MollieApiClient setApiEndpoint(string $url) - * @method string getApiEndpoint() - * @method string getVersionStrings() - * @method MollieApiClient setApiKey(string $apiKey) - * @method MollieApiClient setAccessToken(string $accessToken) - * @method ?bool usesOAuth() - * @method MollieApiClient addVersionString(string $versionString) - * @method void enableDebugging() - * @method void disableDebugging() - * @method MollieApiClient setIdempotencyKey(string $key) - * @method string getIdempotencyKey() - * @method MollieApiClient resetIdempotencyKey() - * @method MollieApiClient setIdempotencyKeyGenerator(\Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator) - * @method MollieApiClient clearIdempotencyKeyGenerator() + * @method static MollieApiClient api() */ class Mollie extends Facade { @@ -101,6 +20,6 @@ class Mollie extends Facade */ protected static function getFacadeAccessor() { - return MollieApiClient::class; + return MollieManager::class; } } diff --git a/src/MollieConnectProvider.php b/src/MollieConnectProvider.php index 6ccdfad..221f0b7 100644 --- a/src/MollieConnectProvider.php +++ b/src/MollieConnectProvider.php @@ -1,37 +1,5 @@ - * @copyright Mollie B.V. - * - * @link https://www.mollie.com - */ - namespace Mollie\Laravel; use Laravel\Socialite\Two\AbstractProvider; diff --git a/src/MollieManager.php b/src/MollieManager.php new file mode 100644 index 0000000..3ce3402 --- /dev/null +++ b/src/MollieManager.php @@ -0,0 +1,18 @@ +app->make(MollieApiClient::class); + } +} diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index db9dce0..a60e1d2 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -1,46 +1,11 @@ - * @copyright Mollie B.V. - * - * @link https://www.mollie.com - */ - namespace Mollie\Laravel; use Illuminate\Contracts\Container\Container; use Illuminate\Support\ServiceProvider; use Mollie\Api\MollieApiClient; -/** - * Class MollieServiceProvider. - */ class MollieServiceProvider extends ServiceProvider { const PACKAGE_VERSION = '3.0.0'; From 68fbb8e0cc903e62a500314a0fd2f7cca8220bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krishan=20K=C3=B6nig?= Date: Tue, 12 Mar 2024 14:52:07 +0100 Subject: [PATCH 10/17] Create LICENSE.md --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bf76669 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Mollie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From aaa554ee06162acc0845c3443131bbc2ee8ead99 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 12 Mar 2024 14:54:55 +0100 Subject: [PATCH 11/17] replace license reference in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22e308c..dc028f4 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ But how would you like to contribute to a [technology oriented organization](htt ## License -[BSD (Berkeley Software Distribution) License](http://www.opensource.org/licenses/bsd-license.php). Copyright (c) 2016, Mollie B.V. +[The MIT License](LICENSE.md). Copyright (c) 2024, Mollie B.V. ## Support From 98b26a22a718d9284aed5201d11cf8c6f3f615ff Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 14 Mar 2024 13:28:12 +0100 Subject: [PATCH 12/17] undo version upgrade for gh actions for now --- .github/workflows/pint.yml | 4 ++-- .github/workflows/tests.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index aadc6bb..987c9b6 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} @@ -22,6 +22,6 @@ jobs: run: pint - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v5 + uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: Fix styling diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2936c92..d3ac711 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 From 826aab98b85a1ebffa141d01c4c905cd58a26acf Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 14 Mar 2024 14:14:11 +0100 Subject: [PATCH 13/17] add new image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc028f4..02fd778 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Mollie for Laravel

- +![create new payment](https://github.com/mollie/laravel-mollie/assets/10154100/205b536f-51a3-4d1b-b2c9-69f02ba019fa) Laravel-Mollie incorporates the [Mollie API](https://www.mollie.com/en/docs/overview) and [Mollie Connect](https://www.mollie.com/en/connect) into your [Laravel](https://laravel.com/) or [Lumen](https://lumen.laravel.com/) project. From 1c056dc763fce8e851027d16cfbc3c694c954f15 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 14 Mar 2024 13:14:34 +0000 Subject: [PATCH 14/17] Fix styling --- src/MollieConnectProvider.php | 8 ++++---- src/MollieLaravelHttpClientAdapter.php | 2 +- src/MollieServiceProvider.php | 6 +++--- tests/MollieLaravelHttpClientAdapterTest.php | 1 - tests/TestCase.php | 1 - 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/MollieConnectProvider.php b/src/MollieConnectProvider.php index 221f0b7..5196b37 100644 --- a/src/MollieConnectProvider.php +++ b/src/MollieConnectProvider.php @@ -47,7 +47,7 @@ class MollieConnectProvider extends AbstractProvider implements ProviderInterfac */ protected function getAuthUrl($state) { - return $this->buildAuthUrlFromBase(static::MOLLIE_WEB_URL . '/oauth2/authorize', $state); + return $this->buildAuthUrlFromBase(static::MOLLIE_WEB_URL.'/oauth2/authorize', $state); } /** @@ -57,7 +57,7 @@ protected function getAuthUrl($state) */ protected function getTokenUrl() { - return static::MOLLIE_API_URL . '/oauth2/tokens'; + return static::MOLLIE_API_URL.'/oauth2/tokens'; } /** @@ -68,8 +68,8 @@ protected function getTokenUrl() */ protected function getUserByToken($token) { - $response = $this->getHttpClient()->get(static::MOLLIE_API_URL . '/v2/organizations/me', [ - 'headers' => ['Authorization' => 'Bearer ' . $token], + $response = $this->getHttpClient()->get(static::MOLLIE_API_URL.'/v2/organizations/me', [ + 'headers' => ['Authorization' => 'Bearer '.$token], ]); return json_decode($response->getBody(), true); diff --git a/src/MollieLaravelHttpClientAdapter.php b/src/MollieLaravelHttpClientAdapter.php index d52ffb3..296c8bf 100644 --- a/src/MollieLaravelHttpClientAdapter.php +++ b/src/MollieLaravelHttpClientAdapter.php @@ -21,7 +21,7 @@ public function send($httpMethod, $url, $headers, $httpBody): ?object return match (true) { $response->noContent() => null, $response->failed() => throw ApiException::createFromResponse($response->toPsrResponse(), null), - empty($response->body()) => throw new ApiException("Mollie response body is empty."), + empty($response->body()) => throw new ApiException('Mollie response body is empty.'), default => $this->parseResponseBody($response), }; } diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index a60e1d2..a01235f 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -28,7 +28,7 @@ public function boot() */ protected function setupConfig() { - $source = realpath(__DIR__ . '/../config/mollie.php'); + $source = realpath(__DIR__.'/../config/mollie.php'); if ($this->app->runningInConsole()) { $this->publishes([$source => config_path('mollie.php')]); @@ -66,9 +66,9 @@ public function register() MollieApiClient::class, function (Container $app) { $client = (new MollieApiClient(new MollieLaravelHttpClientAdapter)) - ->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION); + ->addVersionString('MollieLaravel/'.self::PACKAGE_VERSION); - if (!empty($apiKey = $app['config']['mollie.key'])) { + if (! empty($apiKey = $app['config']['mollie.key'])) { $client->setApiKey($apiKey); } diff --git a/tests/MollieLaravelHttpClientAdapterTest.php b/tests/MollieLaravelHttpClientAdapterTest.php index f0bbecc..ee75d84 100644 --- a/tests/MollieLaravelHttpClientAdapterTest.php +++ b/tests/MollieLaravelHttpClientAdapterTest.php @@ -5,7 +5,6 @@ use Illuminate\Support\Facades\Http; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; -use Mollie\Laravel\Tests\TestCase; /** * Class MollieApiWrapper diff --git a/tests/TestCase.php b/tests/TestCase.php index 0f9dbe4..287725f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace Mollie\Laravel\Tests; use Mollie\Laravel\MollieServiceProvider; -use Mollie\Laravel\Tests\TempHelpers\LaravelTrait; /** * This is the abstract test case class. From 84564a7fac5ffcfa5ccce0e16cf7f080a588525b Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 14 Mar 2024 14:15:13 +0100 Subject: [PATCH 15/17] wip --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02fd778..ef50e02 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ You can find the latest development roadmap for this package [here](docs/roadmap ## Want to help us make our Laravel module even better? Want to help us make our Laravel module even better? We take [pull requests](https://github.com/mollie/laravel-mollie/pulls?utf8=%E2%9C%93&q=is%3Apr), sure. -But how would you like to contribute to a [technology oriented organization](https://www.mollie.com/nl/blog/post/werken-bij-mollie-als-developer/)? Mollie is hiring developers and system engineers. +But how would you like to contribute to a technology oriented organization? Mollie is hiring developers and system engineers. [Check out our vacancies](https://jobs.mollie.com/) or [get in touch](mailto:personeel@mollie.com). ## License @@ -125,7 +125,7 @@ But how would you like to contribute to a [technology oriented organization](htt ## Support -Contact: [www.mollie.com](https://www.mollie.com) — info@mollie.com — +31 20-612 88 55 +Contact: [www.mollie.com](https://www.mollie.com) — info@mollie.com * [More information about Mollie Connect](https://www.mollie.com/products/connect) * [Documentation for the Mollie API](https://docs.mollie.com/) From 8dfa2c0bcb4e4e455fd7a716d6efe713d87b868c Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 14 Mar 2024 14:22:14 +0100 Subject: [PATCH 16/17] wip --- src/MollieServiceProvider.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index a01235f..580ad32 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -17,24 +17,11 @@ class MollieServiceProvider extends ServiceProvider */ public function boot() { - $this->setupConfig(); - $this->extendSocialite(); - } - - /** - * Setup the config. - * - * @return void - */ - protected function setupConfig() - { - $source = realpath(__DIR__.'/../config/mollie.php'); - if ($this->app->runningInConsole()) { - $this->publishes([$source => config_path('mollie.php')]); + $this->publishes([__DIR__ . '/../config/mollie.php' => config_path('mollie.php')]); } - $this->mergeConfigFrom($source, 'mollie'); + $this->extendSocialite(); } /** @@ -62,18 +49,22 @@ protected function extendSocialite() */ public function register() { + $this->mergeConfigFrom(__DIR__ . '/../config/mollie.php', 'mollie'); + $this->app->singleton( MollieApiClient::class, function (Container $app) { $client = (new MollieApiClient(new MollieLaravelHttpClientAdapter)) - ->addVersionString('MollieLaravel/'.self::PACKAGE_VERSION); + ->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION); - if (! empty($apiKey = $app['config']['mollie.key'])) { + if (!empty($apiKey = $app['config']['mollie.key'])) { $client->setApiKey($apiKey); } return $client; } ); + + $this->app->singleton(MollieManager::class); } } From 9a836caf38237030c506a634a54d9360ff0afb74 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 14 Mar 2024 13:22:41 +0000 Subject: [PATCH 17/17] Fix styling --- src/MollieServiceProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MollieServiceProvider.php b/src/MollieServiceProvider.php index 580ad32..0a17be3 100644 --- a/src/MollieServiceProvider.php +++ b/src/MollieServiceProvider.php @@ -18,7 +18,7 @@ class MollieServiceProvider extends ServiceProvider public function boot() { if ($this->app->runningInConsole()) { - $this->publishes([__DIR__ . '/../config/mollie.php' => config_path('mollie.php')]); + $this->publishes([__DIR__.'/../config/mollie.php' => config_path('mollie.php')]); } $this->extendSocialite(); @@ -49,15 +49,15 @@ protected function extendSocialite() */ public function register() { - $this->mergeConfigFrom(__DIR__ . '/../config/mollie.php', 'mollie'); + $this->mergeConfigFrom(__DIR__.'/../config/mollie.php', 'mollie'); $this->app->singleton( MollieApiClient::class, function (Container $app) { $client = (new MollieApiClient(new MollieLaravelHttpClientAdapter)) - ->addVersionString('MollieLaravel/' . self::PACKAGE_VERSION); + ->addVersionString('MollieLaravel/'.self::PACKAGE_VERSION); - if (!empty($apiKey = $app['config']['mollie.key'])) { + if (! empty($apiKey = $app['config']['mollie.key'])) { $client->setApiKey($apiKey); }