Unicode C Requires Chilkat v11.0.0+
Unicode C
PayPal: Cancel a sent, unpaid invoice
See more PayPal Examples
Cancel an unpaid invoice that has already been sent and notify the customer why. For a draft use delete instead. Cancellation does not return funds.
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkHttpResponseW resp;
HCkJsonObjectW body;
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();
// This cancels a sent, unpaid invoice. It does not send a refund.
CkHttpW_SetUrlVar(http,L"id",L"INVOICE_ID");
body = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(body,L"subject",L"Inspection invoice canceled");
CkJsonObjectW_UpdateString(body,L"note",L"The inspection was canceled before work began.");
CkJsonObjectW_UpdateBool(body,L"send_to_recipient",TRUE);
success = CkHttpW_HttpJson(http,L"POST",L"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/cancel",body,L"application/json",resp);
if (success != TRUE) {
wprintf(L"No HTTP response: %s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(body);
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);
CkJsonObjectW_Dispose(body);
CkJsonObjectW_Dispose(errorInfo);
return;
}
wprintf(L"Cancellation accepted; HTTP %d\n",CkHttpResponseW_getStatusCode(resp));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(body);
CkJsonObjectW_Dispose(errorInfo);
}