Sample code for 30+ languages & platforms
Unicode C Requires Chilkat v11.7.0+

Stripe: Issue a full or partial refund

See more Stripe Examples

Issue a partial refund against a selected payment, or refund the remaining amount by omitting the amount field.

Stripe documentation and cURL example

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpCurlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    const wchar_t *apiKey;
    const wchar_t *operationId;
    HCkHttpCurlW curl;
    HCkStringBuilderW cmd;
    HCkJsonObjectW json;
    int replaced;
    const wchar_t *paymentIntent;

    success = FALSE;

    //  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
    //  Supply a restricted sandbox key from merchant-controlled configuration.
    apiKey = L"YOUR_STRIPE_TEST_KEY";
    //  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
    operationId = L"YOUR_SAVED_OPERATION_UUID";

    curl = CkHttpCurlW_Create();
    cmd = CkStringBuilderW_Create();
    json = CkJsonObjectW_Create();

    paymentIntent = L"pi_FROM_SELECTED_PAYMENT";

    //  The operator selected a partial refund of 500 minor units. Omit the amount field to refund the remaining balance. For a charge ID use charge= instead of payment_intent=.

    //  curl -X POST "https://api.stripe.com/v1/refunds" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive" \
    //    -H "Idempotency-Key: {operationId}-refund" \
    //    -d "payment_intent={paymentIntent}" \
    //    -d "amount=500"
    CkStringBuilderW_SetString(cmd,L"curl -X POST \"https://api.stripe.com/v1/refunds\"");
    CkStringBuilderW_Append(cmd,L" -u \"@KEY@:\"");
    CkStringBuilderW_Append(cmd,L" -H \"Stripe-Version: 2026-10-28.endive\"");
    CkStringBuilderW_Append(cmd,L" -H \"Idempotency-Key: @OP@-refund\"");
    CkStringBuilderW_Append(cmd,L" -d \"payment_intent=@PAYMENT@\"");
    CkStringBuilderW_Append(cmd,L" -d \"amount=500\"");
    replaced = CkStringBuilderW_Replace(cmd,L"@PAYMENT@",paymentIntent);
    replaced = CkStringBuilderW_Replace(cmd,L"@OP@",operationId);
    replaced = CkStringBuilderW_Replace(cmd,L"@KEY@",apiKey);
    success = CkHttpCurlW_DoYourThing(curl,CkStringBuilderW_getAsString(cmd));
    if (success != TRUE) {
        wprintf(L"No HTTP response. Chilkat failure code: %d\n",CkHttpCurlW_getFailReason(curl));
        CkHttpCurlW_Dispose(curl);
        CkStringBuilderW_Dispose(cmd);
        CkJsonObjectW_Dispose(json);
        return;
    }

    success = CkHttpCurlW_GetResponseJson(curl,json);
    if ((CkHttpCurlW_getStatusCode(curl) != 200) || (success != TRUE)) {
        wprintf(L"Stripe HTTP %d  Request-Id: %s\n",CkHttpCurlW_getStatusCode(curl),CkHttpCurlW_getResponseHeaderField(curl,L"Request-Id"));
        if (success == TRUE) {
            wprintf(L"%s\n",CkJsonObjectW_stringOf(json,L"error.message"));
        }

        CkHttpCurlW_Dispose(curl);
        CkStringBuilderW_Dispose(cmd);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"id = %s\n",CkJsonObjectW_stringOf(json,L"id"));
    wprintf(L"status = %s\n",CkJsonObjectW_stringOf(json,L"status"));
    wprintf(L"amount = %s\n",CkJsonObjectW_stringOf(json,L"amount"));
    wprintf(L"currency = %s\n",CkJsonObjectW_stringOf(json,L"currency"));

    //  Save this refund ID with the refund request for status checks.


    CkHttpCurlW_Dispose(curl);
    CkStringBuilderW_Dispose(cmd);
    CkJsonObjectW_Dispose(json);

    }