From 6dbb3b4549362bfb27d8103e9c32014fc396cba0 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 1 Mar 2024 13:25:18 +0100 Subject: [PATCH] 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); - } - } }