Skip to content
Merged
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ Route::get('/buy', function (Request $request) {
});
```

### Product Details

You can overwrite additional data for product checkouts with the `withProductName` and `withDescription` methods:

```php
$request->user()->checkout('variant-id')
->withProductName('Ebook')
->withDescription('A thrilling novel!');
```

### Receipt Thank You

Additionally, you can customize the thank you note for the order receipt email.

```php
$request->user()->checkout('variant-id')
->withThankYouNote('Thanks for your purchase!');
```

### Redirects After Purchase

To redirect customers back to your app after purchase, you may use the `redirectTo` method:
Expand Down
34 changes: 32 additions & 2 deletions src/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Checkout implements Responsable

private array $custom = [];

private ?string $productName = null;

private ?string $description = null;

private ?string $thankYouNote = null;

private ?string $redirectUrl;

private ?DateTimeInterface $expiresAt;
Expand Down Expand Up @@ -157,6 +163,27 @@ public function withCustomData(array $custom): self
return $this;
}

public function withProductName(string $productName): self
{
$this->productName = $productName;

return $this;
}

public function withDescription(string $description): self
{
$this->description = $description;

return $this;
}

public function withThankYouNote(string $thankYouNote): self
{
$this->thankYouNote = $thankYouNote;

return $this;
}

public function redirectTo(string $url): self
{
$this->redirectUrl = $url;
Expand Down Expand Up @@ -201,9 +228,12 @@ public function url(): string
], function ($value) {
return ! is_null($value);
}),
'product_options' => [
'product_options' => array_filter([
'name' => $this->productName,
'description' => $this->description,
'receipt_thank_you_note' => $this->thankYouNote,
'redirect_url' => $this->redirectUrl ?? config('lemon-squeezy.redirect_url'),
],
]),
'expires_at' => isset($this->expiresAt) ? $this->expiresAt->format(DateTimeInterface::ATOM) : null,
],
'relationships' => [
Expand Down