-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
go/patterns-use-cases/src/webhookcallbacks/callbackrouter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import restate "github.com/restatedev/sdk-go" | ||
|
||
type WebhookCallbackRouter struct{} | ||
|
||
// Any handler can be a durable webhook processor that never loses events | ||
// You don't need to do anything special for this. Just point your webhook to the handler endpoint. | ||
|
||
func (WebhookCallbackRouter) OnStripeEvent(ctx restate.Context, event StripeEvent) error { | ||
if event.Type == "invoice.payment_failed" { | ||
restate.ObjectSend(ctx, "PaymentTracker", "onPaymentFailed", event.Data.Object.ID). | ||
Send(event) | ||
} else if event.Type == "invoice.payment_succeeded" { | ||
restate.ObjectSend(ctx, "PaymentTracker", "onPaymentSuccess", event.Data.Object.ID). | ||
Send(event) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import restate "github.com/restatedev/sdk-go" | ||
|
||
type StripeEvent struct { | ||
ID string `json:"id"` | ||
Type string `json:"type"` | ||
Created int64 `json:"created"` | ||
Data struct { | ||
Object struct { | ||
ID string `json:"id"` | ||
Customer string `json:"customer"` | ||
} `json:"object"` | ||
} `json:"data"` | ||
} | ||
|
||
// Have a look at the scheduling tasks example (../schedulingtasks/paymentreminders.go) | ||
// to see a full implementation of this | ||
|
||
type PaymentTracker struct{} | ||
|
||
func (PaymentTracker) OnPaymentFailed(ctx restate.Context, event StripeEvent) error { return nil } | ||
func (PaymentTracker) OnPaymentSuccess(ctx restate.Context, event StripeEvent) error { return nil } |