Add PayPal checkout provider
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyCheckoutService;
|
||||
use Mockery;
|
||||
|
||||
class TenantLemonSqueezyCheckoutTest extends TenantTestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_tenant_can_create_lemonsqueezy_checkout(): void
|
||||
{
|
||||
$package = Package::factory()->create([
|
||||
'lemonsqueezy_variant_id' => 'pri_test_123',
|
||||
'price' => 129,
|
||||
]);
|
||||
|
||||
$checkoutService = Mockery::mock(LemonSqueezyCheckoutService::class);
|
||||
$checkoutService->shouldReceive('createCheckout')
|
||||
->once()
|
||||
->withArgs(function ($tenant, $payloadPackage, array $payload) use ($package) {
|
||||
return $tenant->is($this->tenant)
|
||||
&& $payloadPackage->is($package)
|
||||
&& array_key_exists('success_url', $payload)
|
||||
&& array_key_exists('return_url', $payload)
|
||||
&& array_key_exists('metadata', $payload)
|
||||
&& is_array($payload['metadata'])
|
||||
&& ! empty($payload['metadata']['checkout_session_id']);
|
||||
})
|
||||
->andReturn([
|
||||
'checkout_url' => 'https://checkout.lemonsqueezy.test/checkout/123',
|
||||
'id' => 'chk_test_123',
|
||||
]);
|
||||
$this->instance(LemonSqueezyCheckoutService::class, $checkoutService);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/lemonsqueezy-checkout', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('checkout_url', 'https://checkout.lemonsqueezy.test/checkout/123')
|
||||
->assertJsonStructure(['checkout_session_id']);
|
||||
}
|
||||
|
||||
public function test_lemonsqueezy_checkout_requires_lemonsqueezy_variant_id(): void
|
||||
{
|
||||
$package = Package::factory()->create([
|
||||
'lemonsqueezy_variant_id' => null,
|
||||
'price' => 129,
|
||||
]);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/lemonsqueezy-checkout', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonStructure([
|
||||
'errors' => [
|
||||
'package_id' => [],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
70
tests/Feature/Tenant/TenantPayPalCheckoutTest.php
Normal file
70
tests/Feature/Tenant/TenantPayPalCheckoutTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Services\PayPal\PayPalOrderService;
|
||||
use Mockery;
|
||||
|
||||
class TenantPayPalCheckoutTest extends TenantTestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_tenant_can_create_paypal_checkout(): void
|
||||
{
|
||||
$package = Package::factory()->create([
|
||||
'price' => 129,
|
||||
]);
|
||||
|
||||
$checkoutService = Mockery::mock(PayPalOrderService::class);
|
||||
$checkoutService->shouldReceive('createOrder')
|
||||
->once()
|
||||
->withArgs(function ($session, $payloadPackage, array $payload) use ($package) {
|
||||
return $session->tenant?->is($this->tenant)
|
||||
&& $payloadPackage->is($package)
|
||||
&& array_key_exists('return_url', $payload)
|
||||
&& array_key_exists('cancel_url', $payload)
|
||||
&& array_key_exists('request_id', $payload);
|
||||
})
|
||||
->andReturn([
|
||||
'id' => 'order_test_123',
|
||||
'status' => 'CREATED',
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'approve',
|
||||
'href' => 'https://paypal.test/checkout/123',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$checkoutService->shouldReceive('resolveApproveUrl')
|
||||
->once()
|
||||
->andReturn('https://paypal.test/checkout/123');
|
||||
$this->instance(PayPalOrderService::class, $checkoutService);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/paypal-checkout', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('approve_url', 'https://paypal.test/checkout/123')
|
||||
->assertJsonPath('order_id', 'order_test_123')
|
||||
->assertJsonStructure(['checkout_session_id']);
|
||||
}
|
||||
|
||||
public function test_paypal_checkout_requires_package_id(): void
|
||||
{
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/paypal-checkout', []);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonStructure([
|
||||
'errors' => [
|
||||
'package_id' => [],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user