This example shows how to create a workflow similar to an Amazon Dash Button. An Amazon Dash Button triggers actions when someone clicks on it. It is often used for something you need regularly. During the process, the customer needs to be charged and receive the billing according to the payment process. Stripe - in charge of payment - and Quickbooks -for the billing - are two connectors used in the example to interact with external services.
This flowchart helps to visualize different tasks within the workflow.
View the workflow code on Github here. View all of the files, fork the project and deploy to heroku in a few clicks.
This workflow is the code that orchestrates tasks (through the Zenaton workflow engine) and executes them on your servers. Tasks will be dispatched as soon as the user presses the button to order something.
const { workflow, duration } = require("zenaton");
module.exports = workflow("OrderFromDashButton", {
*handle(order) {
const stripe = this.connector(
'stripe',
'your-stripe-connector-id-from-zenaton-dashboard'
);
const quickbooks = this.connector(
'quickbooks',
'your-quickbooks-connector-id-from-zenaton-dashboard'
);
const charge = yield stripe.post(`/v1/charges`, {amount: order.total});
const capture_response = yield stripe.post(`/v1/charges/${charge.id}/capture`);
const charged = capture_response.captured
let event = null;
if (!charged) {
this.run.task("AskForNewPaymentDetails", order);
event = yield this.wait.event("OrderPaid").for(duration.weeks(2));
}
if (charged || event) {
const realmID = order.realmID
const email = order.email
// Create an invoice
const invoice_lines = this.invoice_lines(order);
const invoice = yield quickbooks.post(`/v3/company/${realmID}/invoice`, invoice_lines);
// Send the invoice
yield quickbooks.post(`/v3/company/${realmID}/invoice/${invoice.Invoice.Id}/send?sendTo=${email}`);
this.run.task("SendOrderToShipping", order);
} else {
this.run.task("CancelOrder", order);
}
},
invoice_lines: function(order) {
// ...
}
});
Sample Projects
Start building workflows
Sign-up and run a sample project Learn more