Lua Requires Chilkat v11.0.0+
Lua
PayPal: Revise a draft invoice from its full billing record
See more PayPal Examples
PUT replaces the invoice. This example revises the quantity on the simple two-inspection draft to three. Rebuild the complete editable document from your billing record; omitted items, terms or recipients can be lost. Do not use this body for an unrelated invoice.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- See Unlock Chilkat before making requests.
-- For the merchant's internal backoffice application. Load the sandbox token
-- from the merchant's credential store. Keep it out of publicly distributed apps.
-- See Get a PayPal access token.
local http = chilkat.Http.new()
http.auth_token = "SANDBOX_ACCESS_TOKEN"
local resp = chilkat.HttpResponse.new()
-- Use only the ID of the matching draft from the create example, while it is still a
-- draft. Preserve all of your real draft fields, including any custom invoice number.
http:set_url_var("id", "INVOICE_ID")
http:set_request_header("Prefer", "return=representation")
local body = chilkat.JsonObject.new()
body:update_string("detail.currency_code", "USD")
body:update_string("detail.payment_term.term_type", "NET_30")
body:update_string("primary_recipients[0].billing_info.email_address", "buyer@example.com")
body:update_string("items[0].name", "Equipment inspection")
body:update_string("items[0].quantity", "3")
body:update_string("items[0].unit_amount.currency_code", "USD")
body:update_string("items[0].unit_amount.value", "45.00")
local success = http:http_json("PUT", "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}", body, "application/json", resp)
if not success then
print("No HTTP response: " .. http.last_error_text)
return
end
if (resp.status_code < 200) or (resp.status_code >= 300) then
local errorInfo = chilkat.JsonObject.new()
errorInfo:load(resp.body_str)
print("HTTP " .. resp.status_code .. " " .. errorInfo:string_of("name") .. " " .. errorInfo:string_of("details[0].issue"))
print("PayPal debug ID: " .. errorInfo:string_of("debug_id"))
return
end
local result = chilkat.JsonObject.new()
local parsed = result:load(resp.body_str)
if not parsed then
print("Expected a JSON response; HTTP " .. resp.status_code)
return
end
print("ID: " .. result:string_of("id"))
print("Status: " .. result:string_of("status"))
print("New total: " .. result:string_of("amount.value"))
print("Currency: " .. result:string_of("amount.currency_code"))