PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Crypt
string ls_RequestId
oleobject loo_ErrorInfo
li_Success = 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.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.AuthToken = "SANDBOX_ACCESS_TOKEN"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
// Use the original authorization ID to release the hold; do not send an amount.
loo_Http.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.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
ls_RequestId = loo_Crypt.GenerateUuid()
loo_Http.SetRequestHeader("PayPal-Request-Id",ls_RequestId)
li_Success = loo_Http.HttpNoBody("POST","https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void",loo_Resp)
if li_Success <> 1 then
Write-Debug "No HTTP response: " + loo_Http.LastErrorText
destroy loo_Http
destroy loo_Resp
destroy loo_Crypt
return
end if
if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
loo_ErrorInfo = create oleobject
li_rc = loo_ErrorInfo.ConnectToNewObject("Chilkat.JsonObject")
loo_ErrorInfo.Load(loo_Resp.BodyStr)
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_ErrorInfo.StringOf("name") + " " + loo_ErrorInfo.StringOf("details[0].issue")
Write-Debug "PayPal debug ID: " + loo_ErrorInfo.StringOf("debug_id")
destroy loo_Http
destroy loo_Resp
destroy loo_Crypt
destroy loo_ErrorInfo
return
end if
Write-Debug "Authorization void accepted; HTTP " + string(loo_Resp.StatusCode)
destroy loo_Http
destroy loo_Resp
destroy loo_Crypt
destroy loo_ErrorInfo