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 <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkCrypt2W.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkHttpResponseW resp;
HCkCrypt2W crypt;
const wchar_t *requestId;
HCkJsonObjectW errorInfo;
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.
http = CkHttpW_Create();
CkHttpW_putAuthToken(http,L"SANDBOX_ACCESS_TOKEN");
resp = CkHttpResponseW_Create();
// Use the original authorization ID to release the hold; do not send an amount.
CkHttpW_SetUrlVar(http,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.
crypt = CkCrypt2W_Create();
requestId = CkCrypt2W_generateUuid(crypt);
CkHttpW_SetRequestHeader(http,L"PayPal-Request-Id",requestId);
success = CkHttpW_HttpNoBody(http,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",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkCrypt2W_Dispose(crypt);
return;
}
if ((CkHttpResponseW_getStatusCode(resp) < 200) || (CkHttpResponseW_getStatusCode(resp) >= 300)) {
errorInfo = CkJsonObjectW_Create();
CkJsonObjectW_Load(errorInfo,CkHttpResponseW_bodyStr(resp));
wprintf(L"HTTP %d %s %s\n",CkHttpResponseW_getStatusCode(resp),CkJsonObjectW_stringOf(errorInfo,L"name"),CkJsonObjectW_stringOf(errorInfo,L"details[0].issue"));
wprintf(L"PayPal debug ID: %s\n",CkJsonObjectW_stringOf(errorInfo,L"debug_id"));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkCrypt2W_Dispose(crypt);
CkJsonObjectW_Dispose(errorInfo);
return;
}
wprintf(L"Authorization void accepted; HTTP %d\n",CkHttpResponseW_getStatusCode(resp));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkCrypt2W_Dispose(crypt);
CkJsonObjectW_Dispose(errorInfo);
}