diff --git a/src/Checkout.php b/src/Checkout.php index 4366083..709eb94 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -42,6 +42,8 @@ class Checkout implements Responsable private ?int $customPrice = null; + private int $quantity = 1; + public function __construct(private string $store, private string $variant) { } @@ -145,6 +147,18 @@ public function withDiscountCode(string $discountCode): self return $this; } + public function withQuantity(int $quantity): self + { + $this->checkoutData['variant_quantities'] = [ + [ + 'variant_id' => (int) $this->variant, + 'quantity' => $quantity, + ], + ]; + + return $this; + } + public function withCustomData(array $custom): self { if ( diff --git a/tests/Feature/CheckoutTest.php b/tests/Feature/CheckoutTest.php index 239a449..230f16c 100644 --- a/tests/Feature/CheckoutTest.php +++ b/tests/Feature/CheckoutTest.php @@ -98,3 +98,18 @@ expect($checkout->url()) ->toBe('https://lemon.lemonsqueezy.com/checkout/buy/variant_123'); }); + +it('can include quantities', function () { + $checkout = Checkout::make('store_24398', 'variant_123') + ->withName('John Doe') + ->withQuantity(2); + + Http::fake([ + 'api.lemonsqueezy.com/v1/checkouts' => Http::response([ + 'data' => ['attributes' => ['url' => 'https://lemon.lemonsqueezy.com/checkout/buy/variant_123']], + ]), + ]); + + expect($checkout->url()) + ->toBe('https://lemon.lemonsqueezy.com/checkout/buy/variant_123'); +});