PureBasic Requires Chilkat v11.0.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkCrypt2.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
; Use the original authorization ID to release the hold; do not send an amount.
CkHttp::ckSetUrlVar(http,"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.
crypt.i = CkCrypt2::ckCreate()
If crypt.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
requestId.s = CkCrypt2::ckGenerateUuid(crypt)
CkHttp::ckSetRequestHeader(http,"PayPal-Request-Id",requestId)
success = CkHttp::ckHttpNoBody(http,"POST","https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void",resp)
If success <> 1
Debug "No HTTP response: " + CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkCrypt2::ckDispose(crypt)
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)
CkCrypt2::ckDispose(crypt)
CkJsonObject::ckDispose(errorInfo)
ProcedureReturn
EndIf
Debug "Authorization void accepted; HTTP " + Str(CkHttpResponse::ckStatusCode(resp))
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkCrypt2::ckDispose(crypt)
CkJsonObject::ckDispose(errorInfo)
ProcedureReturn
EndProcedure