diff --git a/examples/invoice.rs b/examples/invoice.rs index 7ae1bfd..7fa96c4 100644 --- a/examples/invoice.rs +++ b/examples/invoice.rs @@ -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); diff --git a/src/api/invoice.rs b/src/api/invoice.rs index 03ac35f..197c696 100644 --- a/src/api/invoice.rs +++ b/src/api/invoice.rs @@ -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(()) } } diff --git a/src/api/orders.rs b/src/api/orders.rs index 7253adf..63f8b0d 100644 --- a/src/api/orders.rs +++ b/src/api/orders.rs @@ -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(()) } } diff --git a/src/client.rs b/src/client.rs index 4fb4836..8f32d78 100644 --- a/src/client.rs +++ b/src/client.rs @@ -189,7 +189,7 @@ impl Client { } /// Executes the given endpoint with the given headers. - pub async fn execute_ext(&self, endpoint: E, headers: HeaderParams) -> Result + pub async fn execute_ext(&self, endpoint: &E, headers: HeaderParams) -> Result 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(&self, endpoint: E) -> Result + pub async fn execute(&self, endpoint: &E) -> Result where E: Endpoint, { diff --git a/src/data/common.rs b/src/data/common.rs index cf99c5b..50fa6d2 100644 --- a/src/data/common.rs +++ b/src/data/common.rs @@ -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)] diff --git a/src/data/invoice.rs b/src/data/invoice.rs index eefeb1f..675bee2 100644 --- a/src/data/invoice.rs +++ b/src/data/invoice.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index 405c76e..c363cfa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(); //! } //! ``` //!