easydonate_api/v3/
payment.rs1use std::collections::HashMap;
2use isahc::{send_async, AsyncReadResponseExt, Request};
3use serde::{Deserialize, Serialize};
4use crate::result::{EasyResponse, EasyResult};
5
6#[derive(Serialize, Debug, Clone)]
7pub struct PaymentBody {
8 customer: String,
9 server_id: i32,
10 products: HashMap<String, i32>,
11 email: String,
12 coupon: Option<String>,
13 success_url: Option<String>
14}
15
16#[derive(Serialize, Deserialize)]
17pub struct PaymentResponse {
18 pub url: String,
19 }
21
22pub async fn create_payment(
25 shop_key: String,
26 payload: PaymentBody
27) -> EasyResult<String> {
28 let request = Request::get("https://easydonate.ru/api/v3/shop/payment/create")
29 .header("Shop-Key", shop_key)
30 .header("Content-Type", "application/json")
31 .body(serde_json::to_string(&payload)?)?;
32
33 let mut response = send_async(request)
34 .await?;
35
36 let body = response.text()
37 .await?;
38
39 let des = serde_json::from_str::<EasyResponse<PaymentResponse>>(&body)?;
40
41 Ok(des.result()?.url)
42}