Crate bpay

Crate bpay 

Source
Expand description

This library provides access to Binance pay APIs. Refer: Binance Pay Documentation.

§Quickstart

Make sure the following env variables are set:

  • BINANCE_PAY_API_KEY
  • BINANCE_PAY_API_SECRET

In your Cargo.toml, add the following:

binance-pay-rs = "^0"
tokio = { version = "1.18.0", features = ["rt-multi-thread", "macros"] }

§Example

use bpay::api::order::create::{
   Currency, Env, Goods, GoodsCategory, GoodsType, Request as OrderRequest, TerminalType,
};
use bpay::client::Client;
use bpay::utils::create_nonce;
use tokio;

#[tokio::main]
async fn main() {

   let order = OrderRequest {
       env: Env {
           terminal_type: TerminalType::Web,
       },
       merchant_trade_no: create_nonce(10),
       order_amount: 10.0,
       currency: Currency::USDT,
       goods: Goods {
           goods_type: GoodsType::VirtualGoods,
           goods_category: GoodsCategory::Electronics,
           reference_goods_id: "sku1234".into(),
           goods_name: "Laptop".into(),
           goods_detail: None,
       },
   };

   let client = Client::from_env();
   let create_order_result = order.create(&client).await.unwrap();
   println!(
       "This url can be sent across to complete the payment procedure: {}",
       create_order_result.universal_url
   );
}

Modules§

api
Use Binance client::Client in conjunction with the Request Response structs.
c2b
Contains all the possible Serializable and Deserializable request and response structs inside respective modules.
client
Client particularly configured to send requests to the Binance Pay API.
errors
Custom error handling for the crate specific errrors.
utils
Utilities functions commonly used in the project.