fixes and utility for money type

This commit is contained in:
Edgar 2022-04-28 10:06:23 +02:00
parent b9153e7ace
commit 5dccdcbb28
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
7 changed files with 37 additions and 19 deletions

View file

@ -33,7 +33,7 @@ async fn main() -> Result<()> {
let invoice = CreateDraftInvoice::new(payload);
let res = client.execute(invoice).await?;
let res = client.execute(&invoice).await?;
println!("{:#?}", res);

View file

@ -348,7 +348,7 @@ mod tests {
use super::*;
use crate::data::common::*;
use crate::data::invoice::*;
use crate::{Client, HeaderParams};
use crate::Client;
async fn create_client() -> Client {
dotenv::dotenv().ok();
@ -361,7 +361,7 @@ mod tests {
}
#[tokio::test]
async fn test_invoice_creates() -> anyhow::Result<()> {
async fn test_invoice_create_cancel() -> anyhow::Result<()> {
let client = create_client().await;
let payload = InvoicePayloadBuilder::default()
@ -383,7 +383,7 @@ mod tests {
let invoice = CreateDraftInvoice::new(payload);
client.execute(invoice).await?;
let res = client.execute(&invoice).await?;
Ok(())
}
}

View file

@ -187,13 +187,9 @@ impl Endpoint for AuthorizeOrder {
#[cfg(test)]
mod tests {
use crate::data::common::Currency;
use crate::HeaderParams;
use crate::{
api::orders::{CreateOrder, ShowOrderDetails},
data::orders::*,
tests::create_client,
};
use crate::{api::orders::CaptureOrder, data::common::Currency};
use crate::{api::orders::*, data::orders::*, tests::create_client};
#[tokio::test]
async fn test_order() -> anyhow::Result<()> {
@ -217,7 +213,7 @@ mod tests {
let order_created = client
.execute_ext(
create_order,
&create_order,
HeaderParams {
request_id: Some(ref_id.clone()),
..Default::default()
@ -233,7 +229,7 @@ mod tests {
let show_order_result = client
.execute_ext(
show_order,
&show_order,
HeaderParams {
request_id: Some(ref_id.clone()),
..Default::default()
@ -244,6 +240,10 @@ mod tests {
assert_eq!(order_created.id, show_order_result.id);
assert_eq!(order_created.status, show_order_result.status);
let capture_order = CaptureOrder::new(&show_order_result.id);
let _res = client.execute(&capture_order).await?;
Ok(())
}
}

View file

@ -189,7 +189,7 @@ impl Client {
}
/// Executes the given endpoint with the given headers.
pub async fn execute_ext<E>(&self, endpoint: E, headers: HeaderParams) -> Result<E::Response, ResponseError>
pub async fn execute_ext<E>(&self, endpoint: &E, headers: HeaderParams) -> Result<E::Response, ResponseError>
where
E: Endpoint,
{
@ -226,7 +226,7 @@ impl Client {
/// Executes the given endpoints with the default headers.
///
/// You must remember to call `get_access_token` first or this may fail due to not being authed.
pub async fn execute<E>(&self, endpoint: E) -> Result<E::Response, ResponseError>
pub async fn execute<E>(&self, endpoint: &E) -> Result<E::Response, ResponseError>
where
E: Endpoint,
{

View file

@ -74,6 +74,27 @@ pub struct Money {
pub value: String,
}
macro_rules! impl_money {
($name:ident, $type:expr) => {
#[doc=concat!("Creates a instance of Money with the currency ", stringify!($type))]
pub fn $name(value: &str) -> Self {
Self {
currency_code: $type,
value: value.to_string(),
}
}
};
}
impl Money {
impl_money!(eur, Currency::EUR);
impl_money!(usd, Currency::USD);
impl_money!(brl, Currency::BRL);
impl_money!(cny, Currency::CNY);
impl_money!(czk, Currency::CZK);
impl_money!(jpy, Currency::JPY);
}
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Copy)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[allow(missing_docs)]

View file

@ -635,6 +635,7 @@ pub struct InvoiceList {
/// Cancel invoice reason
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)]
#[builder(setter(strip_option, into), default)]
pub struct CancelReason {
/// The subject of the email that is sent as a notification to the recipient.
pub subject: Option<String>,

View file

@ -7,10 +7,6 @@
//!
//! A rust library that wraps the [paypal api](https://developer.paypal.com/docs/api) asynchronously in a strongly typed manner.
//!
//! Crate: https://crates.io/crates/paypal-rs
//!
//! Documentation: https://docs.rs/paypal-rs
//!
//! Currently in early development.
//!
@ -42,7 +38,7 @@
//! let create_order = CreateOrder::new(order);
//!
//! let _order_created = client
//! .execute(create_order).await.unwrap();
//! .execute(&create_order).await.unwrap();
//! }
//! ```
//!