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

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const char *strResponseBody;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *object;
    int amount;
    BOOL balance_transaction;
    const char *charge;
    int created;
    const char *currency;
    BOOL reason;
    BOOL receipt_number;
    const char *status;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/refunds
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    CkRest_AddQueryParam(rest,"charge","ch_1BnETKGswQrCoh0XE7kJI2wj");

    strResponseBody = CkRest_fullRequestFormUrlEncoded(rest,"POST","/v1/refunds");
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_Load(jsonResponse,strResponseBody);

    id = CkJsonObject_stringOf(jsonResponse,"id");
    object = CkJsonObject_stringOf(jsonResponse,"object");
    amount = CkJsonObject_IntOf(jsonResponse,"amount");
    balance_transaction = CkJsonObject_IsNullOf(jsonResponse,"balance_transaction");
    charge = CkJsonObject_stringOf(jsonResponse,"charge");
    created = CkJsonObject_IntOf(jsonResponse,"created");
    currency = CkJsonObject_stringOf(jsonResponse,"currency");
    reason = CkJsonObject_IsNullOf(jsonResponse,"reason");
    receipt_number = CkJsonObject_IsNullOf(jsonResponse,"receipt_number");
    status = CkJsonObject_stringOf(jsonResponse,"status");


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(jsonResponse);

    }

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"
}