Stripe connection test

This commit is contained in:
Čarodej
2022-05-09 17:38:38 +02:00
parent 4eb901dae0
commit e3293f0b1a
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace Domain\Settings\Actions;
use ErrorException;
use VueFileManager\Subscription\Domain\Plans\DTO\CreateFixedPlanData;
use VueFileManager\Subscription\Support\EngineManager;
class TestStripeConnectionAction
{
public function __construct(
public EngineManager $subscription
) {}
public function __invoke($credentials)
{
try {
// Set temporary stripe connection
config([
'subscription.credentials.stripe' => [
'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)
);
}
}
}

View File

@@ -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
};