Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Adyen Create Payment Session

See more Adyen Examples

Creates an Adyen payment session.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cPaymentSession

nSuccess := 0

oHttp := CreateObject("Chilkat.Http")

//  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, and is constructed by the code that follows.

//  {
//    "merchantAccount": "YourMerchantAccount",
//    "sdkVersion": "1.9.7",
//    "channel": "Web",
//    "amount": {
//      "currency": "EUR",
//      "value": 17408
//    },
//    "reference": "Your order number",
//    "countryCode": "NL",
//    "shopperLocale": "nl_NL",
//    "origin": "https://www.yourshop.com",
//    "returnUrl": "https://www.yourshop.com/checkout/completed"
//  }
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("merchantAccount", "YourMerchantAccount")
oJson:UpdateString("sdkVersion", "1.9.7")
oJson:UpdateString("channel", "Web")
oJson:UpdateString("amount.currency", "EUR")
oJson:UpdateInt("amount.value", 17408)
oJson:UpdateString("reference", "Your order number")
oJson:UpdateString("countryCode", "NL")
oJson:UpdateString("shopperLocale", "nl_NL")
oJson:UpdateString("origin", "https://www.yourshop.com")
oJson:UpdateString("returnUrl", "https://www.yourshop.com/checkout/completed")

oHttp:SetRequestHeader("X-API-Key", "YourAPIkey")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://checkout-test.adyen.com/v41/paymentSession", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

nRespStatusCode := oResp:StatusCode
? "Status Code = " + Str(nRespStatusCode)
? "Response Body:"
? oJResp:Emit()

IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

//  Sample JSON response:

//  {
//    "paymentSession": "eyJjaGVja291 ... iMS45LjcifQ=="
//  }

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

cPaymentSession := oJResp:StringOf("paymentSession")

oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()