Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Paynow.pl -- Make a Payment RequestMake a payment request POST with prepared message on Paynow payment request endpoint. For more information, see https://docs.paynow.pl/#section/Payments/Make-a-payment
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; const wchar_t *myApiAccessKey; const wchar_t *mySigCalcKey; HCkCrypt2W crypt; const wchar_t *messageBody; const wchar_t *signature; HCkHttpResponseW resp; HCkJsonObjectW jsonResp; const wchar_t *redirectUrl; const wchar_t *paymentId; const wchar_t *status; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // 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" // } // } json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateInt(json,L"amount",45671); CkJsonObjectW_UpdateString(json,L"externalId",L"234567898654"); CkJsonObjectW_UpdateString(json,L"description",L"Test transaction"); CkJsonObjectW_UpdateString(json,L"buyer.email",L"jan.kowalski@melements.pl"); myApiAccessKey = L"c12c386b-650b-43db-9430-d84fc05d9433"; mySigCalcKey = L"b758f20d-ba92-44fa-acca-f57e99787b9d"; // Calculate the Signature header. crypt = CkCrypt2W_Create(); CkCrypt2W_putMacAlgorithm(crypt,L"hmac"); CkCrypt2W_putEncodingMode(crypt,L"base64"); CkCrypt2W_SetMacKeyString(crypt,mySigCalcKey); CkCrypt2W_putHashAlgorithm(crypt,L"SHA-256"); messageBody = CkJsonObjectW_emit(json); signature = CkCrypt2W_macStringENC(crypt,messageBody); CkHttpW_SetRequestHeader(http,L"Idempotency-Key",CkCrypt2W_generateUuid(crypt)); CkHttpW_SetRequestHeader(http,L"Api-Key",myApiAccessKey); CkHttpW_SetRequestHeader(http,L"Signature",signature); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); CkHttpW_putAccept(http,L"application/json"); resp = CkHttpW_PostJson3(http,L"https://api.sandbox.paynow.pl/v1/payments",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkCrypt2W_Dispose(crypt); return; } wprintf(L"Response body:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); // Sample response: // { // "redirectUrl": "https://paywall.sandbox.paynow.pl/NOA0-YJ9-Y1P-29V?token=eyJraWQiOiJhMD ... L60wk", // "paymentId": "NOA0-YJ9-Y1P-29V", // "status": "NEW" // } jsonResp = CkJsonObjectW_Create(); CkJsonObjectW_Load(jsonResp,CkHttpResponseW_bodyStr(resp)); redirectUrl = CkJsonObjectW_stringOf(json,L"redirectUrl"); paymentId = CkJsonObjectW_stringOf(json,L"paymentId"); status = CkJsonObjectW_stringOf(json,L"status"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkCrypt2W_Dispose(crypt); CkJsonObjectW_Dispose(jsonResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.