Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

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.

PayPal documentation

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  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 = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("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 = ObjCreate("Chilkat.Crypt2")
Local $sRequestId = $oCrypt.GenerateUuid()
$oHttp.SetRequestHeader "PayPal-Request-Id",$sRequestId

$bSuccess = $oHttp.HttpNoBody("POST","https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void",$oResp)
If ($bSuccess <> True) Then
    ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
    Exit
EndIf

If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    $oErrorInfo = ObjCreate("Chilkat.JsonObject")
    $oErrorInfo.Load($oResp.BodyStr)
    ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
    ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
    Exit
EndIf

ConsoleWrite("Authorization void accepted; HTTP " & $oResp.StatusCode & @CRLF)