Skip to content

Commit

Permalink
added withQuantity method to checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
dcblogdev committed Nov 9, 2023
1 parent 2b31286 commit 86207ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -145,6 +147,16 @@ public function withDiscountCode(string $discountCode): self
return $this;
}

public function withQuantity(int $quantity): self
{
$this->checkoutData['variant_quantities'] = [
'variant_id' => $this->variant,
'quantity' => $quantity,
];

return $this;
}

public function withCustomData(array $custom): self
{
if (
Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/CheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 86207ff

Please sign in to comment.