Sample code for 30+ languages & platforms
PowerBuilder

Adyen Create Payment Session

See more Adyen Examples

Creates an Adyen payment session.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_PaymentSession

li_Success = 0

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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"
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

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

loo_Http.SetRequestHeader("X-API-Key","YourAPIkey")

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://checkout-test.adyen.com/v41/paymentSession",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Status Code = " + string(li_RespStatusCode)
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// 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

ls_PaymentSession = loo_JResp.StringOf("paymentSession")


destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp