From f98344a16c042e6d09e69397fc660c9ad89457f6 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Mon, 8 Feb 2021 10:19:28 +0100 Subject: [PATCH] some fixes --- src/invoice.rs | 35 ++++++++++++++++++++++++++++++----- src/lib.rs | 20 +++++++------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/invoice.rs b/src/invoice.rs index d0f7e11..244a3a3 100644 --- a/src/invoice.rs +++ b/src/invoice.rs @@ -10,6 +10,7 @@ use crate::common::*; use crate::errors::{PaypalError, ResponseError}; use crate::HeaderParams; use bytes::Bytes; +use chrono::NaiveDate; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use std::collections::HashMap; @@ -59,7 +60,7 @@ pub struct PaymentTerm { /// The payment term. Payment can be due upon receipt, a specified date, or in a set number of days pub term_type: PaymentTermType, /// The date when the invoice payment is due, - pub due_date: Option>, + pub due_date: Option, } /// Flow type @@ -124,9 +125,9 @@ pub struct InvoiceDetail { /// The invoice number. Default is the number that is auto-incremented number from the last number. pub invoice_number: String, /// The invoice date as specificed by the sender - pub invoice_date: chrono::DateTime, + pub invoice_date: chrono::NaiveDate, /// The payment due date for the invoice. - pub payment_term: PaymentTerm, + pub payment_term: Option, /// The audit metadata pub metadata: Metadata, } @@ -556,9 +557,9 @@ pub struct Invoice { /// The details of the invoice. Includes the invoice number, date, payment terms, and audit metadata. pub detail: InvoiceDetail, /// The invoicer information. Includes the business name, email, address, phone, fax, tax ID, additional notes, and logo URL. - pub invoicer: InvoicerInfo, + pub invoicer: Option, /// The billing and shipping information. Includes name, email, address, phone and language. - pub primary_recipients: Vec, + pub primary_recipients: Option>, /// An array of one or more CC: emails to which notifications are sent. /// If you omit this parameter, a notification is sent to all CC: email addresses that are part of the invoice. pub additional_recipients: Option>, @@ -887,3 +888,27 @@ impl super::Client { // TODO: https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete } + +#[cfg(test)] +mod tests { + use crate::{invoice::*, Client, HeaderParams}; + + async fn create_client() -> Client { + dotenv::dotenv().ok(); + let clientid = std::env::var("PAYPAL_CLIENTID").unwrap(); + let secret = std::env::var("PAYPAL_SECRET").unwrap(); + + let client = Client::new(clientid, secret, true); + + client + } + + #[tokio::test] + async fn test_invoice() { + let mut client = create_client().await; + + let list = client.list_invoices(1, 10, HeaderParams::default()).await.unwrap(); + + println!("{:?}", list); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5b9a07c..035d0a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,10 +40,7 @@ //! let order = client //! .create_order( //! order_payload, -//! HeaderParams { -//! prefer: Some(Prefer::Representation), -//! ..Default::default() -//! }, +//! HeaderParams::default(), //! ) //! .await //! .unwrap(); @@ -192,7 +189,7 @@ pub enum Prefer { impl Default for Prefer { fn default() -> Self { - Prefer::Minimal + Prefer::Representation } } @@ -214,7 +211,7 @@ pub struct HeaderParams { /// You can retry calls that fail with network timeouts or the HTTP 500 status code. You can retry calls for as long as the server stores the ID. pub request_id: Option, /// The preferred server response upon successful completion of the request. - pub prefer: Option, + pub prefer: Prefer, /// The media type. Required for operations with a request body. pub content_type: Option, } @@ -318,12 +315,10 @@ impl Client { headers.append("PayPal-Request-Id", request_id.parse().unwrap()); } - if let Some(prefer) = header_params.prefer { - match prefer { - Prefer::Minimal => headers.append("Prefer", "return=minimal".parse().unwrap()), - Prefer::Representation => headers.append("Prefer", "return=representation".parse().unwrap()), - }; - } + match header_params.prefer { + Prefer::Minimal => headers.append("Prefer", "return=minimal".parse().unwrap()), + Prefer::Representation => headers.append("Prefer", "return=representation".parse().unwrap()), + }; if let Some(content_type) = header_params.content_type { headers.append(header::CONTENT_TYPE, content_type.parse().unwrap()); @@ -409,7 +404,6 @@ mod tests { .create_order( order, HeaderParams { - prefer: Some(Prefer::Representation), request_id: Some(ref_id.clone()), ..Default::default() },