Buy Now (Product to Cash) Example
Create a Buy Now solution to let customers select and purchase products using a preconfigured payment method.
To implement a solution, either call the Buy Now Flow or use the REST API. This document explains how to build a Buy Now solution using the REST API.
First, examine this diagram to learn how to chain the REST endpoints. Then read details about each step and navigate to the API reference for each endpoint.
Use SOQL to query for your products and display them to customers for purchase.
After the customer has selected the products and indicated the quantities, pass that information, along with any transaction-level and order-level price adjustments, to /commerce/pricing/{objectName}/actions/calculate-price. Volume discounts are calculated automatically.
The price for each item is returned. If the item is purchased by subscription, the price is calculated for the duration of the subscription.
Create a Subscription Management order with an order action of type New Sale. Create the order items and add them to the order, using the prices from the previous step. When the order is final, activate it by setting the order's Status
field to Activated
.
Create the assets to track the lifecycle of the order items. Assets show you the current quantity, monthly recurring revenue, amount, and invoice line balance of subscription products. Assets also track changes to quantity and cancellations.
Subscribe to the CreateAssetsOrderEvent platform event to learn when the assets are created and to get the IDs of the asset records.
Create the billing schedules. Billing schedules contain information that Subscription Management uses to create invoices. Order items that are invoiced at the same time are added to the same billing schedule group.
Subscribe to the BillingScheduleCreatedEvent platform event to learn when the billing schedules are created and to get the IDs of the billing schedule records.
Generate the invoices for the order, using the following values.
Parameter | Value |
---|---|
invoiceDate | order.EffectiveDate |
targetDate | order.EffectiveDate |
invoiceStatus | Posted |
Two invoices are generated for each order item: one invoice for the cost of the item, and one invoice for the tax.
If the order item is sold by subscription, the first set of invoices contains the amounts owing for the first billing period.
Subscribe to the InvoiceProcessedEvent platform event to learn when the invoices are created and to get the IDs of the invoice records.
Make a payment sale to process the payment.
Subscribe to the PaymentCreationEvent platform event to learn when the payment is processed and to get the IDs of the payment records.
Apply the payment to the invoice.