Sample code for 30+ languages & platforms
PowerBuilder

Paynow.pl -- Make a Payment Request

See more Paynow.pl Examples

Make a payment request POST with prepared message on Paynow payment request endpoint.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
string ls_MyApiAccessKey
string ls_MySigCalcKey
oleobject loo_Crypt
string ls_MessageBody
string ls_Signature
oleobject loo_Resp
oleobject loo_JsonResp
string ls_RedirectUrl
string ls_PaymentId
string ls_Status

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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

// Implements the following CURL command:

// curl --request POST 'https://api.sandbox.paynow.pl/v1/payments' \
// -H 'Content-Type: application/json' \
// -H 'Api-Key: c12c386b-650b-43db-9430-d84fc05d9433' \
// -H 'Signature: aYPCytCoc+/wFgqHZJjgBCi20omXTn0yzm9LysJgnFo=' \
// -H 'Idempotency-Key: 59c6dd26-f905-487b-96c9-fd1d2bd76885' \
// --data-raw '{
//     "amount": 45671,
//     "externalId": "234567898654",
//     "description": "Test transaction",
//     "buyer": {
//         "email": "jan.kowalski@melements.pl"
//     }
// }'

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

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

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

// {
//   "amount": 45671,
//   "externalId": "234567898654",
//   "description": "Test transaction",
//   "buyer": {
//     "email": "jan.kowalski@melements.pl"
//   }
// }

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

loo_Json.UpdateInt("amount",45671)
loo_Json.UpdateString("externalId","234567898654")
loo_Json.UpdateString("description","Test transaction")
loo_Json.UpdateString("buyer.email","jan.kowalski@melements.pl")

ls_MyApiAccessKey = "c12c386b-650b-43db-9430-d84fc05d9433"
ls_MySigCalcKey = "b758f20d-ba92-44fa-acca-f57e99787b9d"

// Calculate the Signature header.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")

loo_Crypt.MacAlgorithm = "hmac"
loo_Crypt.EncodingMode = "base64"
loo_Crypt.SetMacKeyString(ls_MySigCalcKey)
loo_Crypt.HashAlgorithm = "SHA-256"
ls_MessageBody = loo_Json.Emit()
ls_Signature = loo_Crypt.MacStringENC(ls_MessageBody)

loo_Http.SetRequestHeader("Idempotency-Key",loo_Crypt.GenerateUuid())
loo_Http.SetRequestHeader("Api-Key",ls_MyApiAccessKey)
loo_Http.SetRequestHeader("Signature",ls_Signature)
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.Accept = "application/json"

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

li_Success = loo_Http.HttpJson("POST","https://api.sandbox.paynow.pl/v1/payments",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Crypt
    destroy loo_Resp
    return
end if

Write-Debug "Response body:"
Write-Debug loo_Resp.BodyStr

// Sample response:
// {
//   "redirectUrl": "https://paywall.sandbox.paynow.pl/NOA0-YJ9-Y1P-29V?token=eyJraWQiOiJhMD ... L60wk",
//   "paymentId": "NOA0-YJ9-Y1P-29V",
//   "status": "NEW"
// }

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

loo_JsonResp.Load(loo_Resp.BodyStr)
ls_RedirectUrl = loo_Json.StringOf("redirectUrl")
ls_PaymentId = loo_Json.StringOf("paymentId")
ls_Status = loo_Json.StringOf("status")


destroy loo_Http
destroy loo_Json
destroy loo_Crypt
destroy loo_Resp
destroy loo_JsonResp