some fixes
This commit is contained in:
parent
86191f455e
commit
f98344a16c
|
@ -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<chrono::DateTime<chrono::Utc>>,
|
||||
pub due_date: Option<chrono::NaiveDate>,
|
||||
}
|
||||
|
||||
/// 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<chrono::Utc>,
|
||||
pub invoice_date: chrono::NaiveDate,
|
||||
/// The payment due date for the invoice.
|
||||
pub payment_term: PaymentTerm,
|
||||
pub payment_term: Option<PaymentTerm>,
|
||||
/// 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<InvoicerInfo>,
|
||||
/// The billing and shipping information. Includes name, email, address, phone and language.
|
||||
pub primary_recipients: Vec<RecipientInfo>,
|
||||
pub primary_recipients: Option<Vec<RecipientInfo>>,
|
||||
/// 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<Vec<String>>,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
20
src/lib.rs
20
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<String>,
|
||||
/// The preferred server response upon successful completion of the request.
|
||||
pub prefer: Option<Prefer>,
|
||||
pub prefer: Prefer,
|
||||
/// The media type. Required for operations with a request body.
|
||||
pub content_type: Option<String>,
|
||||
}
|
||||
|
@ -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()
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue