Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oErrorInfo
LOCAL oResult
LOCAL nParsed
LOCAL i

nSuccess := 0

//  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.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "SANDBOX_ACCESS_TOKEN"
oResp := CreateObject("Chilkat.HttpResponse")

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

oHttp:SetUrlVar("id", "ORDER_ID")

nSuccess := oHttp:HttpNoBody("GET", "https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}", oResp)
IF (nSuccess != 1)
    ? "No HTTP response: " + oHttp:LastErrorText
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

IF ((oResp:StatusCode < 200) .OR. (oResp:StatusCode >= 300))
    oErrorInfo := CreateObject("Chilkat.JsonObject")
    oErrorInfo:Load(oResp:BodyStr)
    ? "HTTP " + Str(oResp:StatusCode) + " " + oErrorInfo:StringOf("name") + " " + oErrorInfo:StringOf("details[0].issue")
    ? "PayPal debug ID: " + oErrorInfo:StringOf("debug_id")
    oHttp:destroy()
    oResp:destroy()
    oErrorInfo:destroy()
    RETURN
ENDIF

oResult := CreateObject("Chilkat.JsonObject")
nParsed := oResult:Load(oResp:BodyStr)
IF (nParsed != 1)
    ? "Expected a JSON response; HTTP " + Str(oResp:StatusCode)
    oHttp:destroy()
    oResp:destroy()
    oErrorInfo:destroy()
    oResult:destroy()
    RETURN
ENDIF

? "ID: " + oResult:StringOf("id")
? "Status: " + oResult:StringOf("status")
? "Intent: " + oResult:StringOf("intent")
i := 0
DO WHILE (i < oResult:SizeOfArray("purchase_units"))
    oResult:I := i
    ? oResult:StringOf("purchase_units[i].reference_id") + ": " + oResult:StringOf("purchase_units[i].amount.value") + " " + oResult:StringOf("purchase_units[i].amount.currency_code")
    i := i + 1
ENDDO

oHttp:destroy()
oResp:destroy()
oErrorInfo:destroy()
oResult:destroy()