Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

PayPal: Look up a checkout order

See more PayPal Examples

Read intent, order status and the amount requested for each purchase unit. A completed checkout order can contain payment resources with their own statuses; use their IDs to inspect individual captures or authorizations.

PayPal documentation

Chilkat Lua Downloads

Lua
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()

-- Look up the order itself; its ID does not identify an individual capture.

http:set_url_var("id", "ORDER_ID")

local success = http:http_no_body("GET", "https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}", 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("Intent: " .. result:string_of("intent"))
local i = 0
while i < result:size_of_array("purchase_units") do
    result.i = i
    print(result:string_of("purchase_units[i].reference_id") .. ": " .. result:string_of("purchase_units[i].amount.value") .. " " .. result:string_of("purchase_units[i].amount.currency_code"))
    i = i + 1
end