Skip to content

Commit 4816ba5

Browse files
authored
Add docs for transforming WebhookCall payload into Stripe object (#129)
1 parent 57dd30a commit 4816ba5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,40 @@ Example config for Connect might look like:
316316
'signing_secret_connect' => 'whsec_123',
317317
```
318318

319+
### Transforming the Webhook payload into a Stripe Object
320+
321+
You can transform the Webhook payload into a Stripe object to assist in accessing its various methods and properties.
322+
323+
To do this, use the `Stripe\Event::constructFrom($payload)` method with the `WebhookCall`'s payload:
324+
325+
```php
326+
use Stripe\Event;
327+
328+
// ...
329+
330+
public function handle(WebhookCall $webhookCall)
331+
{
332+
/** @var \Stripe\StripeObject|null */
333+
$stripeObject = Event::constructFrom($webhookCall->payload)->data?->object;
334+
}
335+
```
336+
337+
For example, if you have setup a Stripe webhook for the `invoice.created` event, you can transform the payload into a `StripeInvoice` object:
338+
339+
```php
340+
/** @var \Stripe\StripeInvoice|null */
341+
$stripeInvoice = Event::constructFrom($webhookCall->payload)->data?->object;
342+
343+
// $stripeInvoice->status
344+
// $stripeInvoice->amount_due
345+
// $stripeInvoice->amount_paid
346+
// $stripeInvoice->amount_remaining
347+
348+
foreach ($stripeInvoice->lines as $invoiceLine) {
349+
// ...
350+
}
351+
```
352+
319353
### About Cashier
320354

321355
[Laravel Cashier](https://laravel.com/docs/5.5/billing#handling-stripe-webhooks) allows you to easily handle Stripe subscriptions. You may install it in the same application together with `laravel-stripe-webhooks`. There are no known conflicts.

0 commit comments

Comments
 (0)