Finalize Purchase

This function is used to finalize Draft Purchases. Once finalized, Fusebill creates charges and applies them to the customer account which may trigger invoice creation and payment collection.

Note:

  1. You can choose to use the parameter ?preview=true to return a preview DTO but choosing this option will not finalize the purchase
  2. The default action of this call is to "Follow billing terms"
  3. Including the invoiceCollectionOptions object in the request payload will override the "Follow billing terms" default

URL Parameters

PropertyTypeDescriptionRequired
showZeroDollarChargesBooleanIf true, then the invoice that might be generated by this request will show zero dollar charges as line items. False by default.No
temporarilyDisableAutoPostBooleanIf true, then the invoice will be created in 'draft' form. False by defaultNo
previewBooleanIf true, results in no system change. A preview of the purchase and the resulting invoice and charges are returned as a response. False by defaultNo

Request Parameters

PropertyTypeDescriptionRequired
customerIdIntegerThis is the ID of the Customer who has the draft purchasesYes
purchaseIdsList of IntegersList of draft purchase IDsYes
invoiceCollectOptionsObject. Defined belowThis can be used to provide special invoice collection instructionsOptional

Invoice collection options

PropertyTypeDescription
paymentMethodEnum: { UseDefaultPaymentMethod, UseExistingPaymentMethod, UseExistingPaymentMethodAndMakeDefault, UseProvidedPaymentMethodOnce, UseProvidedPaymentMethodAndMakeDefault, UseProvidedPaymentMethodAndSave, CreateAndApplyCredit}Controls which payment method to use
paymentMethodIdIntegerID of the payment method.
useAnyAvailableFundsFirstBooleanControls whether available funds on the customer entity should be used first.
creditCardObjectSee credit card creation parameters as outlined in Create Credit Card Payment Method
achCardObjectSee ACH card creation parameters as outlined in Create ACH Payment Method
rollbackOnFailedPaymentBooleanIf payment fails, Fusebill can undo the purchase completion and prevent the invoice from posting.
Examples
curl -X POST "https://secure.fusebill.com/v1/Purchases/Purchase?preview=true&showZeroDollarCharges=true&temporarilyDisableAutoPost=true" \
	-H "Content-Type: application/json" \
	-H "Authorization: Basic {APIKey}" \
	-d "{customerId:{CustomerId},id:[{PurchaseId1},{PurchaseId2}]}"
//Json Payload
string jsonData = "{customerId:{CustomerId},id:[{PurchaseId1},{PurchaseId2}]}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/Purchases/Purchase?preview=true&showZeroDollarCharges=true&temporarilyDisableAutoPost=true");
//Add Content type
request.ContentType = "application/json";
//Add Api key authorization
request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + apiKey);
//Set request method
request.Method = "POST";
//Add the json data to request
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
  streamWriter.Write(jsonData);
  streamWriter.Flush();
  streamWriter.Close();
}
//Perform the request
var httpResponse = (HttpWebResponse)request.GetResponse();
//Record the response from our request
var result = "";
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
  result = streamReader.ReadToEnd();
}
#Import library JSON
import json
#Import library Requests
import requests
#Pass in a dictionary to the Headers parameter
headers = {'Authorization' : 'Basic {APIKey}', 'Content-Type' : 'application/json'}
#Pass in a dictionary to the Payload parameter
payload = {"customerId":{id},"purchaseIds":[{id}]}
#Pass in your URI, Payload and Headers
r = requests.post('https://secure.fusebill.com/v1/Purchases/Purchase?preview=true&showZeroDollarCharges=true&temporarilyDisableAutoPost=true', 
data=json.dumps(payload), headers=headers)
print(r.content)
{
    "customerId": 311194,
    "purchaseIds": [
      78717,
      78718,
      78721
    ]
}
{
  "customerId":12345678,
  "purchaseIds":
  [
    96541,
    96542,
    96543
    ],
  "invoiceCollectOptions":
  {
    "paymentMethod":"UseDefaultPaymentMethod",
    "paymentMethodId":null,
    "useAnyAvailableFundsFirst":true,
    "creditCard":null,
    "achCard":null,
    "rollbackOnFailedPayment":true
  }
}
Response
{
   "invoicePreview":{
      "draftCharges":[
         {
            "transactionId":0,
            "chargeTypeId":null,
            "transactionType":"Purchase",
            "quantity":1.0,
            "unitPrice":1.00,
            "amount":1.00,
            "taxableAmount":1.00,
            "subscriptionPeriodId":0,
            "draftInvoiceId":0,
            "name":"Manual Charge",
            "description":"One off charges",
            "effectiveTimestamp":"2017-02-13T18:54:52.0009642Z",
            "proratedUnitPrice":null,
            "startServiceDate":"2017-02-13T18:54:52.0009642Z",
            "endServiceDate":"2017-02-13T18:54:52.0009642Z",
            "rangeQuantity":null,
            "draftDiscount":null,
            "draftDiscounts":[

            ],
            "status":"Active",
            "productItems":null,
            "canProrateCharge":false,
            "postable":true,
            "id":0,
            "uri":null
         }
      ],
      "subtotal":1.00,
      "total":1.00,
      "draftTaxes":[

      ],
      "totalTaxes":0.00,
      "totalDiscount":0.0,
      "poNumber":null,
      "effectiveTimestamp":"0001-01-01T00:00:00",
      "status":"Ready",
      "draftChargeGroups":[
         {
            "name":"Purchases",
            "description":null,
            "reference":null,
            "draftCharges":[
               {
                  "transactionId":0,
                  "chargeTypeId":null,
                  "transactionType":"Purchase",
                  "quantity":1.0,
                  "unitPrice":1.00,
                  "amount":1.00,
                  "taxableAmount":1.00,
                  "subscriptionPeriodId":0,
                  "draftInvoiceId":0,
                  "name":"Manual Charge",
                  "description":"One off charges",
                  "effectiveTimestamp":"2017-02-13T18:54:52.0009642Z",
                  "proratedUnitPrice":null,
                  "startServiceDate":"2017-02-13T18:54:52.0009642Z",
                  "endServiceDate":"2017-02-13T18:54:52.0009642Z",
                  "rangeQuantity":null,
                  "draftDiscount":null,
                  "draftDiscounts":[

                  ],
                  "status":"Active",
                  "productItems":null,
                  "canProrateCharge":false,
                  "postable":true,
                  "id":0,
                  "uri":null
               }
            ]
         }
      ],
      "notes":null,
      "shippingInstructions":null,
      "openingArBalance":16.4600,
      "closingArBalance":17.4600
   }
}
{
    "ErrorId": 0,
    "HttpStatusCode": 400,
    "Errors": [
        {
            "Key": "Api Error",
            "Value": "Unable to complete purchase. The following items do not exist: 123"
        }
    ]
}
Language
Authorization