Skip to content

Latest commit

 

History

History
50 lines (41 loc) · 1.25 KB

invoice-receipt.mdx

File metadata and controls

50 lines (41 loc) · 1.25 KB
title description
Invoice Receipt
Send invoices or receipts immediately after a user purchases.

Introduction

Invoices and receipts require custom fields such as the order number, billing details, and objects purchased which must be dynamically fetched from the database. The use of step controls and the payload schema simplifies the fetching of that unique data.

Explore the source code on GitHub

Preview

<img style={{ borderRadius: '0.5rem' }} src="/images/how-to/invoice-receipt.png" />

Code example

import { workflow } from '@novu/framework';
import { renderAppleReceiptEmail } from '../emails/apple-receipt';
import { zodControlSchema, jsonSchema, zodPayloadSchema } from './schemas';

/**
 * Apple Receipt workflow
 */
export const appleReceipt = workflow(
  "Apple Receipt",
  async ({ step, payload }) => {
    await step.email(
      "send-email",
      async (controls) => {
        return {
          subject: controls.receiptSubject,
          body: renderAppleReceiptEmail(controls, payload),
        };
      },
      {
        controlSchema: zodControlSchema
      },
    );
  },
  { 
    payloadSchema: zodPayloadSchema
  }
);