Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a2ff1b7

Browse files
UrosCodesdriesvints
andauthoredJul 18, 2023
Add support for custom name, description at checkout. And receipt_thank_you_note. (lmsqueezy#34)
* Update Checkout.php Checkout have name description of product * wip * wip --------- Co-authored-by: Dries Vints <dries@vints.be>
1 parent 6182bdc commit a2ff1b7

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed
 

‎README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,25 @@ Route::get('/buy', function (Request $request) {
286286
});
287287
```
288288

289+
### Product Details
290+
291+
You can overwrite additional data for product checkouts with the `withProductName` and `withDescription` methods:
292+
293+
```php
294+
$request->user()->checkout('variant-id')
295+
->withProductName('Ebook')
296+
->withDescription('A thrilling novel!');
297+
```
298+
299+
### Receipt Thank You
300+
301+
Additionally, you can customize the thank you note for the order receipt email.
302+
303+
```php
304+
$request->user()->checkout('variant-id')
305+
->withThankYouNote('Thanks for your purchase!');
306+
```
307+
289308
### Redirects After Purchase
290309

291310
To redirect customers back to your app after purchase, you may use the `redirectTo` method:

‎src/Checkout.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Checkout implements Responsable
3030

3131
private array $custom = [];
3232

33+
private ?string $productName = null;
34+
35+
private ?string $description = null;
36+
37+
private ?string $thankYouNote = null;
38+
3339
private ?string $redirectUrl;
3440

3541
private ?DateTimeInterface $expiresAt;
@@ -157,6 +163,27 @@ public function withCustomData(array $custom): self
157163
return $this;
158164
}
159165

166+
public function withProductName(string $productName): self
167+
{
168+
$this->productName = $productName;
169+
170+
return $this;
171+
}
172+
173+
public function withDescription(string $description): self
174+
{
175+
$this->description = $description;
176+
177+
return $this;
178+
}
179+
180+
public function withThankYouNote(string $thankYouNote): self
181+
{
182+
$this->thankYouNote = $thankYouNote;
183+
184+
return $this;
185+
}
186+
160187
public function redirectTo(string $url): self
161188
{
162189
$this->redirectUrl = $url;
@@ -201,9 +228,12 @@ public function url(): string
201228
], function ($value) {
202229
return ! is_null($value);
203230
}),
204-
'product_options' => [
231+
'product_options' => array_filter([
232+
'name' => $this->productName,
233+
'description' => $this->description,
234+
'receipt_thank_you_note' => $this->thankYouNote,
205235
'redirect_url' => $this->redirectUrl ?? config('lemon-squeezy.redirect_url'),
206-
],
236+
]),
207237
'expires_at' => isset($this->expiresAt) ? $this->expiresAt->format(DateTimeInterface::ATOM) : null,
208238
],
209239
'relationships' => [

0 commit comments

Comments
 (0)
Failed to load comments.