Swift Stripe: Retrieve a Refund

Back to Index

Retrieves the details of an existing refund.

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

CURL Command

curl https://api.stripe.com/v1/refunds/re_1BnETKGswQrCoh0XT2qLx7S0 \
   -u STRIPE_SECRET_KEY:

Swift Example


func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //  URL: https://api.stripe.com/v1/refunds/re_1BnETKGswQrCoh0XT2qLx7S0
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.Connect("api.stripe.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.integerValue)")
        print("\(rest.LastErrorText)")
        return
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY", password: "")

    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("GET", uriPath: "/v1/refunds/re_1BnETKGswQrCoh0XT2qLx7S0", sb: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.LoadSb(sbResponseBody)

    var id: String?
    var object: String?
    var amount: Int
    var balance_transaction: Bool
    var charge: String?
    var created: Int
    var currency: String?
    var reason: Bool
    var receipt_number: Bool
    var status: String?

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