DavidAJohn / PhotoPortfolio

Personal photo portfolio .NET web application which implements a Blazor and Tailwind CSS user interface with a MongoDb database, and includes integration with Stripe Checkout and Prodigi Print API
0 stars 0 forks source link

Order callback URL & CloudEvents #67

Open DavidAJohn opened 8 months ago

DavidAJohn commented 8 months ago

When an order is placed with Prodigi, they can send callbacks to a public URL that is either listed in the Order object sent or set globally in your Prodigi dashboard. This callbacks provide updates to the status of the order as it progresses.

At the moment, the application sends a localhost url in the callbackUrl field to the sandbox API because it's not a real order.

But realistically, the application should have a means of receiving and processing the callbacks so that the order can be updated in the database. There needs to be a 'callbacks' endpoint within the API, created via a controller. The callbacks can then be processed in a manner that is similar to the way Stripe Webhook events are processed in the Payments Controller.

These callbacks are sent by Prodigi as CloudEvents.

Some links for reference purposes:

Prodigi callbacks documentation CloudEvents C# SDK on GitHub CloudEvents v1.0 spec

DavidAJohn commented 3 months ago

The callback URL that is added to a Prodigi order is now generated dynamically via a config value that supplies the application's base URL. The order id is then suffixed, eg. {ApplicationBaseUrl}/api/callbacks/{order id}

As illustrated in this commit: ed92cd285f16d16badaaa72253a878927c349f4a

DavidAJohn commented 4 weeks ago

What I'd like to do here is initially just save each incoming callback as a JSON object for reference purposes.

I'd also like to deserialize the callback and handle the primary (and possibly only) use case, which is for notifications about changes in the status of an order. The 'data' property of the callback should contain on 'order' object that can be deserialized to a Prodigi Order model class. The current status can then be checked and updated as appropriate, with any further details or issues recorded against the order.