use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub struct WechatPay {
pub app_id: String,
pub mch_id: String,
pub private_key: String,
pub serial_no: String,
pub v3_key: String,
pub notify_url: String,
pub domain: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct Amount {
pub total: u64,
#[builder(default = "\"CNY\".to_string()", setter(into))]
pub currency: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct Payer {
pub openid: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct StoreInfo {
id: String,
name: Option<String>,
area_code: Option<String>,
address: String,
}
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct JsapiResult {
pub app_id: String,
pub time_stamp: String,
pub nonce_str: String,
pub package: String,
pub sign_type: String,
pub pay_sign: String,
pub prepay_id: String,
}
impl JsapiResult {
pub fn get_sign_str(&self) -> String {
format!(
"{}\n{}\n{}\n{}\n",
self.app_id, self.time_stamp, self.nonce_str, self.package
)
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct AppResult {
pub appid: String,
pub partner_id: String,
pub prepay_id: String,
pub time_stamp: String,
pub nonce_str: String,
pub package_value: String,
pub sign: String,
}
impl AppResult {
pub fn get_sign_str(&self) -> String {
format!(
"{}\n{}\n{}\n{}\n",
self.appid, self.time_stamp, self.nonce_str, self.prepay_id
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RPayResponse<T> {
data: T,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub enum PayType {
Micro,
Jsapi,
Native,
App,
H5,
}
impl Display for PayType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
PayType::Micro => write!(f, "MICRO"),
PayType::Jsapi => write!(f, "JSAPI"),
PayType::Native => write!(f, "NATIVE"),
PayType::App => write!(f, "APP"),
PayType::H5 => write!(f, "H5"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct Detail {
pub cost_price: u64,
invoice_id: Option<String>,
goods_detail: Vec<GoodsDetailItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct GoodsDetailItem {
pub merchant_goods_id: Option<String>,
pub wechatpay_goods_id: Option<String>,
pub goods_name: String,
pub quantity: u64,
pub unit_price: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct SettleInfo {
pub profit_sharing: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct SceneInfo {
pub payer_client_ip: String,
pub device_id: String,
pub store_info: StoreInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct WechatPayDecodeData {
pub mchid: String,
pub appid: String,
pub out_trade_no: String,
pub transaction_id: String,
pub trade_type: String,
pub trade_state: String,
pub trade_state_desc: String,
pub bank_type: String,
pub attach: String,
pub success_time: String,
pub payer: PayerInfo,
pub amount: AmountInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PayerInfo {
pub openid: String,
}
impl From<&str> for PayerInfo {
fn from(value: &str) -> Self {
Self {
openid: value.to_string(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AmountInfo {
pub total: i32,
}
impl From<i32> for AmountInfo {
fn from(value: i32) -> Self {
Self { total: value }
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ParseEncrypt {
pub ciphertext: String,
pub nonce: String,
pub associated_data: String,
pub algorithm: String,
pub original_type: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SignData {
pub app_id: String,
pub sign_type: String,
pub package: String,
pub nonce_str: String,
pub timestamp: String,
pub pay_sign: String,
}