easydonate_api/v3/
payment.rs

1use 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  pub customer: String,
9  pub server_id: i32,
10  pub products: HashMap<String, i32>,
11  pub email: String,
12  pub coupon: Option<String>,
13  pub success_url: Option<String>
14}
15
16#[derive(Serialize, Deserialize)]
17pub struct PaymentResponse {
18  pub url: String,
19  // payment: {...}
20}
21
22/// **Неполная** Имплементация
23/// https://docs.easydonate.ru/shop/payment-create
24pub 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}