Rust Requires Chilkat v11.0.0+
Rust
Adyen Create Payment Session
See more Adyen Examples
Creates an Adyen payment session.Chilkat Rust Downloads
let http = chilkat::Http::new();
// 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"
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("merchantAccount", "YourMerchantAccount");
let _ = json.update_string("sdkVersion", "1.9.7");
let _ = json.update_string("channel", "Web");
let _ = json.update_string("amount.currency", "EUR");
let _ = json.update_int("amount.value", 17408);
let _ = json.update_string("reference", "Your order number");
let _ = json.update_string("countryCode", "NL");
let _ = json.update_string("shopperLocale", "nl_NL");
let _ = json.update_string("origin", "https://www.yourshop.com");
let _ = json.update_string("returnUrl", "https://www.yourshop.com/checkout/completed");
http.set_request_header("X-API-Key", "YourAPIkey");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://checkout-test.adyen.com/v41/paymentSession", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
let resp_status_code = resp.status_code();
println!("Status Code = {}", resp_status_code);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
// 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
let payment_session = j_resp.string_of("paymentSession").unwrap_or_default();