Paystack connection test

This commit is contained in:
Čarodej
2022-05-09 17:32:44 +02:00
parent 911f15d493
commit 4eb901dae0
3 changed files with 85 additions and 4 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Domain\Settings\Actions;
use ErrorException;
use VueFileManager\Subscription\Domain\Plans\DTO\CreateFixedPlanData;
use VueFileManager\Subscription\Support\EngineManager;
class TestPaystackConnectionAction
{
public function __construct(
public EngineManager $subscription
){}
public function __invoke($credentials)
{
try {
// Set temporary paystack connection
config([
'subscription.credentials.paystack' => [
'secret' => $credentials['secret'],
'public_key' => $credentials['key'],
],
]);
// Define test plan
$data = CreateFixedPlanData::fromArray([
'type' => 'fixed',
'name' => 'Test Plan',
'description' => null,
'features' => [
'max_storage_amount' => 200,
'max_team_members' => 20,
],
'currency' => 'ZAR',
'amount' => 99999,
'interval' => 'month',
]);
// Create test plan
$plan = $this->subscription
->driver('paystack')
->createFixedPlan($data);
// Delete plan
$this->subscription
->driver('paystack')
->deletePlan($plan['id']);
} catch (ErrorException $error) {
abort(
response()->json([
'type' => 'service-connection-error',
'title' => 'Service Connection Error',
'message' => $error->getMessage(),
], 401)
);
}
}
}