Add PayPal support for add-on and gift voucher checkout
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\CheckoutSession;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPackage;
|
||||
use App\Models\EventPackageAddon;
|
||||
use App\Models\Package;
|
||||
use App\Services\PayPal\PayPalOrderService;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Mockery;
|
||||
|
||||
class EventAddonCheckoutTest extends TenantTestCase
|
||||
{
|
||||
@@ -20,14 +23,15 @@ class EventAddonCheckoutTest extends TenantTestCase
|
||||
'variant_id' => 'var_addon_photos',
|
||||
'increments' => ['extra_photos' => 500],
|
||||
]);
|
||||
Config::set('package-addons.provider', CheckoutSession::PROVIDER_LEMONSQUEEZY);
|
||||
|
||||
Config::set('lemonsqueezy.api_key', 'test_key');
|
||||
Config::set('lemonsqueezy.base_url', 'https://lemonsqueezy.test');
|
||||
Config::set('lemonsqueezy.base_url', 'https://api.lemonsqueezy.com/v1');
|
||||
Config::set('lemonsqueezy.store_id', 'store_123');
|
||||
|
||||
// Fake Lemon Squeezy response
|
||||
Http::fake([
|
||||
'https://lemonsqueezy.test/checkouts' => Http::response([
|
||||
'https://api.lemonsqueezy.com/v1/checkouts' => Http::response([
|
||||
'data' => [
|
||||
'id' => 'chk_addon_123',
|
||||
'attributes' => [
|
||||
@@ -81,4 +85,69 @@ class EventAddonCheckoutTest extends TenantTestCase
|
||||
$addon = EventPackageAddon::where('event_package_id', $eventPackage->id)->latest()->first();
|
||||
$this->assertSame(1000, $addon->extra_photos); // increments * quantity
|
||||
}
|
||||
|
||||
public function test_paypal_checkout_creates_pending_addon_record(): void
|
||||
{
|
||||
Config::set('package-addons.provider', CheckoutSession::PROVIDER_PAYPAL);
|
||||
Config::set('checkout.currency', 'EUR');
|
||||
Config::set('package-addons.extra_photos_small.price', 12.50);
|
||||
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_photos' => 100,
|
||||
'max_guests' => 50,
|
||||
'gallery_days' => 7,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->for($this->tenant)->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'used_photos' => 0,
|
||||
'used_guests' => 0,
|
||||
'gallery_expires_at' => now()->addDays(7),
|
||||
]);
|
||||
|
||||
$orders = Mockery::mock(PayPalOrderService::class);
|
||||
$orders->shouldReceive('createSimpleOrder')
|
||||
->once()
|
||||
->andReturn([
|
||||
'id' => 'ORDER-ADDON-1',
|
||||
'links' => [
|
||||
['rel' => 'approve', 'href' => 'https://paypal.test/approve'],
|
||||
],
|
||||
]);
|
||||
$orders->shouldReceive('resolveApproveUrl')
|
||||
->once()
|
||||
->andReturn('https://paypal.test/approve');
|
||||
$this->app->instance(PayPalOrderService::class, $orders);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/addons/checkout", [
|
||||
'addon_key' => 'extra_photos_small',
|
||||
'quantity' => 2,
|
||||
'accepted_terms' => true,
|
||||
'accepted_waiver' => true,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('checkout_id', 'ORDER-ADDON-1');
|
||||
$response->assertJsonPath('checkout_url', 'https://paypal.test/approve');
|
||||
|
||||
$this->assertDatabaseHas('event_package_addons', [
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'addon_key' => 'extra_photos_small',
|
||||
'status' => 'pending',
|
||||
'quantity' => 2,
|
||||
'checkout_id' => 'ORDER-ADDON-1',
|
||||
'amount' => 25.00,
|
||||
'currency' => 'EUR',
|
||||
]);
|
||||
|
||||
$addon = EventPackageAddon::where('event_package_id', $eventPackage->id)->latest()->first();
|
||||
$this->assertSame(1000, $addon->extra_photos);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user