diff --git a/src/api/invoice.rs b/src/api/invoice.rs index a1a402b..fc08423 100644 --- a/src/api/invoice.rs +++ b/src/api/invoice.rs @@ -45,7 +45,7 @@ impl Endpoint for GenerateInvoiceNumber { type Response = InvoiceNumber; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Borrowed("/v2/invoicing/generate-next-invoice-number") } @@ -80,7 +80,7 @@ impl Endpoint for CreateDraftInvoice { type Response = Invoice; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Borrowed("/v2/invoicing/invoices") } @@ -116,7 +116,7 @@ impl Endpoint for GetInvoice { type Response = Invoice; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice_id)) } @@ -147,7 +147,7 @@ impl Endpoint for ListInvoices { type Response = InvoiceList; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Borrowed("/v2/invoicing/invoices") } @@ -187,7 +187,7 @@ impl Endpoint for DeleteInvoice { type Response = (); - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice_id)) } @@ -230,7 +230,7 @@ impl Endpoint for UpdateInvoice { type Response = Invoice; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/invoicing/invoices/{}", self.invoice.id)) } @@ -273,7 +273,7 @@ impl Endpoint for CancelInvoice { type Response = (); - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/invoicing/invoices/{}/cancel", self.invoice_id)) } @@ -312,7 +312,7 @@ impl Endpoint for SendInvoice { type Response = (); - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/invoicing/invoices/{}/send", self.invoice_id)) } diff --git a/src/api/orders.rs b/src/api/orders.rs index bd0979d..50cb781 100644 --- a/src/api/orders.rs +++ b/src/api/orders.rs @@ -33,7 +33,7 @@ impl Endpoint for CreateOrder { type Response = Order; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Borrowed("/v2/checkout/orders") } @@ -69,7 +69,7 @@ impl Endpoint for ShowOrderDetails { type Response = Order; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/checkout/orders/{}", self.order_id)) } @@ -132,7 +132,7 @@ impl Endpoint for CaptureOrder { type Response = Order; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/checkout/orders/{}/capture", self.order_id)) } @@ -173,7 +173,7 @@ impl Endpoint for AuthorizeOrder { type Response = Order; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/checkout/orders/{}/authorize", self.order_id)) } diff --git a/src/api/payments.rs b/src/api/payments.rs index 8e1b05b..ce2889a 100644 --- a/src/api/payments.rs +++ b/src/api/payments.rs @@ -35,7 +35,7 @@ impl Endpoint for GetAuthorizedPayment { type Response = AuthorizedPaymentDetails; - fn relative_path(&self) -> Cow { + fn relative_path(&self) -> Cow<'_, str> { Cow::Owned(format!("/v2/payments/authorizations/{}", self.authorization_id)) } diff --git a/src/data/invoice.rs b/src/data/invoice.rs index 75521bd..26f2c8a 100644 --- a/src/data/invoice.rs +++ b/src/data/invoice.rs @@ -412,7 +412,7 @@ pub enum PaymentType { } /// The payment mode or method through which the invoicer can accept the payment. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PaymentMethod { /// Payments can be received through bank transfers. @@ -426,6 +426,7 @@ pub enum PaymentMethod { /// Payments can be received through debit card payments. DebitCard, /// Payments can be received through paypal payments. + #[default] Paypal, /// Payments can be received through wire transfer. WireTransfer, @@ -433,12 +434,6 @@ pub enum PaymentMethod { Other, } -impl Default for PaymentMethod { - fn default() -> Self { - PaymentMethod::Paypal - } -} - /// Payment detail #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Builder)] diff --git a/src/data/orders.rs b/src/data/orders.rs index bd0e7b7..7118b32 100644 --- a/src/data/orders.rs +++ b/src/data/orders.rs @@ -6,10 +6,11 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; /// The intent to either capture payment immediately or authorize a payment for an order after order creation. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum Intent { /// The merchant intends to capture payment immediately after the customer makes a payment. + #[default] Capture, /// The merchant intends to authorize a payment and place funds on hold after the customer makes a payment. /// Authorized payments are guaranteed for up to three days but are available to capture for up to 29 days. @@ -19,12 +20,6 @@ pub enum Intent { Authorize, } -impl Default for Intent { - fn default() -> Self { - Intent::Capture - } -} - /// Represents a payer name. /// /// @@ -197,9 +192,10 @@ pub struct PlatformFee { } /// The funds that are held on behalf of the merchant -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Default)] pub enum DisbursementMode { /// The funds are released to the merchant immediately. + #[default] Instant, /// The funds are held for a finite number of days. The actual duration depends on the region and type of integration. /// You can release the funds through a referenced payout. @@ -207,12 +203,6 @@ pub enum DisbursementMode { Delayed, } -impl Default for DisbursementMode { - fn default() -> Self { - DisbursementMode::Instant - } -} - /// Any additional payment instructions for PayPal Commerce Platform customers. #[skip_serializing_none] #[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)] @@ -225,12 +215,13 @@ pub struct PaymentInstruction { } /// The item category type. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum ItemCategoryType { /// Goods that are stored, delivered, and used in their electronic format. /// This value is not currently supported for API callers that leverage /// the [PayPal for Commerce Platform](https://www.paypal.com/us/webapps/mpp/commerce-platform) product. + #[default] DigitalGoods, /// A tangible item that can be shipped with proof of delivery. PhysicalGoods, @@ -239,12 +230,6 @@ pub enum ItemCategoryType { Donation, } -impl Default for ItemCategoryType { - fn default() -> Self { - ItemCategoryType::DigitalGoods - } -} - /// The name of the person to whom to ship the items. #[skip_serializing_none] #[derive(Debug, Default, Serialize, Deserialize, Clone)] @@ -549,7 +534,7 @@ impl PurchaseUnit { } /// The type of landing page to show on the PayPal site for customer checkout. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum LandingPage { /// When the customer clicks PayPal Checkout, the customer is redirected to a page to log in to PayPal and approve the payment. @@ -560,20 +545,16 @@ pub enum LandingPage { /// When the customer clicks PayPal Checkout, the customer is redirected to either a page to log in to PayPal and approve /// the payment or to a page to enter credit or debit card and other relevant billing information required to complete the purchase, /// depending on their previous interaction with PayPal. + #[default] NoPreference, } -impl Default for LandingPage { - fn default() -> Self { - LandingPage::NoPreference - } -} - /// The shipping preference -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum ShippingPreference { /// Use the customer-provided shipping address on the PayPal site. + #[default] GetFromFile, /// Redact the shipping address from the PayPal site. Recommended for digital goods. NoShipping, @@ -581,19 +562,14 @@ pub enum ShippingPreference { SetProvidedAddress, } -impl Default for ShippingPreference { - fn default() -> Self { - ShippingPreference::GetFromFile - } -} - /// Configures a Continue or Pay Now checkout flow. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum UserAction { /// After you redirect the customer to the PayPal payment page, a Continue button appears. Use this option when /// the final amount is not known when the checkout flow is initiated and you want to redirect the customer /// to the merchant page without processing the payment. + #[default] Continue, /// After you redirect the customer to the PayPal payment page, a Pay Now button appears. /// Use this option when the final amount is known when the checkout is initiated and you want to @@ -601,17 +577,12 @@ pub enum UserAction { PayNow, } -impl Default for UserAction { - fn default() -> Self { - UserAction::Continue - } -} - /// The merchant-preferred payment sources. -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Default)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PayeePreferred { /// Accepts any type of payment from the customer. + #[default] Unrestricted, /// Accepts only immediate payment from the customer. /// For example, credit card, PayPal balance, or instant ACH. @@ -619,12 +590,6 @@ pub enum PayeePreferred { ImmediatePaymentRequired, } -impl Default for PayeePreferred { - fn default() -> Self { - PayeePreferred::Unrestricted - } -} - /// A payment method. #[skip_serializing_none] #[derive(Debug, Default, Serialize, Deserialize, Clone)] diff --git a/src/endpoint.rs b/src/endpoint.rs index 3ff8560..c53d28f 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -13,7 +13,7 @@ pub trait Endpoint { type Response: DeserializeOwned; /// The endpoint relative path. Must start with a `/` - fn relative_path(&self) -> Cow; + fn relative_path(&self) -> Cow<'_, str>; /// The request method of this endpoint. fn method(&self) -> reqwest::Method;