From e3293f0b1a7e19c5a45e97ac04f8eb4a6ec7ee79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Mon, 9 May 2022 17:38:38 +0200 Subject: [PATCH] Stripe connection test --- .../Actions/TestStripeConnectionAction.php | 61 +++++++++++++++++++ ...orePaymentServiceCredentialsController.php | 7 +++ 2 files changed, 68 insertions(+) create mode 100644 src/Domain/Settings/Actions/TestStripeConnectionAction.php diff --git a/src/Domain/Settings/Actions/TestStripeConnectionAction.php b/src/Domain/Settings/Actions/TestStripeConnectionAction.php new file mode 100644 index 00000000..c6e13578 --- /dev/null +++ b/src/Domain/Settings/Actions/TestStripeConnectionAction.php @@ -0,0 +1,61 @@ + [ + 'secret' => $credentials['secret'], + 'public_key' => $credentials['key'], + 'webhook_key' => $credentials['webhook'], + ], + ]); + + // Define test plan + $data = CreateFixedPlanData::fromArray([ + 'type' => 'fixed', + 'name' => 'Test Plan', + 'description' => null, + 'features' => [ + 'max_storage_amount' => 200, + 'max_team_members' => 20, + ], + 'currency' => 'EUR', + 'amount' => 99, + 'interval' => 'month', + ]); + + // Create test plan + $plan = $this->subscription + ->driver('stripe') + ->createFixedPlan($data); + + // Delete plan + $this->subscription + ->driver('stripe') + ->deletePlan($plan['id']); + + } catch (ErrorException $error) { + abort( + response()->json([ + 'type' => 'service-connection-error', + 'title' => 'Service Connection Error', + 'message' => $error->getMessage(), + ], 401) + ); + } + } +} \ No newline at end of file diff --git a/src/Domain/Settings/Controllers/StorePaymentServiceCredentialsController.php b/src/Domain/Settings/Controllers/StorePaymentServiceCredentialsController.php index bc91b4d5..f1501ab6 100644 --- a/src/Domain/Settings/Controllers/StorePaymentServiceCredentialsController.php +++ b/src/Domain/Settings/Controllers/StorePaymentServiceCredentialsController.php @@ -4,6 +4,7 @@ namespace Domain\Settings\Controllers; use Artisan; use Illuminate\Http\Response; use Domain\Settings\Models\Setting; +use Domain\Settings\Actions\TestStripeConnectionAction; use Domain\Settings\Actions\TestPaystackConnectionAction; use Domain\Settings\Requests\StorePaymentServiceCredentialsRequest; @@ -11,6 +12,7 @@ class StorePaymentServiceCredentialsController { public function __construct( public TestPaystackConnectionAction $testPaystackConnection, + public TestStripeConnectionAction $testStripeConnection, ) {} /** @@ -54,6 +56,11 @@ class StorePaymentServiceCredentialsController 'key' => $request->input('key'), 'secret' => $request->input('secret'), ]), + 'stripe' => ($this->testStripeConnection)([ + 'key' => $request->input('key'), + 'secret' => $request->input('secret'), + 'webhook' => $request->input('webhook'), + ]), default => null };