Add PayPal support for add-on and gift voucher checkout

This commit is contained in:
Codex Agent
2026-02-04 14:54:40 +01:00
parent 7025418d9e
commit 17025df47b
24 changed files with 1599 additions and 34 deletions

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit;
use App\Enums\CouponStatus;
use App\Enums\CouponType;
use App\Mail\GiftVoucherIssued;
use App\Models\Coupon;
@@ -156,4 +157,65 @@ class GiftVoucherServiceTest extends TestCase
$this->assertSame(65.00, (float) $voucher->amount);
$this->assertSame('USD', $voucher->currency);
}
public function test_it_issues_voucher_from_paypal_payload(): void
{
Mail::fake();
config()->set('gift-vouchers.reminder_days', 0);
config()->set('gift-vouchers.expiry_reminder_days', 0);
$voucher = GiftVoucher::factory()->create([
'status' => GiftVoucher::STATUS_PENDING,
'paypal_order_id' => 'ORDER-123',
]);
$payload = [
'id' => 'CAPTURE-123',
'status' => 'COMPLETED',
'purchase_units' => [
[
'payments' => [
'captures' => [
['id' => 'CAPTURE-123'],
],
],
],
],
];
$service = $this->app->make(GiftVoucherService::class);
$service->issueFromPayPal($voucher, $payload, 'ORDER-123');
$voucher->refresh();
$this->assertSame(GiftVoucher::STATUS_ISSUED, $voucher->status);
$this->assertSame('ORDER-123', $voucher->paypal_order_id);
$this->assertSame('CAPTURE-123', $voucher->paypal_capture_id);
$this->assertNotNull($voucher->coupon_id);
Mail::assertQueued(GiftVoucherIssued::class, 2);
}
public function test_it_marks_voucher_refunded_from_paypal(): void
{
$coupon = Coupon::factory()->create([
'status' => CouponStatus::ACTIVE,
'enabled_for_checkout' => true,
]);
$voucher = GiftVoucher::factory()->create([
'status' => GiftVoucher::STATUS_ISSUED,
'coupon_id' => $coupon->id,
]);
$service = $this->app->make(GiftVoucherService::class);
$service->markRefundedFromPayPal($voucher, ['id' => 'REFUND-1']);
$voucher->refresh();
$coupon->refresh();
$this->assertSame(GiftVoucher::STATUS_REFUNDED, $voucher->status);
$this->assertSame(CouponStatus::ARCHIVED, $coupon->status);
$this->assertFalse($coupon->enabled_for_checkout);
}
}