API Calls for Pre-paid Scenario

This developer guide shows the typical sequence of activities relevant for pre-paid subscription plans.

Sample Plan and Charges

For this example, consider a hypothetical web hosting company, called "DaddyHost", wishes to introduce a plan that has two charges:

Note: The configuration of the sample plan above is covered in detail under [Guides and How To] >> [Sample Pre-paid Plan].

DaddyHost wishes to collect pro-rated payment upfront when the customer signs up. In order to simplify their billing, they have chosen to bill all their customers on the 1st of every month (rather than opt for Anniversary billing). See the [Guides and How To] >> [Sample Pre-paid Plan] for details on these choices.

API Calls Invoked for New Customer Signup

The BluBilling REST API details are covered here. This guide will provide insights on the sequence of API calls that need to be invoked in order to meet DaddyHost's requirements.

DaddyHost would collect the following information from the prospective customer on their website:

Then, DaddyHost would initiate the following calls from their website.

1. Create the Customer

DaddyHost also creates an account on their system, so they have their own identifier for the customer (JOHNDOE001). So DaddyHost makes the following request:

POST  /rest/customers?format=xml


    <name>John Doe</name>  


    <extCustomerRef>JOHNDOE001</extCustomerRef> <!-- DaddyHost assigned Customer ID -->



    <currency id="USD"/>




        <accountLocked>true</accountLocked> <!-- Prevents the customer from logging into BluBilling -->




        <workPhone>555 555 5555</workPhone>


            <street1>43 Main Av</street1>




            <country>United States</country>





The response echoed back from BluBilling (abridged for brevity) contains the values sent along with defaults populated and identifiers assigned as seen below.

<customer id="366">  <!-- BluBilling assigned Customer ID -->

    <name>John Doe</name>  





So, going forward we could either use the BluBilling assigned customer Id (366) or refrence the customer using the DaddyHost assigned identifier (JOHNDOE001).

2. Create the Order

The SubscriptionOrder represents the association between the above customer and a particular Plan. So we want to create an Order and generate an Invoice as well so that we know the exact amount to pay.

POST rest/orders?format=xml&extCustomerRef=JOHNDOE001&generateInvoice=true



    <startDate>2011-09-20</startDate> <!-- The start date can be in the future if a free trial period is offered -->


    <contractCode>WHITE-LBL-A</contractCode> <!-- the Plan associated with this order -->




        <quantity>1.0</quantity> <!-- the quantity is required -->

        <priceCode>MNTHLY</priceCode>  <!-- each charge associated with plan -->




Since we have the "generateInvoice=true" querystring parameter, an invoice will be immediately generated for this customer and returned in the response:  

<subscriptionOrder id="381">



    <customer id="366" />


     <!-- other order fields -->


        <invoice id="2396">


            <outstandingBalance>60.50</outstandingBalance> <!-- Amount to pay -->


            <invoiceNumber>1019</invoiceNumber> <!-- End user only sees the invoiceNumber, not the id -->





                <!-- Invoice line Item details -->





At this point, an Order has been placed, and since it is a pre-paid order with the generateInvoice flag set, it has already been invoiced for the correct amount. Note that in the above case the amount has been adjusted so that the charge is pro-rated to account for the mid-month start date.

Note: In simple cases it may be possible for the calling application to pre-determine the amount, but in complex cases (e.g., taxes, discounts, pro-rating, tiered pricing, etc.), it would be best to let BluBilling generate an invoice so that the precise amount can be calculated per the configured business rules.

3. Remit the Payment

Once the invoice has been generated, the correct amount may be presented to the user for payment. A request for processing payment using a credit card is show below.

POST  rest/payments?format=xml&extCustomerRef=JOHNDOE001

Request XML:






        <invoice id="2396" />


    <paymentMethodDTO type="CreditCard">


            <!-- Set to 1, 2, or 3 to save as customer's preferred auto-pay method -->








And the Response:

<payment id="213">


    <customer id="366" />


    <currency id="USD" />

    <amount>60.50</amount> <!-- validate amount -->


    <status>Paid</status>   <!-- Use this element to validate that payment is successful -->




    <processorResult id="192">

        <customer id="366" />






        <!-- Address verification result: Y = Match (AVS ok); N = No Match (AVS fail); X = Unsupported -->


                    <!-- CVV result: Y = Match (CVV ok); N = No Match (CVV fail); X = Unsupported-->



        <payment id="213" />




        <approvalCode>0S33CM</approvalCode> <!-- Correlate with payment processor statements-->

        <statusMessage>RRC_1_1 : This transaction has been approved.</statusMessage>

        <errorCode />



        <batchIndicator />

        <errorMessage />

        <paymentProcessor id="6" />


    <paymentMethodContext>Visa: 1111</paymentMethodContext>


    <paymentProcessor id="6">

        <name>Authorize.NET V1</name>



        <invoicePayment id="171">

            <payment id="213" />


            <invoice id="2396" />

            <customer id="366" />




If the payment attempt is successful, then nothing more needs to be done. BluSynergy's BluBilling system will generate invoices periodically and perform the bill-presentment. If the <autopayPreferance> element had been set in the request XML, then the customer's credit card or bank account will be automatically billed for the monthly amount.

If the payment does not go though, DaddyHost's policy is to allow the customer upto three retry attempts before cancelling the order and invoice. See the "API calls for change management" section on how to cancel the invoice and order.

Note: Once an Invoice has been generated, the Order cannot be deleted. The recommended practice is to Cancel the Invoice and Suspend the Order.