Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oCrypt
LOCAL cRequestId
LOCAL oErrorInfo
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")
// Use the original authorization ID to release the hold; do not send an amount.
oHttp:SetUrlVar("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.
oCrypt := CreateObject("Chilkat.Crypt2")
cRequestId := oCrypt:GenerateUuid()
oHttp:SetRequestHeader("PayPal-Request-Id", cRequestId)
nSuccess := oHttp:HttpNoBody("POST", "https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void", oResp)
IF (nSuccess != 1)
? "No HTTP response: " + oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
oCrypt: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()
oCrypt:destroy()
oErrorInfo:destroy()
RETURN
ENDIF
? "Authorization void accepted; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oCrypt:destroy()
oErrorInfo:destroy()