63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class LemonSqueezyReturnTest extends TestCase
|
|
{
|
|
public function test_return_redirects_to_success_url_for_paid_order(): void
|
|
{
|
|
Config::set('lemonsqueezy.api_key', 'test_key');
|
|
Config::set('lemonsqueezy.base_url', 'https://lemonsqueezy.test');
|
|
Config::set('app.url', 'https://fotospiel-app.test');
|
|
|
|
Http::fake([
|
|
'https://lemonsqueezy.test/orders/ord_123' => Http::response([
|
|
'data' => [
|
|
'id' => 'ord_123',
|
|
'attributes' => [
|
|
'status' => 'paid',
|
|
'custom_data' => [
|
|
'success_url' => 'https://fotospiel-app.test/event-admin/mobile/events/slug/photos?addon_success=1',
|
|
'return_url' => 'https://fotospiel-app.test/event-admin/mobile/events/slug/photos',
|
|
],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$response = $this->get('/lemonsqueezy/return?order_id=ord_123');
|
|
|
|
$response->assertRedirect('https://fotospiel-app.test/event-admin/mobile/events/slug/photos?addon_success=1');
|
|
}
|
|
|
|
public function test_return_redirects_to_return_url_when_not_completed(): void
|
|
{
|
|
Config::set('lemonsqueezy.api_key', 'test_key');
|
|
Config::set('lemonsqueezy.base_url', 'https://lemonsqueezy.test');
|
|
Config::set('app.url', 'https://fotospiel-app.test');
|
|
|
|
Http::fake([
|
|
'https://lemonsqueezy.test/orders/ord_456' => Http::response([
|
|
'data' => [
|
|
'id' => 'ord_456',
|
|
'attributes' => [
|
|
'status' => 'failed',
|
|
'custom_data' => [
|
|
'success_url' => 'https://fotospiel-app.test/event-admin/mobile/events/slug/photos?addon_success=1',
|
|
'return_url' => 'https://fotospiel-app.test/event-admin/mobile/events/slug/photos',
|
|
],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$response = $this->get('/lemonsqueezy/return?order_id=ord_456');
|
|
|
|
$response->assertRedirect('https://fotospiel-app.test/event-admin/mobile/events/slug/photos');
|
|
}
|
|
}
|