Updated checkout to wait for backend confirmation before advancing, added a “Processing payment…” state with retry/ refresh fallback, and now use Paddle totals/currency for purchase records + confirmation emails (with new email translations).

This commit is contained in:
Codex Agent
2025-12-22 09:06:48 +01:00
parent 41d29eb7d3
commit 84234bfb8e
36 changed files with 1742 additions and 187 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Unit;
use App\Models\Package;
use App\Models\Tenant;
use App\Services\Paddle\PaddleCheckoutService;
use App\Services\Paddle\PaddleClient;
use App\Services\Paddle\PaddleCustomerService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;
class PaddleCheckoutServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_checkout_sends_custom_data_payload(): void
{
$tenant = Tenant::factory()->create([
'contact_email' => 'buyer@example.com',
]);
$package = Package::factory()->create([
'paddle_price_id' => 'pri_123',
]);
$client = Mockery::mock(PaddleClient::class);
$customers = Mockery::mock(PaddleCustomerService::class);
$customers->shouldReceive('ensureCustomerId')
->once()
->with($tenant)
->andReturn('ctm_123');
$client->shouldReceive('post')
->once()
->with('/checkout/links', Mockery::on(function (array $payload) use ($tenant, $package) {
return $payload['items'][0]['price_id'] === 'pri_123'
&& $payload['customer_id'] === 'ctm_123'
&& ($payload['custom_data']['tenant_id'] ?? null) === (string) $tenant->id
&& ($payload['custom_data']['package_id'] ?? null) === (string) $package->id
&& ($payload['custom_data']['source'] ?? null) === 'test'
&& ! isset($payload['metadata']);
}))
->andReturn(['data' => ['url' => 'https://paddle.test/checkout/123', 'id' => 'chk_123']]);
$this->app->instance(PaddleClient::class, $client);
$this->app->instance(PaddleCustomerService::class, $customers);
$service = $this->app->make(PaddleCheckoutService::class);
$checkout = $service->createCheckout($tenant, $package, [
'success_url' => 'https://example.test/success',
'return_url' => 'https://example.test/cancel',
'metadata' => ['source' => 'test'],
]);
$this->assertSame('https://paddle.test/checkout/123', $checkout['checkout_url']);
$this->assertSame('chk_123', $checkout['id']);
}
}