Unicode C++ Stripe: Create a Refund

Back to Index

Creates a new refund to refund a charge that has previously been created but not yet refunded.

Documentation: https://stripe.com/docs/api/curl#create_refund

CURL Command

curl https://api.stripe.com/v1/refunds \
   -u STRIPE_SECRET_KEY: \
   -d charge=ch_1BnETKGswQrCoh0XE7kJI2wj
   -X POST

Unicode C++ Example

#include <CkRestW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://api.stripe.com/v1/refunds
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.SetAuthBasic(L"STRIPE_SECRET_KEY",L"");

    rest.AddQueryParam(L"charge",L"ch_1BnETKGswQrCoh0XE7kJI2wj");

    const wchar_t *strResponseBody = rest.fullRequestFormUrlEncoded(L"POST",L"/v1/refunds");
    if (rest.get_LastMethodSuccess() != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.Load(strResponseBody);

    const wchar_t *id = 0;
    const wchar_t *object = 0;
    int amount;
    bool balance_transaction;
    const wchar_t *charge = 0;
    int created;
    const wchar_t *currency = 0;
    bool reason;
    bool receipt_number;
    const wchar_t *status = 0;

    id = jsonResponse.stringOf(L"id");
    object = jsonResponse.stringOf(L"object");
    amount = jsonResponse.IntOf(L"amount");
    balance_transaction = jsonResponse.IsNullOf(L"balance_transaction");
    charge = jsonResponse.stringOf(L"charge");
    created = jsonResponse.IntOf(L"created");
    currency = jsonResponse.stringOf(L"currency");
    reason = jsonResponse.IsNullOf(L"reason");
    receipt_number = jsonResponse.IsNullOf(L"receipt_number");
    status = jsonResponse.stringOf(L"status");
    }

Sample JSON Response Body

{
  "id": "re_1BnETKGswQrCoh0XT2qLx7S0",
  "object": "refund",
  "amount": 100,
  "balance_transaction": null,
  "charge": "ch_1BnETKGswQrCoh0XE7kJI2wj",
  "created": 1516662782,
  "currency": "usd",
  "metadata": {},
  "reason": null,
  "receipt_number": null,
  "status": "succeeded"
}