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.

Buy Now Solution

(1) Query Active Products 

Use SOQL to query for your products and display them to customers for purchase.

(2) Calculate Prices 

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.

(3) Create the Order 

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.

(4) Create the Assets 

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.

(5) Bill the Order 

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.

(6) Generate the Invoices 

Generate the invoices for the order, using the following values.

ParameterValue
invoiceDateorder.EffectiveDate
targetDateorder.EffectiveDate
invoiceStatusPosted

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.

(7) Process the Payment 

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.

(8) Apply the Payment to the Invoice 

Apply the payment to the invoice.

Release Preview

This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.