PureBasic Requires Chilkat v11.0.0+
PureBasic
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.
Chilkat PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 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.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkAuthToken(http, "SANDBOX_ACCESS_TOKEN")
resp.i = CkHttpResponse::ckCreate()
If resp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Look up the order itself; its ID does not identify an individual capture.
CkHttp::ckSetUrlVar(http,"id","ORDER_ID")
success = CkHttp::ckHttpNoBody(http,"GET","https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}",resp)
If success <> 1
Debug "No HTTP response: " + CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
If (CkHttpResponse::ckStatusCode(resp) < 200) OR (CkHttpResponse::ckStatusCode(resp) >= 300)
errorInfo.i = CkJsonObject::ckCreate()
If errorInfo.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(errorInfo,CkHttpResponse::ckBodyStr(resp))
Debug "HTTP " + Str(CkHttpResponse::ckStatusCode(resp)) + " " + CkJsonObject::ckStringOf(errorInfo,"name") + " " + CkJsonObject::ckStringOf(errorInfo,"details[0].issue")
Debug "PayPal debug ID: " + CkJsonObject::ckStringOf(errorInfo,"debug_id")
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkJsonObject::ckDispose(errorInfo)
ProcedureReturn
EndIf
result.i = CkJsonObject::ckCreate()
If result.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
parsed.i = CkJsonObject::ckLoad(result,CkHttpResponse::ckBodyStr(resp))
If parsed <> 1
Debug "Expected a JSON response; HTTP " + Str(CkHttpResponse::ckStatusCode(resp))
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkJsonObject::ckDispose(errorInfo)
CkJsonObject::ckDispose(result)
ProcedureReturn
EndIf
Debug "ID: " + CkJsonObject::ckStringOf(result,"id")
Debug "Status: " + CkJsonObject::ckStringOf(result,"status")
Debug "Intent: " + CkJsonObject::ckStringOf(result,"intent")
i.i = 0
While (i < CkJsonObject::ckSizeOfArray(result,"purchase_units"))
CkJsonObject::setCkI(result, i)
Debug CkJsonObject::ckStringOf(result,"purchase_units[i].reference_id") + ": " + CkJsonObject::ckStringOf(result,"purchase_units[i].amount.value") + " " + CkJsonObject::ckStringOf(result,"purchase_units[i].amount.currency_code")
i = i + 1
Wend
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkJsonObject::ckDispose(errorInfo)
CkJsonObject::ckDispose(result)
ProcedureReturn
EndProcedure