set('gift-vouchers.tiers', [ ['key' => 'gift-a', 'label' => 'A', 'amount' => 10, 'currency' => 'EUR', 'lemonsqueezy_variant_id' => 'pri_a'], ['key' => 'gift-b', 'label' => 'B', 'amount' => 20, 'currency' => 'EUR', 'lemonsqueezy_variant_id' => null], ]); $service = $this->app->make(GiftVoucherCheckoutService::class); $tiers = $service->tiers(); $this->assertCount(2, $tiers); $this->assertTrue($tiers[0]['can_checkout']); $this->assertFalse($tiers[1]['can_checkout']); } public function test_it_creates_checkout_link_with_metadata(): void { config()->set('gift-vouchers.tiers', [ ['key' => 'gift-a', 'label' => 'A', 'amount' => 10, 'currency' => 'EUR', 'lemonsqueezy_variant_id' => 'pri_a'], ]); $checkoutService = Mockery::mock(LemonSqueezyCheckoutService::class); $checkoutService->shouldReceive('createVariantCheckout') ->once() ->with('pri_a', Mockery::on(function (array $customData) { return ($customData['type'] ?? null) === 'gift_voucher' && ($customData['tier_key'] ?? null) === 'gift-a' && ($customData['purchaser_email'] ?? null) === 'buyer@example.com' && ($customData['recipient_email'] ?? null) === 'friend@example.com' && ($customData['recipient_name'] ?? null) === 'Friend' && ($customData['message'] ?? null) === 'Hi'; }), Mockery::type('array')) ->andReturn(['checkout_url' => 'https://lemonsqueezy.test/checkout/123', 'id' => 'chk_123']); $this->app->instance(LemonSqueezyCheckoutService::class, $checkoutService); $service = $this->app->make(GiftVoucherCheckoutService::class); $checkout = $service->create([ 'tier_key' => 'gift-a', 'purchaser_email' => 'buyer@example.com', 'recipient_email' => 'friend@example.com', 'recipient_name' => 'Friend', 'message' => 'Hi', ]); $this->assertSame('https://lemonsqueezy.test/checkout/123', $checkout['checkout_url']); $this->assertSame('chk_123', $checkout['id']); } }