mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
PayPal connection test
This commit is contained in:
62
src/Domain/Settings/Actions/TestPayPalConnectionAction.php
Normal file
62
src/Domain/Settings/Actions/TestPayPalConnectionAction.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Domain\Settings\Actions;
|
||||||
|
|
||||||
|
use ErrorException;
|
||||||
|
use VueFileManager\Subscription\Domain\Plans\DTO\CreateFixedPlanData;
|
||||||
|
use VueFileManager\Subscription\Support\EngineManager;
|
||||||
|
|
||||||
|
class TestPayPalConnectionAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public EngineManager $subscription
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke($credentials)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Set temporary stripe connection
|
||||||
|
config([
|
||||||
|
'subscription.credentials.paypal' => [
|
||||||
|
'secret' => $credentials['secret'],
|
||||||
|
'id' => $credentials['key'],
|
||||||
|
'webhook_id' => $credentials['webhook'],
|
||||||
|
'is_live' => $credentials['live'],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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('paypal')
|
||||||
|
->createFixedPlan($data);
|
||||||
|
|
||||||
|
// Delete plan
|
||||||
|
$this->subscription
|
||||||
|
->driver('paypal')
|
||||||
|
->deletePlan($plan['id']);
|
||||||
|
|
||||||
|
} catch (ErrorException $error) {
|
||||||
|
abort(
|
||||||
|
response()->json([
|
||||||
|
'type' => 'service-connection-error',
|
||||||
|
'title' => 'Service Connection Error',
|
||||||
|
'message' => $error->getMessage(),
|
||||||
|
], 401)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ use Artisan;
|
|||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Domain\Settings\Models\Setting;
|
use Domain\Settings\Models\Setting;
|
||||||
use Domain\Settings\Actions\TestStripeConnectionAction;
|
use Domain\Settings\Actions\TestStripeConnectionAction;
|
||||||
|
use Domain\Settings\Actions\TestPayPalConnectionAction;
|
||||||
use Domain\Settings\Actions\TestPaystackConnectionAction;
|
use Domain\Settings\Actions\TestPaystackConnectionAction;
|
||||||
use Domain\Settings\Requests\StorePaymentServiceCredentialsRequest;
|
use Domain\Settings\Requests\StorePaymentServiceCredentialsRequest;
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ class StorePaymentServiceCredentialsController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
public TestPaystackConnectionAction $testPaystackConnection,
|
public TestPaystackConnectionAction $testPaystackConnection,
|
||||||
public TestStripeConnectionAction $testStripeConnection,
|
public TestStripeConnectionAction $testStripeConnection,
|
||||||
|
public TestPayPalConnectionAction $testPayPalConnection,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +63,12 @@ class StorePaymentServiceCredentialsController
|
|||||||
'secret' => $request->input('secret'),
|
'secret' => $request->input('secret'),
|
||||||
'webhook' => $request->input('webhook'),
|
'webhook' => $request->input('webhook'),
|
||||||
]),
|
]),
|
||||||
|
'paypal' => ($this->testPayPalConnection)([
|
||||||
|
'key' => $request->input('key'),
|
||||||
|
'secret' => $request->input('secret'),
|
||||||
|
'webhook' => $request->input('webhook'),
|
||||||
|
'live' => $request->has('live') ? (string)$request->input('live') : $PayPalDefaultMode,
|
||||||
|
]),
|
||||||
default => null
|
default => null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user