Lua Requires Chilkat v11.0.0+
Lua
PayPal: Void an unused authorization
See more PayPal Examples
Release an unused hold with the authorization ID. A fully captured authorization cannot be voided; refund its capture instead. A successful void can have an empty response body.
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 the original authorization ID to release the hold; do not send an amount.
http:set_url_var("id", "AUTHORIZATION_ID")
-- Create and persist this key once per business operation. On a timeout,
-- retry the same request with its saved key, not a newly generated one.
local crypt = chilkat.Crypt2.new()
local requestId = crypt:generate_uuid()
http:set_request_header("PayPal-Request-Id", requestId)
local success = http:http_no_body("POST", "https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void", 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
print("Authorization void accepted; HTTP " .. resp.status_code)