Rust
Rust
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 Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// 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"
// }
// }
let json = chilkat::JsonObject::new();
let _ = json.update_int("amount", 45671);
let _ = json.update_string("externalId", "234567898654");
let _ = json.update_string("description", "Test transaction");
let _ = json.update_string("buyer.email", "jan.kowalski@melements.pl");
let my_api_access_key = "c12c386b-650b-43db-9430-d84fc05d9433".to_string();
let my_sig_calc_key = "b758f20d-ba92-44fa-acca-f57e99787b9d".to_string();
// Calculate the Signature header.
let crypt = chilkat::Crypt2::new();
crypt.set_mac_algorithm("hmac");
crypt.set_encoding_mode("base64");
let _ = crypt.set_mac_key_string(&my_sig_calc_key);
crypt.set_hash_algorithm("SHA-256");
let message_body = json.emit().unwrap_or_default();
let signature = crypt.mac_string_enc(&message_body).unwrap_or_default();
http.set_request_header("Idempotency-Key", &crypt.generate_uuid().unwrap_or_default());
http.set_request_header("Api-Key", &my_api_access_key);
http.set_request_header("Signature", &signature);
http.set_request_header("Content-Type", "application/json");
http.set_accept("application/json");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.sandbox.paynow.pl/v1/payments", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("Response body:");
println!("{}", resp.body_str());
// Sample response:
// {
// "redirectUrl": "https://paywall.sandbox.paynow.pl/NOA0-YJ9-Y1P-29V?token=eyJraWQiOiJhMD ... L60wk",
// "paymentId": "NOA0-YJ9-Y1P-29V",
// "status": "NEW"
// }
let json_resp = chilkat::JsonObject::new();
let _ = json_resp.load(&resp.body_str());
let redirect_url = json.string_of("redirectUrl").unwrap_or_default();
let payment_id = json.string_of("paymentId").unwrap_or_default();
let status = json.string_of("status").unwrap_or_default();