C# UWP/WinRT 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# UWP/WinRT Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://api.stripe.com/v1/refunds
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = await rest.ConnectAsync("api.stripe.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

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

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

string strResponseBody = await rest.FullRequestFormUrlEncodedAsync("POST","/v1/refunds");
if (rest.LastMethodSuccess != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.Load(strResponseBody);

string id;
string object;
int amount;
bool balance_transaction;
string charge;
int created;
string currency;
bool reason;
bool receipt_number;
string status;

id = jsonResponse.StringOf("id");
object = jsonResponse.StringOf("object");
amount = jsonResponse.IntOf("amount");
balance_transaction = jsonResponse.IsNullOf("balance_transaction");
charge = jsonResponse.StringOf("charge");
created = jsonResponse.IntOf("created");
currency = jsonResponse.StringOf("currency");
reason = jsonResponse.IsNullOf("reason");
receipt_number = jsonResponse.IsNullOf("receipt_number");
status = jsonResponse.StringOf("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"
}