post https://secure.fusebill.com/v1/purchases/Purchase?preview=&showZeroDollarCharges=&temporarilyDisableAutoPost=
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:
- You can choose to use the parameter ?preview=true to return a preview DTO but choosing this option will not finalize the purchase
- The default action of this call is to "Follow billing terms"
- Including the
invoiceCollectionOptions
object in the request payload will override the "Follow billing terms" default
URL Parameters
Property | Type | Description | Required |
---|---|---|---|
showZeroDollarCharges | Boolean | If true, then the invoice that might be generated by this request will show zero dollar charges as line items. False by default. | No |
temporarilyDisableAutoPost | Boolean | If true, then the invoice will be created in 'draft' form. False by default | No |
preview | Boolean | If true, results in no system change. A preview of the purchase and the resulting invoice and charges are returned as a response. False by default | No |
Request Parameters
Property | Type | Description | Required |
---|---|---|---|
customerId | Integer | This is the ID of the Customer who has the draft purchases | Yes |
purchaseIds | List of Integers | List of draft purchase IDs | Yes |
invoiceCollectOptions | Object. Defined below | This can be used to provide special invoice collection instructions | Optional |
Invoice collection options
Property | Type | Description |
---|---|---|
paymentMethod | Enum: { UseDefaultPaymentMethod, UseExistingPaymentMethod, UseExistingPaymentMethodAndMakeDefault, UseProvidedPaymentMethodOnce, UseProvidedPaymentMethodAndMakeDefault, UseProvidedPaymentMethodAndSave, CreateAndApplyCredit} | Controls which payment method to use |
paymentMethodId | Integer | ID of the payment method. |
useAnyAvailableFundsFirst | Boolean | Controls whether available funds on the customer entity should be used first. |
creditCard | Object | See credit card creation parameters as outlined in Create Credit Card Payment Method |
achCard | Object | See ACH card creation parameters as outlined in Create ACH Payment Method |
rollbackOnFailedPayment | Boolean | If 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"
}
]
}