fix conflict
This commit is contained in:
parent
f98344a16c
commit
32b9f74994
|
@ -14,14 +14,14 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.11.0", features = ["json"] }
|
reqwest = { version = "0.11.0", features = ["json"] }
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.119", features = ["derive"] }
|
||||||
serde_json = "1.0.61"
|
serde_json = "1.0.61"
|
||||||
serde_with = "1.6.2"
|
serde_with = "1.6.2"
|
||||||
chrono = { version = "0.4.19", features = ["serde"] }
|
chrono = { version = "0.4.19", features = ["serde"] }
|
||||||
jsonwebtoken = "7.2.0"
|
jsonwebtoken = "7.2.0"
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
log = "0.4.11"
|
log = "0.4.13"
|
||||||
bytes = "1.0.0"
|
bytes = "1.0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.0.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.0.1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
81
examples/invoice.rs
Normal file
81
examples/invoice.rs
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
use paypal_rs::{
|
||||||
|
Client,
|
||||||
|
HeaderParams,
|
||||||
|
Prefer,
|
||||||
|
invoice::*,
|
||||||
|
common::*,
|
||||||
|
errors::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), ResponseError> {
|
||||||
|
dotenv::dotenv().ok();
|
||||||
|
|
||||||
|
let clientid = std::env::var("PAYPAL_CLIENTID").unwrap();
|
||||||
|
let secret = std::env::var("PAYPAL_SECRET").unwrap();
|
||||||
|
|
||||||
|
let mut client = Client::new(clientid, secret, true);
|
||||||
|
|
||||||
|
let payload = InvoicePayload {
|
||||||
|
detail: InvoiceDetail {
|
||||||
|
currency_code: Currency::EUR,
|
||||||
|
//reference: Some("deal-ref".to_owned()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
invoicer: Some(InvoicerInfo {
|
||||||
|
name: Some(Name {
|
||||||
|
given_name: Some("Lucas".to_owned()),
|
||||||
|
prefix: None,
|
||||||
|
suffix: None,
|
||||||
|
surname: None,
|
||||||
|
full_name: None,
|
||||||
|
middle_name: None,
|
||||||
|
alternate_full_name: None,
|
||||||
|
}),
|
||||||
|
phones: None,
|
||||||
|
tax_id: None,
|
||||||
|
website: None,
|
||||||
|
business_name: "Lucas Corp".to_owned(),
|
||||||
|
logo_url: None,
|
||||||
|
// needs to be a valid address...
|
||||||
|
email_address: Some("merchant@example.com".to_owned()),
|
||||||
|
additional_notes: None,
|
||||||
|
}),
|
||||||
|
items: vec![
|
||||||
|
Item {
|
||||||
|
id: None,
|
||||||
|
name: "My item".to_owned(),
|
||||||
|
unit_amount: Money {
|
||||||
|
currency_code: Currency::EUR,
|
||||||
|
value: "10.0".to_owned()
|
||||||
|
},
|
||||||
|
quantity: "1".to_owned(),
|
||||||
|
discount: None,
|
||||||
|
item_date: None,
|
||||||
|
description: Some("A random item".to_owned()),
|
||||||
|
tax: Some(Tax {
|
||||||
|
name: "Sales tax".to_owned(),
|
||||||
|
percent: "7".to_owned(),
|
||||||
|
amount: None,
|
||||||
|
}),
|
||||||
|
unit_of_measure: Some(UnitOfMeasure::Quantity),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
match client.create_draft_invoice(payload, HeaderParams::default()).await {
|
||||||
|
Ok(r) => {
|
||||||
|
println!("{:#?}", r);
|
||||||
|
},
|
||||||
|
Err(ResponseError::HttpError(e)) => {
|
||||||
|
println!("{}", e);
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("{:#?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// some stuff is not sent when representation is minimal.
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -94,7 +94,7 @@ pub struct LinkDescription {
|
||||||
/// The complete target URL.
|
/// The complete target URL.
|
||||||
pub href: String,
|
pub href: String,
|
||||||
/// The link relation type, which serves as an ID for a link that unambiguously describes the semantics of the link.
|
/// The link relation type, which serves as an ID for a link that unambiguously describes the semantics of the link.
|
||||||
pub rel: String,
|
pub rel: Option<String>,
|
||||||
/// The HTTP method required to make the related call.
|
/// The HTTP method required to make the related call.
|
||||||
pub method: Option<LinkMethod>,
|
pub method: Option<LinkMethod>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ pub struct PaypalError {
|
||||||
/// The error name.
|
/// The error name.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// The error message.
|
/// The error message.
|
||||||
pub message: String,
|
pub message: Option<String>,
|
||||||
/// Paypal debug id
|
/// Paypal debug id
|
||||||
pub debug_id: String,
|
pub debug_id: Option<String>,
|
||||||
/// Error details
|
/// Error details
|
||||||
pub details: Vec<HashMap<String, String>>,
|
pub details: Vec<HashMap<String, String>>,
|
||||||
/// Only available on Identity errors
|
/// Only available on Identity errors
|
||||||
|
|
|
@ -113,7 +113,7 @@ pub struct InvoiceDetail {
|
||||||
/// The reference data. Includes a post office (PO) number.
|
/// The reference data. Includes a post office (PO) number.
|
||||||
pub reference: Option<String>,
|
pub reference: Option<String>,
|
||||||
/// The three-character ISO-4217 currency code that identifies the currency.
|
/// The three-character ISO-4217 currency code that identifies the currency.
|
||||||
pub currency_code: String,
|
pub currency_code: Currency,
|
||||||
/// A note to the invoice recipient. Also appears on the invoice notification email.
|
/// A note to the invoice recipient. Also appears on the invoice notification email.
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
/// The general terms of the invoice. Can include return or cancellation policy and other terms and conditions.
|
/// The general terms of the invoice. Can include return or cancellation policy and other terms and conditions.
|
||||||
|
@ -123,13 +123,13 @@ pub struct InvoiceDetail {
|
||||||
/// An array of PayPal IDs for the files that are attached to an invoice.
|
/// An array of PayPal IDs for the files that are attached to an invoice.
|
||||||
pub attachments: Option<Vec<FileReference>>,
|
pub attachments: Option<Vec<FileReference>>,
|
||||||
/// 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: 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: chrono::NaiveDate,
|
pub invoice_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
/// 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
|
||||||
pub metadata: Metadata,
|
pub metadata: Option<Metadata>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A name to be used as recipient, etc.
|
/// A name to be used as recipient, etc.
|
||||||
|
@ -258,7 +258,7 @@ pub struct Discount {
|
||||||
/// The unit of measure for the invoiced item.
|
/// The unit of measure for the invoiced item.
|
||||||
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
|
||||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
pub enum UnitOffMeasure {
|
pub enum UnitOfMeasure {
|
||||||
/// The unit of measure is quantity. This invoice template is typically used for physical goods.
|
/// The unit of measure is quantity. This invoice template is typically used for physical goods.
|
||||||
Quantity,
|
Quantity,
|
||||||
/// The unit of measure is hours. This invoice template is typically used for services.
|
/// The unit of measure is hours. This invoice template is typically used for services.
|
||||||
|
@ -289,7 +289,7 @@ pub struct Item {
|
||||||
/// Discount as a percent or amount at invoice level. The invoice discount amount is subtracted from the item total.
|
/// Discount as a percent or amount at invoice level. The invoice discount amount is subtracted from the item total.
|
||||||
pub discount: Option<Discount>,
|
pub discount: Option<Discount>,
|
||||||
/// The unit of measure for the invoiced item. For AMOUNT the unit_amount and quantity are not shown on the invoice.
|
/// The unit of measure for the invoiced item. For AMOUNT the unit_amount and quantity are not shown on the invoice.
|
||||||
pub unit_of_measure: Option<UnitOffMeasure>,
|
pub unit_of_measure: Option<UnitOfMeasure>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The partial payment details.
|
/// The partial payment details.
|
||||||
|
@ -369,7 +369,7 @@ pub struct Breakdown {
|
||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct Amount {
|
pub struct Amount {
|
||||||
/// The [three-character ISO-4217 currency code](https://developer.paypal.com/docs/integration/direct/rest/currency-codes/) that identifies the currency.
|
/// The [three-character ISO-4217 currency code](https://developer.paypal.com/docs/integration/direct/rest/currency-codes/) that identifies the currency.
|
||||||
pub currency_code: String,
|
pub currency_code: Currency,
|
||||||
/// The value, which might be:
|
/// The value, which might be:
|
||||||
/// - An integer for currencies like JPY that are not typically fractional.
|
/// - An integer for currencies like JPY that are not typically fractional.
|
||||||
/// - A decimal fraction for currencies like TND that are subdivided into thousandths.
|
/// - A decimal fraction for currencies like TND that are subdivided into thousandths.
|
||||||
|
@ -382,9 +382,9 @@ pub struct Amount {
|
||||||
|
|
||||||
impl Amount {
|
impl Amount {
|
||||||
/// Creates a new amount with the required values.
|
/// Creates a new amount with the required values.
|
||||||
pub fn new<S: Into<String>>(currency_code: S, value: S) -> Self {
|
pub fn new(currency_code: Currency, value: &str) -> Self {
|
||||||
Amount {
|
Amount {
|
||||||
currency_code: currency_code.into(),
|
currency_code,
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
breakdown: None,
|
breakdown: None,
|
||||||
}
|
}
|
||||||
|
@ -690,8 +690,9 @@ impl super::Client {
|
||||||
let res = build.json(&invoice).send().await?;
|
let res = build.json(&invoice).send().await?;
|
||||||
|
|
||||||
if res.status().is_success() {
|
if res.status().is_success() {
|
||||||
let x = res.json::<Invoice>().await?;
|
println!("{:#?}", res.text().await?);
|
||||||
Ok(x)
|
//let x = res.json::<Invoice>().await?;
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(res.json::<PaypalError>().await?.into())
|
Err(res.json::<PaypalError>().await?.into())
|
||||||
}
|
}
|
||||||
|
@ -911,4 +912,5 @@ mod tests {
|
||||||
|
|
||||||
println!("{:?}", list);
|
println!("{:?}", list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue