Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loCrypt
LOCAL lcRequestId
LOCAL loErrorInfo
lnSuccess = 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.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
* Use the original authorization ID to release the hold; do not send an amount.
loHttp.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.
loCrypt = CreateObject('Chilkat.Crypt2')
lcRequestId = loCrypt.GenerateUuid()
loHttp.SetRequestHeader("PayPal-Request-Id",lcRequestId)
lnSuccess = loHttp.HttpNoBody("POST","https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loCrypt
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loCrypt
RELEASE loErrorInfo
CANCEL
ENDIF
? "Authorization void accepted; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loCrypt
RELEASE loErrorInfo