Chilkat Online Tools

PureBasic / GP-API Collection / AUT_1.0 3DS Check Version

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

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

    ; The following JSON is sent in the request body.

    ; {
    ;   "account_name": "{{acc_name}}",
    ;   "reference": "abcdendfjknbkjfdns",
    ;   "channel": "CNP",
    ;   "amount": "5",
    ;   "currency": "EUR",
    ;   "country": "US",
    ;   "source": "BROWSER",
    ;   "payment_method": {
    ;     "id": "{{pmt_id}}"
    ;   },
    ;   "notifications": {
    ;     "challenge_return_url": "https://ensi808o85za.x.pipedream.net/",
    ;     "three_ds_method_return_url": "https://en261wy69mex7.x.pipedream.net"
    ;   }
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"account_name","{{acc_name}}")
    CkJsonObject::ckUpdateString(json,"reference","abcdendfjknbkjfdns")
    CkJsonObject::ckUpdateString(json,"channel","CNP")
    CkJsonObject::ckUpdateString(json,"amount","5")
    CkJsonObject::ckUpdateString(json,"currency","EUR")
    CkJsonObject::ckUpdateString(json,"country","US")
    CkJsonObject::ckUpdateString(json,"source","BROWSER")
    CkJsonObject::ckUpdateString(json,"payment_method.id","{{pmt_id}}")
    CkJsonObject::ckUpdateString(json,"notifications.challenge_return_url","https://ensi808o85za.x.pipedream.net/")
    CkJsonObject::ckUpdateString(json,"notifications.three_ds_method_return_url","https://en261wy69mex7.x.pipedream.net")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")
    CkHttp::ckSetRequestHeader(http,"X-GP-Version","{{version}}")

    resp.i = CkHttp::ckPostJson3(http,"https://{{url}}/ucp/authentications","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "X-GP-Version: {{version}}"
	-d '{
    "account_name": "{{acc_name}}",
    "reference": "abcdendfjknbkjfdns",
    "channel": "CNP",
    "amount":"5",
    "currency": "EUR",
    "country": "US",
    "source": "BROWSER",
    "payment_method": {
        "id":"{{pmt_id}}"
    },
    "notifications": {
        "challenge_return_url": "https://ensi808o85za.x.pipedream.net/",
        "three_ds_method_return_url": "https://en261wy69mex7.x.pipedream.net"
    }
}'
https://{{url}}/ucp/authentications

Postman Collection Item JSON

{
  "name": "AUT_1.0 3DS Check Version",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "//Json Parse",
          "//Json Parse",
          "pm.environment.unset(\"aut_id\");",
          "",
          "",
          "var jsonData = JSON.parse(responseBody);",
          "",
          "var pareq = jsonData.three_ds.challenge_value; ",
          "var method_data = jsonData.three_ds.method_data.encoded_method_data;",
          "var method_url = jsonData.three_ds.method_url; ",
          "",
          "postman.setEnvironmentVariable(\"aut_id\", jsonData.id);",
          "postman.setEnvironmentVariable(\"reference\", jsonData.reference);",
          "postman.setEnvironmentVariable(\"act_id\", jsonData.action.id);",
          "",
          "",
          "console.log(pareq);",
          "pm.test(\"set  html\",function(){",
          "    var template='<!DOCTYPE html> <html> <head> <meta charset=\"ISO-8859-1\"> <title>Sample 3DSecure Page</title> </head> <body><form action='+method_url+' method=\"POST\">  <input type=\"hidden\" name=\"threeDSMethodData\" value= '+method_data+' /> <input type=\"submit\" value=\"Submit\"> </form> </body> </html>'     // save your html in the template and then     ",
          "    pm.visualizer.set(template);     // set that template to pm.visualizer",
          "})",
          "//https://test.portal.gpwebpay.com/pay-sim-gpi/sim/acs",
          "//https://apis-dev.globalpay.com/testing/acs",
          "",
          "",
          "",
          "",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "oauth2",
      "oauth2": [
        {
          "key": "accessToken",
          "value": "{{token}}",
          "type": "string"
        },
        {
          "key": "addTokenTo",
          "value": "header",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "X-GP-Version",
        "value": "{{version}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"account_name\": \"{{acc_name}}\",\n    \"reference\": \"abcdendfjknbkjfdns\",\n    \"channel\": \"CNP\",\n    \"amount\":\"5\",\n    \"currency\": \"EUR\",\n    \"country\": \"US\",\n    \"source\": \"BROWSER\",\n    \"payment_method\": {\n        \"id\":\"{{pmt_id}}\"\n    },\n    \"notifications\": {\n        \"challenge_return_url\": \"https://ensi808o85za.x.pipedream.net/\",\n        \"three_ds_method_return_url\": \"https://en261wy69mex7.x.pipedream.net\"\n    }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://{{url}}/ucp/authentications",
      "protocol": "https",
      "host": [
        "{{url}}"
      ],
      "path": [
        "ucp",
        "authentications"
      ]
    },
    "description": "This request must be sent in order to verify what version of 3DS the payer is set up with i.e 3DS1 or 3DS2. \r\n\r\nFor 3DS1, you can see in the response that the redirect url is included. This is the address of the Issuer's Access Control Server.\r\n\r\nFor 3DS2, you can see in the response that the method URL is included. The URL to facilitate the ACS gathering device data. If the ACS does not support this functionality, this field will not be returned.\r\n\r\nFor more info on Checking Version of 3DS, visit: https://developer.globalpay.com/api/authentications#/Check%20Availability/check3DSAvailability"
  },
  "response": [
  ]
}