Sample code for 30+ languages & platforms
Lua

Shippo Create a Refund

See more Shippo Examples

Demonstrates how to refund a shipping label.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl  https://api.goshippo.com/refunds/ \
--     -H "Authorization: ShippoToken <API_Token>" \
--     -d transaction="4503427478ea45a899e9b54abc4c5803"

local req = chilkat.HttpRequest.new()
req.http_verb = "POST"
req.path = "/refunds/"
req.content_type = "application/x-www-form-urlencoded"
req:add_param("transaction", "4503427478ea45a899e9b54abc4c5803")

req:add_header("Authorization", "ShippoToken <API_Token>")

local resp = chilkat.HttpResponse.new()
local success = http:http_req("https://api.goshippo.com/refunds/", req, resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "object_created": "2014-04-21T07:12:41.044Z",
--   "object_id": "bd7b8379a2e847bcb0818125943dde5d",
--   "object_owner": "shippotle@goshippo.com",
--   "object_updated": "2014-04-21T07:12:41.045Z",
--   "status": "QUEUED",
--   "transaction": "35ed59f23a514ecfa2faeaed93a00086"
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local object_created = jResp:string_of("object_created")
local object_id = jResp:string_of("object_id")
local object_owner = jResp:string_of("object_owner")
local object_updated = jResp:string_of("object_updated")
local status = jResp:string_of("status")
local transaction = jResp:string_of("transaction")