Sample code for 30+ languages & platforms
Swift

Adyen Verify Payment Result

See more Adyen Examples

Once a payment has completed, this verifies the result from your server with a /payments/result request.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let http = CkoHttp()!

    // Use this online tool to generate the code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "payload": "2he28Ddhwj242he28Ddhwj..."
    // }
    let json = CkoJsonObject()!
    json.updateString(jsonPath: "payload", value: "2he28Ddhwj242he28Ddhwj...")

    http.setRequestHeader(name: "X-API-Key", value: "Your_API_key")

    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: "https://checkout-test.adyen.com/v41/payments/result", json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp.getBodySb(sb: sbResponseBody)

    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = false

    var respStatusCode: Int = resp.statusCode.intValue
    print("Status Code = \(respStatusCode)")
    print("Response Body:")
    print("\(jResp.emit()!)")

    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp.header!)")
        print("Failed.")
        return
    }

    // Sample JSON response:

    // {
    //   "pspReference": "851559480052382F",
    //   "resultCode": "Authorised",
    //   "merchantReference": "123",
    //   "paymentMethod": "ideal",
    //   "shopperLocale": "nl_NL"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var pspReference: String?
    var resultCode: String?
    var merchantReference: String?
    var paymentMethod: String?
    var shopperLocale: String?

    pspReference = jResp.string(of: "pspReference")
    resultCode = jResp.string(of: "resultCode")
    merchantReference = jResp.string(of: "merchantReference")
    paymentMethod = jResp.string(of: "paymentMethod")
    shopperLocale = jResp.string(of: "shopperLocale")

}