bpay/lib.rs
1/*! This library provides access to Binance pay APIs.
2Refer: [Binance Pay Documentation](https://developers.binance.com/docs/binance-pay/introduction).
3
4# Quickstart
5
6Make sure the following env variables are set:
7 - `BINANCE_PAY_API_KEY`
8 - `BINANCE_PAY_API_SECRET`
9
10In your `Cargo.toml`, add the following:
11
12```toml
13binance-pay-rs = "^0"
14tokio = { version = "1.18.0", features = ["rt-multi-thread", "macros"] }
15```
16
17 ## Example
18 ```
19use bpay::api::order::create::{
20 Currency, Env, Goods, GoodsCategory, GoodsType, Request as OrderRequest, TerminalType,
21};
22use bpay::client::Client;
23use bpay::utils::create_nonce;
24# #[cfg(test)]
25# use mockito;
26# use mockito::mock;
27use tokio;
28
29#[tokio::main]
30async fn main() {
31
32 let order = OrderRequest {
33 env: Env {
34 terminal_type: TerminalType::Web,
35 },
36 merchant_trade_no: create_nonce(10),
37 order_amount: 10.0,
38 currency: Currency::USDT,
39 goods: Goods {
40 goods_type: GoodsType::VirtualGoods,
41 goods_category: GoodsCategory::Electronics,
42 reference_goods_id: "sku1234".into(),
43 goods_name: "Laptop".into(),
44 goods_detail: None,
45 },
46 };
47
48 let client = Client::from_env();
49 # let url = &mockito::server_url();
50 # let response = r#"
51 # {
52 # "status": "SUCCESS",
53 # "code": "000000",
54 # "data": {
55 # "prepayId": "29383937493038367292",
56 # "terminalType": "WEB",
57 # "expireTime": 121123232223,
58 # "qrcodeLink": "https://qrservice.dev.com/en/qr/dplkb005181944f84b84aba2430e1177012b.jpg",
59 # "qrContent": "https://qrservice.dev.com/en/qr/dplk12121112b",
60 # "checkoutUrl": "https://pay.binance.com/checkout/dplk12121112b",
61 # "deeplink": "bnc://app.binance.com/payment/secpay/xxxxxx",
62 # "universalUrl": "https://app.binance.com/payment/secpay?_dp=xxx=&linkToken=xxx"
63 # },
64 # "errorMessage": ""
65 # }"#;
66 # let mut client = Client::new(Some("".into()), Some("".into()), url.to_string());
67 # let _m = mock("POST", "/binancepay/openapi/v2/order")
68 # .with_status(200)
69 # .with_header("content-type", "application/json")
70 # .with_body(response)
71 # .create();
72 let create_order_result = order.create(&client).await.unwrap();
73 println!(
74 "This url can be sent across to complete the payment procedure: {}",
75 create_order_result.universal_url
76 );
77}
78 ```
79*/
80pub mod api;
81pub mod c2b;
82pub mod client;
83pub mod errors;
84pub mod utils;