SQL Server / Razorpay APIs / Create an Invoice
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OASetProperty @http, 'BasicAuth', 1
EXEC sp_OASetProperty @http, 'Login', 'username'
EXEC sp_OASetProperty @http, 'Password', 'password'
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "type": "invoice",
-- "description": "Domestic invoice for Gaurav Kumar.",
-- "partial_payment": true,
-- "customer": {
-- "name": "Gaurav Kumar",
-- "contact": "9876543210",
-- "email": "gaurav.kumar@example.com",
-- "billing_address": {
-- "line1": "Ground FLoor, Millennium Tower, 1st Avenue",
-- "line2": "1st Avenue",
-- "zipcode": "560001",
-- "city": "Bangalore",
-- "state": "Karnataka",
-- "country": "India"
-- },
-- "shipping_address": {
-- "line1": "3rd FLoor, Nakamura Tower, Bomaye Boulevard",
-- "line2": "Baker Street",
-- "zipcode": "560001",
-- "city": "Bangalore",
-- "state": "Karnataka",
-- "country": "in"
-- }
-- },
-- "line_items": [
-- {
-- "name": "Crate of sea weed",
-- "description": "Crate of sea weed.",
-- "amount": 20000,
-- "currency": "INR",
-- "quantity": 1
-- },
-- {
-- "item_id": "{item_id}"
-- }
-- ],
-- "sms_notify": 1,
-- "email_notify": 1,
-- "draft": "1",
-- "date": 1588076279,
-- "expire_by": 1924991999,
-- "receipt": "Receipt No. 1",
-- "comment": "Fresh sea weed mowed this morning",
-- "terms": "No Returns; No Refunds",
-- "notes": {
-- "notes_key_1": "Tea, Earl Grey, Hot",
-- "notes_key_2": "Tea, Earl Grey… decaf."
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'invoice'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', 'Domestic invoice for Gaurav Kumar.'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'partial_payment', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.name', 'Gaurav Kumar'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.contact', '9876543210'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.email', 'gaurav.kumar@example.com'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.line1', 'Ground FLoor, Millennium Tower, 1st Avenue'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.line2', '1st Avenue'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.zipcode', '560001'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.city', 'Bangalore'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.state', 'Karnataka'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.billing_address.country', 'India'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.line1', '3rd FLoor, Nakamura Tower, Bomaye Boulevard'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.line2', 'Baker Street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.zipcode', '560001'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.city', 'Bangalore'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.state', 'Karnataka'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customer.shipping_address.country', 'in'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].name', 'Crate of sea weed'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].description', 'Crate of sea weed.'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'line_items[0].amount', 20000
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].currency', 'INR'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'line_items[0].quantity', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[1].item_id', '{item_id}'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'sms_notify', 1
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'email_notify', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'draft', '1'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'date', 1588076279
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'expire_by', 1924991999
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipt', 'Receipt No. 1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'comment', 'Fresh sea weed mowed this morning'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'terms', 'No Returns; No Refunds'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'notes.notes_key_1', 'Tea, Earl Grey, Hot'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'notes.notes_key_2', 'Tea, Earl Grey… decaf.'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.razorpay.com/v1/invoices', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
Curl Command
curl -X POST
-u 'username:password'
-H "Content-Type: application/json"
-d '{
"type": "invoice",
"description": "Domestic invoice for Gaurav Kumar.",
"partial_payment": true,
"customer": {
"name": "Gaurav Kumar",
"contact": "9876543210",
"email": "gaurav.kumar@example.com",
"billing_address": {
"line1": "Ground FLoor, Millennium Tower, 1st Avenue",
"line2": "1st Avenue",
"zipcode": "560001",
"city": "Bangalore",
"state": "Karnataka",
"country": "India"
},
"shipping_address": {
"line1": "3rd FLoor, Nakamura Tower, Bomaye Boulevard",
"line2": "Baker Street",
"zipcode": "560001",
"city": "Bangalore",
"state": "Karnataka",
"country": "in"
}
},
"line_items": [
{
"name": "Crate of sea weed",
"description": "Crate of sea weed.",
"amount": 20000,
"currency": "INR",
"quantity": 1
},
{
"item_id": "{item_id}"
}
],
"sms_notify": 1,
"email_notify": 1,
"draft": "1",
"date": 1588076279,
"expire_by": 1924991999,
"receipt": "Receipt No. 1",
"comment": "Fresh sea weed mowed this morning",
"terms": "No Returns; No Refunds",
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
}
}'
https://api.razorpay.com/v1/invoices
Postman Collection Item JSON
{
"name": "Create an Invoice",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"type\": \"invoice\",\n \"description\": \"Domestic invoice for Gaurav Kumar.\",\n \"partial_payment\": true,\n \"customer\": {\n \"name\": \"Gaurav Kumar\",\n \"contact\": \"9876543210\",\n \"email\": \"gaurav.kumar@example.com\",\n \"billing_address\": {\n \"line1\": \"Ground FLoor, Millennium Tower, 1st Avenue\",\n \"line2\": \"1st Avenue\",\n \"zipcode\": \"560001\",\n \"city\": \"Bangalore\",\n \"state\": \"Karnataka\",\n \"country\": \"India\"\n },\n \"shipping_address\": {\n \"line1\": \"3rd FLoor, Nakamura Tower, Bomaye Boulevard\",\n \"line2\": \"Baker Street\",\n \"zipcode\": \"560001\",\n \"city\": \"Bangalore\",\n \"state\": \"Karnataka\",\n \"country\": \"in\"\n }\n },\n \"line_items\": [\n {\n \"name\": \"Crate of sea weed\",\n \"description\": \"Crate of sea weed.\",\n \"amount\": 20000,\n \"currency\": \"INR\",\n \"quantity\": 1\n },\n {\n \"item_id\": \"{item_id}\"\n }\n ],\n \"sms_notify\": 1,\n \"email_notify\": 1,\n \"draft\": \"1\",\n \"date\": 1588076279,\n \"expire_by\": 1924991999,\n \"receipt\": \"Receipt No. 1\",\n \"comment\": \"Fresh sea weed mowed this morning\",\n \"terms\": \"No Returns; No Refunds\",\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n }\n}"
},
"url": {
"raw": "https://api.razorpay.com/v1/invoices",
"protocol": "https",
"host": [
"api",
"razorpay",
"com"
],
"path": [
"v1",
"invoices"
],
"query": [
{
"key": "count",
"value": "10",
"disabled": true
},
{
"key": "skip",
"value": "10",
"disabled": true
}
]
},
"description": "Create an Invoice using the Create an Invoice API.\n\nSome points to note. You can:\n- Create a blank invoice (with no details at all) in draft state.\n- Update it with necessary information.\n- Issue it at a later time with the Issue Invoice API. Only after the invoice is issued, you will get a short URL. Also, only after the invoice is issued, it can be sent to customers and the corresponding payment can be made against it.\n- Use <a href=\"https://razorpay.com/docs/api/items/\" target=\"_blank\">Items APIs</a> to create items which you can later use as a template to create line items in an invoice.\n\nKnow more about the <a href=\"https://razorpay.com/docs/api/invoices/#create-an-invoice\" target=\"_blank\">Create an Invoice API</a>."
},
"response": [
]
}