Rust Requires Chilkat v11.0.0+
Rust
PayPal: Reconcile a transaction ID in a reporting window
See more PayPal Examples
Supply the reporting transaction ID and a window containing the activity. Return all matches: transaction IDs are not necessarily unique in the report. Include non-balance-affecting records when reconciling an event.
Chilkat Rust Downloads
// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
let http = chilkat::Http::new();
http.set_auth_token("SANDBOX_ACCESS_TOKEN");
let resp = chilkat::HttpResponse::new();
// Use the UTC window containing the transaction (at most 31 days per request).
let dt = chilkat::DateTime::new();
let _ = dt.set_from_current_system_time();
let query = chilkat::JsonObject::new();
let _ = query.update_string("end_date", &dt.get_as_timestamp(false).unwrap_or_default());
let _ = dt.add_days(-1);
let _ = query.update_string("start_date", &dt.get_as_timestamp(false).unwrap_or_default());
let _ = query.update_string("fields", "transaction_info");
let _ = query.update_int("page_size", 100);
let _ = query.update_string("transaction_id", "REPORT_TRANSACTION_ID");
let _ = query.update_string("balance_affecting_records_only", "N");
let mut page = 1;
let mut last_page = 1;
while page <= last_page {
let _ = query.update_int("page", page);
if http.http_params("GET", "https://api-m.sandbox.paypal.com/v1/reporting/transactions", &query, &resp).is_err() {
println!("No HTTP response: {}", http.last_error_text());
return;
}
if (resp.status_code() < 200) || (resp.status_code() >= 300) {
let error_info = chilkat::JsonObject::new();
let _ = error_info.load(&resp.body_str());
println!("HTTP {} {} {}", resp.status_code(), error_info.string_of("name").unwrap_or_default(), error_info.string_of("details[0].issue").unwrap_or_default());
println!("PayPal debug ID: {}", error_info.string_of("debug_id").unwrap_or_default());
return;
}
let result = chilkat::JsonObject::new();
if result.load(&resp.body_str()).is_err() {
println!("Expected a JSON response; HTTP {}", resp.status_code());
return;
}
let mut i = 0;
let count = result.size_of_array("transaction_details");
while i < count {
result.set_i(i);
println!("{} {} {}", result.string_of("transaction_details[i].transaction_info.transaction_id").unwrap_or_default(), result.string_of("transaction_details[i].transaction_info.transaction_event_code").unwrap_or_default(), result.string_of("transaction_details[i].transaction_info.transaction_status").unwrap_or_default());
println!(" {} {}", result.string_of("transaction_details[i].transaction_info.transaction_amount.value").unwrap_or_default(), result.string_of("transaction_details[i].transaction_info.transaction_amount.currency_code").unwrap_or_default());
i = i + 1;
}
last_page = result.int_of("total_pages");
page = page + 1;
}