mtnmomo 0.1.9

MTN Momo Payment API for Rust, with support for both the Sandbox and Production environments. All products are supported: Collections, Disbursements and Remittances.
Documentation
#[doc(hidden)]
use serde::{Deserialize, Serialize};

#[doc(hidden)]
use reqwest::Body;

use crate::{enums::currency::Currency, structs::party::Party};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Transfer {
    pub amount: String,
    pub currency: Currency,
    #[serde(rename = "externalId")]
    pub external_id: String,
    pub payee: Party,
    #[serde(rename = "payerMessage")]
    pub payer_message: String,
    #[serde(rename = "payeeNote")]
    pub payee_note: String,
}

impl Transfer {
    pub fn new(
        amount: String,
        currency: Currency,
        payee: Party,
        payer_message: String,
        payee_note: String,
    ) -> Self {
        let external_id = uuid::Uuid::new_v4().to_string();
        Transfer {
            amount,
            currency,
            external_id,
            payee,
            payer_message,
            payee_note,
        }
    }
}

impl From<Transfer> for Body {
    fn from(transfer: Transfer) -> Self {
        Body::from(serde_json::to_string(&transfer).unwrap())
    }
}