Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added withQuantity method to checkout #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 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,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 (
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');
});