Place order and pay

Zuora client libraries version 3.x is in the Early Adopter phase. It integrates both the v1 API and Quickstart API into a unified set of libraries. We recommend that you try our client libraries 3.x to start testing or integrating with Zuora.

End-user flow

After end customers enter the payment method information in the Payment Form, the order is created when they click Pay Now. If the subscription is created and the payment is successfully collected, an invoice is generated with a zero balance that you can choose to send to the customer using their bill-to contact.

Sample code

The following sample code creates an order with the following information:

  • existingAccountNumber: A00024362 (obtained from the "Create a billing account" section)
  • subscribeToRatePlans:
    • productRatePlanNumber: PRP-00000180 (obtained from the "Show specific product details" section)
  • orderDate: 2024-07-01
  • processingOptions:
    • runBilling: true. It means that the invoice is generated while the subscription is created.
    • collectPayment : true. Collects the payment when the invoice is generated.
    • targetDate: the same as the orderDate. The invoice is generated and posted on the same day the order is created.
cURLJavaNode.jsPython
Copy
Copied
curl -L -X POST 'https://rest.test.zuora.com/v1/orders' \
-H 'Authorization: Bearer 82db6bcc9b384c159a37262795f12a0a' \
-H 'Content-Type: application/json' \
-d '{
    "orderDate": "2024-07-01",
    "processingOptions": {
        "runBilling": true,
        "collectPayment": true,
        "billingOptions": {
            "targetDate": "2024-07-01"
        }
    },
    "existingAccountNumber": "A00024362",
    "subscriptions": [
        {
            "orderActions": [
                {
                    "type": "CreateSubscription",
                    "createSubscription": {
                        "terms": {
                         "initialTerm": {
                           "termType": "EVERGREEN"
                         }
                        },
                        "subscribeToRatePlans":[
                            {
                            "productRatePlanNumber": "PRP-00000180"
                            }
                        ]
                    }
                }
            ]
        }
    ]
}'
Copy
Copied
var initialTerm = new InitialTerm().periodType(null).termType(TermType.EVERGREEN);
var terms = new OrderActionCreateSubscriptionTerms().renewalTerms(null).initialTerm(initialTerm);
var ratePlanOverride = new CreateOrderRatePlanOverride().productRatePlanNumber("PRP-00000180");

var createOrderCreateSubs = new CreateOrderCreateSubscription()
        .terms(terms)
        .addSubscribeToRatePlansItem(ratePlanOverride);

var createOrderAction = new CreateOrderAction()
            .type(OrderActionType.CREATESUBSCRIPTION)
            .createSubscription(createOrderCreateSubs);
var subscription = new CreateOrderSubscription().addOrderActionsItem(createOrderAction);

var processingOptions = new ProcessingOptionsWithDelayedCapturePayment()
            .runBilling(true)
            .collectPayment(true)
            .billingOptions(new BillingOptions().targetDate(LocalDate.of(2024,7,1)));

var request = new CreateOrderRequest()
            .existingAccountNumber("A00024362")
            .orderDate(LocalDate.of(2024,7,1))
            .addSubscriptionsItem(subscription)
            .processingOptions(processingOptions);

var createOrderResp = zuoraClient.ordersApi().createOrderApi(request).execute();
System.out.print(createOrderResp);
Copy
Copied
const initialTerm = new InitialTerm();
initialTerm.termType = 'EVERGREEN';
const terms = new OrderActionCreateSubscriptionTerms(initialTerm, null);
const ratePlanOverride = new CreateOrderRatePlanOverride()
ratePlanOverride.productRatePlanNumber = 'PRP-00000770';


const createOrderCreateSubs = new CreateOrderCreateSubscription();
createOrderCreateSubs.terms = terms;
createOrderCreateSubs.subscribeToRatePlans = [ratePlanOverride];


const createOrderAction = new CreateOrderAction('CreateSubscription');
createOrderAction.createSubscription = createOrderCreateSubs;


const subscription = new CreateOrderSubscription();
subscription.orderActions = [createOrderAction];

const date = new Date();
date.setFullYear(2024,7,1);

const processingOptions = new ProcessingOptionsWithDelayedCapturePayment();
processingOptions.runBilling = true;
processingOptions.collectPayment = true;
const billingOptions = new BillingOptions();
billingOptions.targetDate = date.toISOString().split('T')[0];
processingOptions.billingOptions = billingOptions;

const request = new CreateOrderRequest();
request.existingAccountNumber = 'A00000099';
request.orderDate = date.toISOString().split('T')[0];
request.subscriptions = [subscription];
request.processingOptions = processingOptions;
    
const createOrderResp = await zuoraClient.ordersApi.createOrder(request);
console.log(JSON.stringify(createOrderResp, (k, v) => v ?? undefined, 2));
Copy
Copied
from datetime import date
from zuora_sdk import CreateOrderRequest, PreviewOrderRequest, PreviewOrderResponse, CreateOrderResponse, CreateOrderSubscription, \
    ProcessingOptionsWithDelayedCapturePayment
...

def create_order(client=None):
    if not client:
        client = get_client()
    try:
        request = CreateOrderRequest(
            order_date=date.today().strftime('%Y-%m-%d'),
            existing_account_number='A00000001',
            subscriptions=[{
                'order_actions': [{
                    'type': 'CreateSubscription',
                    'create_subscription': {
                        'terms': {'initial_term': {'term_type': 'EVERGREEN'}},
                        'subscribe_to_rate_plans': [{'product_rate_plan_number': 'PRP-00000151'}]
                    }
                }]
            }],
            processing_options=ProcessingOptionsWithDelayedCapturePayment(run_billing=True, collect_payment=True, billing_options={'target_date': date.today().strftime('%Y-%m-%d')}))
        api_response: CreateOrderResponse = client.orders_api().create_order(request)
        print(api_response.to_json())
    except ApiException as e:
        print("Exception when calling OrdersApi->create_order: %s\n" % e)
    return None

if __name__ == '__main__':
    create_order()

If the request succeeds, you will get a response similar to the following snippet:

Copy
Copied
{
    "success": true,
    "orderNumber": "O-00000047",
    "accountNumber": "A00024362",
    "status": "Completed",
    "subscriptionNumbers": [
        "A-S00000031"
    ],
    "invoiceNumbers": [
        "INV00000041"
    ]
}

Next step

View the generated invoice