Lua Requires Chilkat v11.0.0+
Lua
PayPal: Find successful Express Checkout transactions
See more PayPal Examples
Filter a reporting window by T0006 (Express Checkout) and S (success). The signed amount distinguishes money received from money sent. This is one transaction class, not all merchant sales; reporting access is required.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local success = false
-- 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 UTC window containing the transaction (at most 31 days per request).
local dt = chilkat.DateTime.new()
dt:set_from_current_system_time()
local query = chilkat.JsonObject.new()
query:update_string("end_date", dt:get_as_timestamp(false))
dt:add_days(-1)
query:update_string("start_date", dt:get_as_timestamp(false))
query:update_string("fields", "transaction_info")
query:update_int("page_size", 100)
query:update_string("transaction_type", "T0006")
query:update_string("transaction_status", "S")
local page = 1
local lastPage = 1
while page <= lastPage do
query:update_int("page", page)
success = http:http_params("GET", "https://api-m.sandbox.paypal.com/v1/reporting/transactions", query, 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
local i = 0
local count = result:size_of_array("transaction_details")
while i < count do
result.i = i
print(result:string_of("transaction_details[i].transaction_info.transaction_id") .. " " .. result:string_of("transaction_details[i].transaction_info.transaction_event_code") .. " " .. result:string_of("transaction_details[i].transaction_info.transaction_status"))
print(" " .. result:string_of("transaction_details[i].transaction_info.transaction_amount.value") .. " " .. result:string_of("transaction_details[i].transaction_info.transaction_amount.currency_code"))
i = i + 1
end
lastPage = result:int_of("total_pages")
page = page + 1
end