From aa5cdf3e01719ed6e4843e6fc0c3948c2164df64 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Fri, 8 Apr 2022 17:04:30 +0200 Subject: [PATCH] progress --- src/api/invoice.rs | 444 +++++++++++++++++++++++++------------------- src/api/orders.rs | 4 + src/client.rs | 7 +- src/data/invoice.rs | 67 +++---- src/data/orders.rs | 13 +- src/lib.rs | 20 +- 6 files changed, 307 insertions(+), 248 deletions(-) diff --git a/src/api/invoice.rs b/src/api/invoice.rs index 03e1fe1..74e7844 100644 --- a/src/api/invoice.rs +++ b/src/api/invoice.rs @@ -6,195 +6,265 @@ //! //! Reference: https://developer.paypal.com/docs/api/invoicing/v2/ +use std::borrow::Cow; -/* +use derive_builder::Builder; +use serde::Serialize; + +use crate::{ + data::{ + invoice::{Invoice, InvoiceList, InvoicePayload, CancelReason}, + orders::InvoiceNumber, + }, + endpoint::Endpoint, + Query, +}; + +/// Generates the next invoice number that is available to the merchant. +/// +/// The next invoice number uses the prefix and suffix from the last invoice number and increments the number by one. +/// +/// For example, the next invoice number after `INVOICE-1234` is `INVOICE-1235`. +#[derive(Debug, Default, Clone)] +pub struct GenerateInvoiceNumber { + pub invoice_number: Option, +} + +impl GenerateInvoiceNumber { + pub fn new(invoice_number: Option) -> Self { + Self { invoice_number } + } +} + +impl Endpoint for GenerateInvoiceNumber { + type Query = (); + + type Body = Option; + + type Response = InvoiceNumber; + + fn relative_path(&self) -> Cow { + Cow::Borrowed("/v2/invoicing/generate-next-invoice-number") + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::POST + } + + fn body(&self) -> Option<&Self::Body> { + Some(&self.invoice_number) + } +} + +/// Creates a draft invoice. To move the invoice from a draft to payable state, you must send the invoice. +/// Include invoice details including merchant information. The invoice object must include an items array. +#[derive(Debug, Clone)] +pub struct CreateDraftInvoice { + pub invoice: InvoicePayload, +} + +impl CreateDraftInvoice { + pub fn new(invoice: InvoicePayload) -> Self { + Self { invoice } + } +} + +impl Endpoint for CreateDraftInvoice { + type Query = (); + + type Body = InvoicePayload; + + type Response = Invoice; + + fn relative_path(&self) -> Cow { + Cow::Borrowed("/v2/invoicing/invoices") + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::POST + } + + fn body(&self) -> Option<&Self::Body> { + Some(&self.invoice) + } +} + +/// Get an invoice by ID. +#[derive(Debug, Clone)] +pub struct GetInvoice { + pub invoice_id: String, +} + +impl GetInvoice { + pub fn new(invoice_id: String) -> Self { + Self { invoice_id } + } +} + +impl Endpoint for GetInvoice { + type Query = (); + + type Body = (); + + type Response = Invoice; + + fn relative_path(&self) -> Cow { + Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice_id)) + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::GET + } +} + +/// List invoices +/// Page size has the following limits: [1, 100]. +#[derive(Debug, Clone)] +pub struct ListInvoices { + pub query: Query, +} + +impl ListInvoices { + pub fn new(query: Query) -> Self { + Self { query } + } +} + +impl Endpoint for ListInvoices { + type Query = Query; + + type Body = (); + + type Response = InvoiceList; + + fn relative_path(&self) -> Cow { + Cow::Borrowed("/v2/invoicing/invoices") + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::GET + } + + fn query(&self) -> Option<&Self::Query> { + Some(&self.query) + } +} + +/// Delete an invoice +#[derive(Debug, Clone)] +pub struct DeleteInvoice { + pub invoice_id: String, +} + +impl DeleteInvoice { + pub fn new(invoice_id: String) -> Self { + Self { invoice_id } + } +} + +impl Endpoint for DeleteInvoice { + type Query = Query; + + type Body = (); + + type Response = (); + + fn relative_path(&self) -> Cow { + Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice_id)) + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::DELETE + } +} + +#[derive(Debug, Clone, Serialize, Builder)] +pub struct UpdateInvoiceQuery { + pub send_to_recipient: bool, + pub send_to_invoicer: bool, +} + +/// Update an invoice. +/// +/// Fully updates an invoice, by ID. In the JSON request body, include a complete invoice object. This call does not support partial updates. +#[derive(Debug, Clone)] +pub struct UpdateInvoice { + pub invoice: Invoice, + pub query: UpdateInvoiceQuery, +} + +impl UpdateInvoice { + pub fn new(invoice: Invoice, query: UpdateInvoiceQuery) -> Self { + Self { + invoice, + query + } + } +} + +impl Endpoint for UpdateInvoice { + type Query = UpdateInvoiceQuery; + + type Body = Invoice; + + type Response = Invoice; + + fn relative_path(&self) -> Cow { + Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice.id)) + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::PUT + } + + fn body(&self) -> Option<&Self::Body> { + Some(&self.invoice) + } + + fn query(&self) -> Option<&Self::Query> { + Some(&self.query) + } +} + +/// Cancel an invoice. +#[derive(Debug, Clone)] +pub struct CancelInvoice { + pub invoice_id: String, + pub reason: CancelReason +} + +impl CancelInvoice { + pub fn new(invoice_id: String, reason: CancelReason) -> Self { + Self { + invoice_id, + reason + } + } +} + +impl Endpoint for CancelInvoice { + type Query = (); + + type Body = CancelReason; + + type Response = (); + + fn relative_path(&self) -> Cow { + Cow::Owned(format!("/v2/invoicing/invoices/{}/cancel", self.invoice_id)) + } + + fn method(&self) -> reqwest::Method { + reqwest::Method::POST + } + + fn body(&self) -> Option<&Self::Body> { + Some(&self.reason) + } +} + +/* impl super::Client { - /// Generates the next invoice number that is available to the merchant. - /// - /// The next invoice number uses the prefix and suffix from the last invoice number and increments the number by one. - /// - /// For example, the next invoice number after `INVOICE-1234` is `INVOICE-1235`. - pub async fn generate_invoice_number( - &mut self, - header_params: crate::HeaderParams, - ) -> Result { - let build = self - .setup_headers( - self.client - .post(format!("{}/v2/invoicing/generate-next-invoice-number", self.endpoint()).as_str()), - header_params, - ) - .await; - - let res = build.send().await?; - - if res.status().is_success() { - let x = res.json::>().await?; - Ok(x.get("invoice_number").expect("to have a invoice number").clone()) - } else { - Err(res.json::().await?.into()) - } - } - - /// Creates a draft invoice. To move the invoice from a draft to payable state, you must send the invoice. - /// Include invoice details including merchant information. The invoice object must include an items array. - pub async fn create_draft_invoice( - &mut self, - invoice: InvoicePayload, - header_params: HeaderParams, - ) -> Result { - let build = self - .setup_headers( - self.client - .post(format!("{}/v2/invoicing/invoices", self.endpoint()).as_str()), - header_params, - ) - .await; - - let res = build.json(&invoice).send().await?; - - if res.status().is_success() { - //println!("{:#?}", res.text().await?); - let inv = res.json::().await?; - Ok(inv) - } else { - Err(res.json::().await?.into()) - } - } - - /// Get an invoice by ID. - pub async fn get_invoice( - &mut self, - invoice_id: &str, - header_params: HeaderParams, - ) -> Result { - let build = self - .setup_headers( - self.client - .post(format!("{}/v2/invoicing/invoices/{}", self.endpoint(), invoice_id).as_str()), - header_params, - ) - .await; - - let res = build.send().await?; - - if res.status().is_success() { - let x = res.json::().await?; - Ok(x) - } else { - Err(res.json::().await?.into()) - } - } - - /// List invoices - /// Page size has the following limits: [1, 100]. - pub async fn list_invoices( - &mut self, - page: i32, - page_size: i32, - header_params: HeaderParams, - ) -> Result { - let build = self - .setup_headers( - self.client.get( - format!( - "{}/v2/invoicing/invoices?page={}&page_size={}&total_required=true", - self.endpoint(), - page, - page_size - ) - .as_str(), - ), - header_params, - ) - .await; - - let res = build.send().await?; - - if res.status().is_success() { - let x = res.json::().await?; - Ok(x) - } else { - Err(res.json::().await?.into()) - } - } - - /// Delete a invoice - pub async fn delete_invoice(&mut self, invoice_id: &str, header_params: HeaderParams) -> Result<(), ResponseError> { - let build = self - .setup_headers( - self.client - .delete(format!("{}/v2/invoicing/invoices/{}", self.endpoint(), invoice_id).as_str()), - header_params, - ) - .await; - - let res = build.send().await?; - - if res.status().is_success() { - Ok(()) - } else { - Err(res.json::().await?.into()) - } - } - - /// Update a invoice - pub async fn update_invoice( - &mut self, - invoice: Invoice, - send_to_recipient: bool, - send_to_invoicer: bool, - header_params: HeaderParams, - ) -> Result<(), ResponseError> { - let build = self - .setup_headers( - self.client.put( - format!( - "{}/v2/invoicing/invoices/{}?send_to_recipient={}&send_to_invoicer={}", - self.endpoint(), - invoice.id, - send_to_recipient, - send_to_invoicer - ) - .as_str(), - ), - header_params, - ) - .await; - - let res = build.send().await?; - - if res.status().is_success() { - Ok(()) - } else { - Err(res.json::().await?.into()) - } - } - - /// Cancel a invoice - pub async fn cancel_invoice( - &mut self, - invoice_id: &str, - reason: CancelReason, - header_params: HeaderParams, - ) -> Result<(), ResponseError> { - let build = self - .setup_headers( - self.client - .post(format!("{}/v2/invoicing/invoices/{}/cancel", self.endpoint(), invoice_id,).as_str()), - header_params, - ) - .await; - - let res = build.json(&reason).send().await?; - - if res.status().is_success() { - Ok(()) - } else { - Err(res.json::().await?.into()) - } - } /// Generate a QR code pub async fn generate_qr_code( @@ -276,4 +346,4 @@ mod tests { } } -*/ \ No newline at end of file +*/ diff --git a/src/api/orders.rs b/src/api/orders.rs index 1a107f6..f73ded3 100644 --- a/src/api/orders.rs +++ b/src/api/orders.rs @@ -1,3 +1,7 @@ +//! An order represents a payment between two or more parties. Use the Orders API to create, update, retrieve, authorize, and capture orders. +//! +//! https://developer.paypal.com/docs/api/orders/v2/ + use std::borrow::Cow; use crate::{ diff --git a/src/client.rs b/src/client.rs index fa0b574..7331a93 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,7 +6,7 @@ use std::time::Instant; use crate::{ endpoint::Endpoint, errors::{PaypalError, ResponseError}, - AuthAssertionClaims, HeaderParams, Prefer, LIVE_ENDPOINT, SANDBOX_ENDPOINT, + AuthAssertionClaims, HeaderParams, LIVE_ENDPOINT, SANDBOX_ENDPOINT, }; /// Represents the access token returned by the OAuth2 authentication. @@ -140,10 +140,7 @@ impl Client { headers.append("PayPal-Request-Id", request_id.parse().unwrap()); } - match header_params.prefer { - Prefer::Minimal => headers.append("Prefer", "return=minimal".parse().unwrap()), - Prefer::Representation => headers.append("Prefer", "return=representation".parse().unwrap()), - }; + 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()); diff --git a/src/data/invoice.rs b/src/data/invoice.rs index cac9d2b..8d6e240 100644 --- a/src/data/invoice.rs +++ b/src/data/invoice.rs @@ -1,9 +1,10 @@ use crate::{data::common::*, data::common::LinkDescription}; +use derive_builder::Builder; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; /// Paypal File reference -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct FileReference { /// The ID of the referenced file. pub id: String, @@ -17,7 +18,7 @@ pub struct FileReference { pub size: String, } -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// The payment term type. pub enum PaymentTermType { @@ -42,7 +43,7 @@ pub enum PaymentTermType { } /// The payment due date for the invoice. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] 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, @@ -51,7 +52,7 @@ pub struct PaymentTerm { } /// Flow type -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] /// The flow variation pub enum FlowType { @@ -65,7 +66,7 @@ pub enum FlowType { /// Metadata about a resource #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Metadata { /// The date and time when the resource was created pub create_time: Option>, @@ -95,7 +96,7 @@ pub struct Metadata { /// The details of the invoice. Includes the invoice number, date, payment terms, and audit metadata. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct InvoiceDetail { /// The reference data. Includes a post office (PO) number. pub reference: Option, @@ -121,7 +122,7 @@ pub struct InvoiceDetail { /// A name to be used as recipient, etc. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Name { /// The prefix, or title, to the party's name. pub prefix: Option, @@ -144,7 +145,7 @@ pub struct Name { /// Phone information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct PhoneDetail { /// The country calling code (CC), in its canonical international E.164 numbering plan format. pub country_code: String, @@ -158,7 +159,7 @@ pub struct PhoneDetail { /// The invoicer information. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct InvoicerInfo { /// Required. The business name of the party. pub business_name: String, @@ -181,7 +182,7 @@ pub struct InvoicerInfo { /// Billing information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct BillingInfo { /// Required. The business name of the party. pub business_name: String, @@ -201,7 +202,7 @@ pub struct BillingInfo { /// Contact information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ContactInformation { /// Required. The business name of the party. pub business_name: String, @@ -213,7 +214,7 @@ pub struct ContactInformation { /// Recipient information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct RecipientInfo { /// The billing information for the invoice recipient. Includes name, address, email, phone, and language. pub billing_info: Option, @@ -223,7 +224,7 @@ pub struct RecipientInfo { /// Tax information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Tax { /// The name of the tax applied on the invoice items. pub name: String, @@ -234,7 +235,7 @@ pub struct Tax { } /// Discount information -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Discount { /// The discount as a percentage value. Value is from 0 to 100. Supports up to five decimal places. pub percent: Option, @@ -243,7 +244,7 @@ pub struct Discount { } /// The unit of measure for the invoiced item. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum UnitOfMeasure { /// The unit of measure is quantity. This invoice template is typically used for physical goods. @@ -256,7 +257,7 @@ pub enum UnitOfMeasure { /// Item information #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Item { /// The ID of the invoice line item. /// Read only. @@ -281,7 +282,7 @@ pub struct Item { /// The partial payment details. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct PartialPayment { /// Indicates whether the invoice allows a partial payment. If false, the invoice must be paid in full. If true, the invoice allows partial payments. pub allow_partial_payment: Option, @@ -291,7 +292,7 @@ pub struct PartialPayment { /// The invoice configuration details. Includes partial payment, tip, and tax calculated after discount. #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Configuration { /// Indicates whether the tax is calculated before or after a discount. If false, the tax is calculated before a discount. If true, the tax is calculated after a discount. pub tax_calculated_after_discount: Option, @@ -308,7 +309,7 @@ pub struct Configuration { /// The discount #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct AggregatedDiscount { /// The discount as a percent or amount at invoice level. The invoice discount amount is subtracted from the item total. pub invoice_discount: Option, @@ -317,7 +318,7 @@ pub struct AggregatedDiscount { } /// The shipping fee -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct ShippingCost { /// The shipping amount. Value is from 0 to 1000000. Supports up to two decimal places. pub amount: Option, @@ -327,7 +328,7 @@ pub struct ShippingCost { /// The custom amount to apply to an invoice #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct CustomAmount { /// The label to the custom amount of the invoice. pub label: String, @@ -337,7 +338,7 @@ pub struct CustomAmount { /// The breakdown of the amount. Breakdown provides details such as total item amount, total tax amount, custom amount, shipping and discounts, if any. #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct Breakdown { /// The subtotal for all items. Must equal the sum of (items[].unit_amount * items[].quantity) for all items. pub item_total: Option, @@ -353,7 +354,7 @@ pub struct Breakdown { /// Represents an amount of money. #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct Amount { /// The [three-character ISO-4217 currency code](https://developer.paypal.com/docs/integration/direct/rest/currency-codes/) that identifies the currency. pub currency_code: Currency, @@ -379,7 +380,7 @@ impl Amount { } /// The payment type in an invoicing flow -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PaymentType { /// The payment type is PayPal. @@ -389,7 +390,7 @@ pub enum PaymentType { } /// The payment mode or method through which the invoicer can accept the payment. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PaymentMethod { /// Payments can be received through bank transfers. @@ -418,7 +419,7 @@ impl Default for PaymentMethod { /// Payment detail #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct PaymentDetail { /// The payment type in an invoicing flow which can be PayPal or an external cash or check payment. pub r#type: Option, @@ -438,7 +439,7 @@ pub struct PaymentDetail { /// Payments registered against the invoice #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct Payments { /// The aggregated payment amounts against this invoice. /// Read only. @@ -450,7 +451,7 @@ pub struct Payments { /// Refund details #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RefundDetail { /// The PayPal refund type. Indicates whether the refund was paid through PayPal or externally in the invoicing flow. pub r#type: Option, @@ -466,7 +467,7 @@ pub struct RefundDetail { /// List of refunds #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Refunds { /// The aggregated refund amounts. /// Read only. @@ -477,7 +478,7 @@ pub struct Refunds { } /// The status of the invoice -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum Status { /// The invoice is in draft state. It is not yet sent to the payer. @@ -508,7 +509,7 @@ pub enum Status { /// An invoice payload #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct InvoicePayload { /// The details of the invoice. Includes the invoice number, date, payment terms, and audit metadata. pub detail: InvoiceDetail, @@ -533,7 +534,7 @@ pub struct InvoicePayload { /// Definition: https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Invoice { /// The ID of the invoice. pub id: String, @@ -583,7 +584,7 @@ pub struct InvoiceList { /// Cancel invoice reason #[skip_serializing_none] -#[derive(Debug, Serialize, Deserialize, Default)] +#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)] pub struct CancelReason { /// The subject of the email that is sent as a notification to the recipient. pub subject: Option, diff --git a/src/data/orders.rs b/src/data/orders.rs index 3070074..efdb0cd 100644 --- a/src/data/orders.rs +++ b/src/data/orders.rs @@ -602,7 +602,7 @@ impl OrderPayload { } /// The card brand or network. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum CardBrand { /// Visa card. @@ -639,7 +639,7 @@ pub enum CardBrand { ChinaUnionPay, } -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Copy)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] #[allow(missing_docs)] pub enum CardType { @@ -650,7 +650,7 @@ pub enum CardType { } /// The payment card to use to fund a payment. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct CardResponse { /// The last digits of the payment card. pub last_digits: String, @@ -662,7 +662,7 @@ pub struct CardResponse { } /// The customer's wallet used to fund the transaction. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct WalletResponse { /// Apple Pay Wallet response information. pub apple_pay: CardResponse, @@ -717,4 +717,9 @@ pub struct Order { pub status: OrderStatus, /// An array of request-related HATEOAS links. To complete payer approval, use the approve link to redirect the payer. pub links: Vec, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct InvoiceNumber { + pub invoice_number: String, } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 241caa0..22a2b9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,7 +102,7 @@ pub const SANDBOX_ENDPOINT: &str = "https://api-m.sandbox.paypal.com"; /// let query = Query { count: Some(40), ..Default::default() }; /// ``` #[skip_serializing_none] -#[derive(Debug, Default, Serialize, Builder)] +#[derive(Debug, Default, Serialize, Builder, Clone)] pub struct Query { /// The number of items to list in the response. pub count: Option, @@ -131,22 +131,6 @@ pub struct Query { // TODO: Use https://github.com/samscott89/serde_qs } -/// The preferred server response upon successful completion of the request. -#[derive(Debug, Eq, PartialEq, Copy, Clone)] -pub enum Prefer { - /// The server returns a minimal response to optimize communication between the API caller and the server. - /// A minimal response includes the id, status and HATEOAS links. - Minimal, - /// The server returns a complete resource representation, including the current state of the resource. - Representation, -} - -impl Default for Prefer { - fn default() -> Self { - Prefer::Representation - } -} - /// Represents the optional header values used on paypal requests. /// /// https://developer.paypal.com/docs/api/reference/api-requests/#paypal-auth-assertion @@ -164,8 +148,6 @@ pub struct HeaderParams { /// You can make these calls any number of times without concern that the server creates or completes an action on a resource more than once. /// 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: Prefer, /// The media type. Required for operations with a request body. pub content_type: Option, }