From 8b28347ab23d4d7e0941edeec788e41ac5919797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Wed, 31 Jan 2024 14:19:14 +0100 Subject: [PATCH] wip --- README.md | 41 +++++++++++++++-------------------- composer.json | 2 +- config/bazar_stripe.php | 15 ------------- src/StripeServiceProvider.php | 13 +---------- 4 files changed, 19 insertions(+), 52 deletions(-) delete mode 100644 config/bazar_stripe.php diff --git a/README.md b/README.md index ca77a76..09b67e9 100644 --- a/README.md +++ b/README.md @@ -13,36 +13,29 @@ composer require conedevelopment/bazar-stripe ```ini STRIPE_API_KEY= STRIPE_SECRET= -STRIPE_SUCCESS_URL= -STRIPE_CANCEL_URL= ``` -### Customizing Redirect URL After Payment Intent +### Bazar Config ```php -namespace App\Providers; - -use Cone\Bazar\Models\Order; -use Cone\Bazar\Models\Transaction; -use Cone\Bazar\Stripe\StripeDriver; - -class AppServiceProvider extends ServiceProvider -{ - public function register(): void - { - StripeDriver::redirectUrlAfterPayment(function (Order $order, string $status, Transaction $transaction = null): string { - return match ($status) { - 'success' => '/shop/account/orders/'.$order->uuid, - default => '/shop/retry-checkout?order='.$order->uuid; - }; - }); - } -} + // config/bazar.php + + 'gateway' => [ + 'drivers' => [ + // ... + 'stripe' => [ + 'test_mode' => env('STRIPE_TEST_MODE', false), + 'api_key' => env('STRIPE_API_KEY'), + 'secret' => env('STRIPE_SECRET'), + 'success_url' => env('STRIPE_SUCCESS_URL', '/'), + 'failure_url' => env('STRIPE_FAILURE_URL', '/'), + ], + ], + ], + + // ... ``` -> [!NOTE] -> The `redirectUrlAfterPayment` method overrides `STRIPE_SUCCESS_URL` and `STRIPE_CANCEL_URL` values for the given order. - ## Webhook Events ```sh diff --git a/composer.json b/composer.json index 05299cf..873c5ad 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.2 || ^8.3", - "conedevelopment/bazar": "@dev", + "conedevelopment/bazar": "dev-master || ^1.0.0-beta", "stripe/stripe-php": "^13.1" }, "require-dev": { diff --git a/config/bazar_stripe.php b/config/bazar_stripe.php deleted file mode 100644 index a86f9f7..0000000 --- a/config/bazar_stripe.php +++ /dev/null @@ -1,15 +0,0 @@ - env('STRIPE_TEST_MODE', false), - - 'api_key' => env('STRIPE_API_KEY'), - - 'secret' => env('STRIPE_SECRET'), - - 'success_url' => env('STRIPE_SUCCESS_URL', '/'), - - 'failure_url' => env('STRIPE_FAILURE_URL', '/'), - -]; diff --git a/src/StripeServiceProvider.php b/src/StripeServiceProvider.php index a8335ed..0f1075f 100644 --- a/src/StripeServiceProvider.php +++ b/src/StripeServiceProvider.php @@ -13,12 +13,8 @@ class StripeServiceProvider extends ServiceProvider */ public function register(): void { - if (! $this->app->configurationIsCached()) { - $this->mergeConfigFrom(__DIR__.'/../config/bazar_stripe.php', 'bazar_stripe'); - } - Gateway::extend('stripe', static function (Application $app): StripeDriver { - return new StripeDriver($app['config']->get('bazar_stripe')); + return new StripeDriver($app['config']->get('bazar.gateway.drivers.stripe', [])); }); } @@ -27,13 +23,6 @@ public function register(): void */ public function boot(): void { - if ($this->app->runningInConsole()) { - $this->publishes( - [__DIR__.'/../config/bazar_stripe.php' => $this->app->configPath('bazar_stripe.php')], - 'bazar-stripe-config' - ); - } - $this->app['events']->listen( Events\StripeWebhookInvoked::class, Listeners\HandlePaymentIntentSuccededEvent::class );