upd deps and fix invoice date

This commit is contained in:
Edgar 2021-12-30 23:48:09 +01:00
parent f545a85d0c
commit b5b0dfb5af
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
4 changed files with 50 additions and 24 deletions

View file

@ -13,16 +13,16 @@ edition = "2018"
[dependencies] [dependencies]
reqwest = { version = "0.11", features = ["json"] } reqwest = { version = "0.11.8", features = ["json"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0.132", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0.73"
serde_with = "1.9" serde_with = "1.11.0"
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] }
jsonwebtoken = "7.2" jsonwebtoken = "7.2.0"
base64 = "0.13" base64 = "0.13.0"
log = "0.4" log = "0.4.14"
bytes = "1.0" bytes = "1.1.0"
[dev-dependencies] [dev-dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
dotenv = "0.15" dotenv = "0.15.0"

0
src/client.rs Normal file
View file

View file

@ -10,7 +10,6 @@ use crate::common::*;
use crate::errors::{PaypalError, ResponseError}; use crate::errors::{PaypalError, ResponseError};
use crate::HeaderParams; use crate::HeaderParams;
use bytes::Bytes; use bytes::Bytes;
use chrono::NaiveDate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use std::collections::HashMap; use std::collections::HashMap;
@ -125,7 +124,7 @@ pub struct InvoiceDetail {
/// The invoice number. Default is the number that is auto-incremented number from the last number. /// The invoice number. Default is the number that is auto-incremented number from the last number.
pub invoice_number: Option<String>, pub invoice_number: Option<String>,
/// The invoice date as specificed by the sender /// The invoice date as specificed by the sender
pub invoice_date: Option<chrono::DateTime<chrono::Utc>>, pub invoice_date: Option<chrono::NaiveDate>,
/// The payment due date for the invoice. /// The payment due date for the invoice.
pub payment_term: Option<PaymentTerm>, pub payment_term: Option<PaymentTerm>,
/// The audit metadata /// The audit metadata
@ -910,6 +909,6 @@ mod tests {
let list = client.list_invoices(1, 10, HeaderParams::default()).await.unwrap(); let list = client.list_invoices(1, 10, HeaderParams::default()).await.unwrap();
println!("{:?}", list); println!("{:#?}", list);
} }
} }

View file

@ -1,4 +1,7 @@
//! [![Crates.io](https://meritbadge.herokuapp.com/paypal-rs)](https://crates.io/crates/paypal-rs) //!
//! [![Version](https://img.shields.io/crates/v/paypal-rs)](https://crates.io/crates/paypal-rs)
//! [![Downloads](https://img.shields.io/crates/d/paypal-rs)](https://crates.io/crates/paypal-rs)
//! [![License](https://img.shields.io/crates/l/paypal-rs)](https://crates.io/crates/paypal-rs)
//! ![Rust](https://github.com/edg-l/paypal-rs/workflows/Rust/badge.svg) //! ![Rust](https://github.com/edg-l/paypal-rs/workflows/Rust/badge.svg)
//! [![Docs](https://docs.rs/paypal-rs/badge.svg)](https://docs.rs/paypal-rs) //! [![Docs](https://docs.rs/paypal-rs/badge.svg)](https://docs.rs/paypal-rs)
//! //!
@ -88,7 +91,7 @@ use reqwest::header;
use reqwest::header::HeaderMap; use reqwest::header::HeaderMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use std::time::{Duration, Instant}; use std::{borrow::Cow, time::{Duration, Instant}};
/// The paypal api endpoint used on a live application. /// The paypal api endpoint used on a live application.
pub const LIVE_ENDPOINT: &str = "https://api-m.paypal.com"; pub const LIVE_ENDPOINT: &str = "https://api-m.paypal.com";
@ -131,7 +134,7 @@ pub struct Auth {
#[derive(Debug)] #[derive(Debug)]
pub struct Client { pub struct Client {
/// Internal http client /// Internal http client
pub client: reqwest::Client, pub(crate) client: reqwest::Client,
/// Whether you are or not in a sandbox enviroment. /// Whether you are or not in a sandbox enviroment.
pub sandbox: bool, pub sandbox: bool,
/// Api Auth information /// Api Auth information
@ -244,13 +247,13 @@ impl Client {
/// client.get_access_token().await.unwrap(); /// client.get_access_token().await.unwrap();
/// } /// }
/// ``` /// ```
pub fn new<S: Into<String>>(client_id: S, secret: S, sandbox: bool) -> Client { pub fn new(client_id: String, secret: String, sandbox: bool) -> Client {
Client { Client {
client: reqwest::Client::new(), client: reqwest::Client::new(),
sandbox, sandbox,
auth: Auth { auth: Auth {
client_id: client_id.into(), client_id,
secret: secret.into(), secret,
access_token: None, access_token: None,
expires: None, expires: None,
}, },
@ -365,11 +368,37 @@ impl Client {
} }
} }
pub(crate) trait FromResponse: Sized {
type Response;
fn from_response(res: Self::Response) -> Self;
}
pub(crate) trait Endpoint {
type Query: Serialize;
type Body: Serialize;
type Response: FromResponse;
fn path(&self) -> Cow<str>;
fn method(&self) -> reqwest::Method {
reqwest::Method::GET
}
fn query(&self) -> Option<&Self::Query> {
None
}
fn body(&self) -> Option<&Self::Body> {
None
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::common::Currency; use crate::common::Currency;
use crate::countries::Country; use crate::countries::Country;
use crate::{orders::*, Client, HeaderParams, Prefer}; use crate::{orders::*, Client, HeaderParams};
use std::env; use std::env;
use std::str::FromStr; use std::str::FromStr;
@ -378,9 +407,7 @@ mod tests {
let clientid = env::var("PAYPAL_CLIENTID").unwrap(); let clientid = env::var("PAYPAL_CLIENTID").unwrap();
let secret = env::var("PAYPAL_SECRET").unwrap(); let secret = env::var("PAYPAL_SECRET").unwrap();
let client = Client::new(clientid, secret, true); Client::new(clientid, secret, true)
client
} }
#[tokio::test] #[tokio::test]