Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
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 Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkCrypt2W.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = 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.
CkHttpW http;
http.put_AuthToken(L"SANDBOX_ACCESS_TOKEN");
CkHttpResponseW resp;
// Use the original authorization ID to release the hold; do not send an amount.
http.SetUrlVar(L"id",L"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.
CkCrypt2W crypt;
const wchar_t *requestId = crypt.generateUuid();
http.SetRequestHeader(L"PayPal-Request-Id",requestId);
success = http.HttpNoBody(L"POST",L"https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void",resp);
if (success != true) {
wprintf(L"No HTTP response: %s\n",http.lastErrorText());
return;
}
if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
CkJsonObjectW errorInfo;
errorInfo.Load(resp.bodyStr());
wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),errorInfo.stringOf(L"name"),errorInfo.stringOf(L"details[0].issue"));
wprintf(L"PayPal debug ID: %s\n",errorInfo.stringOf(L"debug_id"));
return;
}
wprintf(L"Authorization void accepted; HTTP %d\n",resp.get_StatusCode());
}