paypal_rs/data/
orders.rs

1//! Paypal object definitions used by the orders api.
2
3use super::common::*;
4use derive_builder::Builder;
5use serde::{Deserialize, Serialize};
6use serde_with::skip_serializing_none;
7
8/// The intent to either capture payment immediately or authorize a payment for an order after order creation.
9#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
10#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
11pub enum Intent {
12    /// The merchant intends to capture payment immediately after the customer makes a payment.
13    Capture,
14    /// The merchant intends to authorize a payment and place funds on hold after the customer makes a payment.
15    /// Authorized payments are guaranteed for up to three days but are available to capture for up to 29 days.
16    /// After the three-day honor period, the original authorized payment expires and you must re-authorize the payment.
17    /// You must make a separate request to capture payments on demand.
18    /// This intent is not supported when you have more than one `purchase_unit` within your order.
19    Authorize,
20}
21
22impl Default for Intent {
23    fn default() -> Self {
24        Intent::Capture
25    }
26}
27
28/// Represents a payer name.
29///
30/// <https://developer.paypal.com/docs/api/orders/v2/#definition-payer.name>
31#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Builder)]
32pub struct PayerName {
33    /// When the party is a person, the party's given, or first, name.
34    pub given_name: String,
35    /// When the party is a person, the party's surname or family name. Also known as the last name.
36    /// Required when the party is a person. Use also to store multiple surnames including the matronymic, or mother's, surname.
37    pub surname: String,
38}
39
40/// The phone number, in its canonical international E.164 numbering plan format.
41#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Builder)]
42#[builder(setter(strip_option))]
43pub struct PhoneNumber {
44    /// The national number, in its canonical international E.164 numbering plan format.
45    /// The combined length of the country calling code (CC) and the national number must not be greater than 15 digits.
46    /// The national number consists of a national destination code (NDC) and subscriber number (SN).
47    pub national_number: String,
48}
49
50/// The phone number of the customer. Available only when you enable the
51/// Contact Telephone Number option in the Profile & Settings for the merchant's PayPal account.
52#[skip_serializing_none]
53#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
54#[builder(setter(strip_option))]
55pub struct Phone {
56    /// The phone type.
57    pub phone_type: Option<PhoneType>,
58    /// The phone number
59    pub phone_number: PhoneNumber,
60}
61
62/// The customer's tax ID type. Supported for the PayPal payment method only.
63#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
64#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
65#[allow(non_camel_case_types)]
66pub enum TaxIdType {
67    /// The individual tax ID type.
68    BR_CPF,
69    /// The business tax ID type.
70    BR_CNPJ,
71}
72
73/// The tax information of the payer.
74#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
75#[builder(setter(strip_option))]
76pub struct TaxInfo {
77    /// The customer's tax ID. Supported for the PayPal payment method only.
78    /// Typically, the tax ID is 11 characters long for individuals and 14 characters long for businesses.
79    pub tax_id: String,
80    /// The customer's tax ID type. Supported for the PayPal payment method only.
81    pub tax_id_type: TaxIdType,
82}
83
84/// The customer who approves and pays for the order. The customer is also known as the payer.
85///
86/// <https://developer.paypal.com/docs/api/orders/v2/#definition-payer>
87#[skip_serializing_none]
88#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
89#[builder(setter(strip_option), default)]
90pub struct Payer {
91    /// The name of the payer.
92    pub name: Option<PayerName>,
93    /// The email address of the payer.
94    pub email_address: Option<String>,
95    /// The PayPal-assigned ID for the payer.
96    pub payer_id: Option<String>,
97    /// The phone number of the customer. Available only when you enable the Contact
98    /// Telephone Number option in the Profile & Settings for the merchant's PayPal account.
99    pub phone: Option<Phone>,
100    /// The birth date of the payer in YYYY-MM-DD format.
101    pub birth_date: Option<String>,
102    /// The tax information of the payer. Required only for Brazilian payer's.
103    pub tax_info: Option<TaxInfo>,
104    /// The address of the payer.
105    pub address: Option<Address>,
106}
107
108/// Breakdown provides details such as total item amount, total tax amount, shipping, handling, insurance, and discounts, if any.
109#[skip_serializing_none]
110#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
111#[builder(setter(strip_option, into))]
112pub struct Breakdown {
113    /// The subtotal for all items. Required if the request includes purchase_units[].items[].unit_amount.
114    /// Must equal the sum of (items[].unit_amount * items[].quantity) for all items.
115    pub item_total: Option<Money>,
116    /// The shipping fee for all items within a given purchase_unit.
117    pub shipping: Option<Money>,
118    /// The handling fee for all items within a given purchase_unit.
119    pub handling: Option<Money>,
120    /// The total tax for all items. Required if the request includes purchase_units.items.tax. Must equal the sum of (items[].tax * items[].quantity) for all items.
121    pub tax_total: Option<Money>,
122    /// The insurance fee for all items within a given purchase_unit.
123    pub insurance: Option<Money>,
124    /// The shipping discount for all items within a given purchase_unit.
125    pub shipping_discount: Option<Money>,
126    /// The discount for all items within a given purchase_unit.
127    pub discount: Option<Money>,
128}
129
130/// Represents an amount of money.
131#[skip_serializing_none]
132#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
133#[builder(setter(strip_option))]
134pub struct Amount {
135    /// The [three-character ISO-4217 currency code](https://developer.paypal.com/docs/integration/direct/rest/currency-codes/) that identifies the currency.
136    pub currency_code: Currency,
137    /// The value, which might be:
138    /// - An integer for currencies like JPY that are not typically fractional.
139    /// - A decimal fraction for currencies like TND that are subdivided into thousandths.
140    ///
141    /// For the required number of decimal places for a currency code, see [Currency Codes](https://developer.paypal.com/docs/api/reference/currency-codes/).
142    pub value: String,
143    /// The breakdown of the amount.
144    pub breakdown: Option<Breakdown>,
145}
146
147impl Amount {
148    /// Creates a new amount with the required values.
149    pub fn new(currency: Currency, value: &str) -> Self {
150        Amount {
151            currency_code: currency,
152            value: value.to_owned(),
153            breakdown: None,
154        }
155    }
156
157    /// Creates a new amount with the EUR currency.
158    pub fn eur(value: &str) -> Self {
159        Amount {
160            currency_code: Currency::EUR,
161            value: value.to_owned(),
162            breakdown: None,
163        }
164    }
165
166    /// Creates a new amount with the USD currency.
167    pub fn usd(value: &str) -> Self {
168        Amount {
169            currency_code: Currency::USD,
170            value: value.to_owned(),
171            breakdown: None,
172        }
173    }
174}
175
176/// The merchant who receives payment for this transaction.
177#[skip_serializing_none]
178#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
179#[builder(setter(strip_option, into))]
180pub struct Payee {
181    /// The email address of merchant.
182    pub email_address: Option<String>,
183    /// The encrypted PayPal account ID of the merchant.
184    pub merchant_id: Option<String>,
185}
186
187/// Fees, commissions, tips, or donations
188#[skip_serializing_none]
189#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
190#[builder(setter(strip_option))]
191pub struct PlatformFee {
192    /// The fee for this transaction.
193    pub amount: Money,
194
195    /// The merchant who receives payment for this transaction.
196    pub payee: Option<Payee>,
197}
198
199/// The funds that are held on behalf of the merchant
200#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
201pub enum DisbursementMode {
202    /// The funds are released to the merchant immediately.
203    Instant,
204    /// The funds are held for a finite number of days. The actual duration depends on the region and type of integration.
205    /// You can release the funds through a referenced payout.
206    /// Otherwise, the funds disbursed automatically after the specified duration.
207    Delayed,
208}
209
210impl Default for DisbursementMode {
211    fn default() -> Self {
212        DisbursementMode::Instant
213    }
214}
215
216/// Any additional payment instructions for PayPal Commerce Platform customers.
217#[skip_serializing_none]
218#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
219#[builder(setter(strip_option, into))]
220pub struct PaymentInstruction {
221    /// An array of various fees, commissions, tips, or donations.
222    pub platform_fees: Option<Vec<PlatformFee>>,
223    /// The funds that are held on behalf of the merchant.
224    pub disbursement_mode: Option<DisbursementMode>,
225}
226
227/// The item category type.
228#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
229#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
230pub enum ItemCategoryType {
231    /// Goods that are stored, delivered, and used in their electronic format.
232    /// This value is not currently supported for API callers that leverage
233    /// the [PayPal for Commerce Platform](https://www.paypal.com/us/webapps/mpp/commerce-platform) product.
234    DigitalGoods,
235    /// A tangible item that can be shipped with proof of delivery.
236    PhysicalGoods,
237
238    /// A contribution or gift for which no good or service is exchanged, usually to a not for profit organization.
239    Donation,
240}
241
242impl Default for ItemCategoryType {
243    fn default() -> Self {
244        ItemCategoryType::DigitalGoods
245    }
246}
247
248/// The name of the person to whom to ship the items.
249#[skip_serializing_none]
250#[derive(Debug, Default, Serialize, Deserialize, Clone)]
251pub struct ShippingDetailName {
252    /// The name of the person to whom to ship the items. Supports only the full_name property.
253    pub full_name: String,
254}
255
256/// The name and address of the person to whom to ship the items.
257#[skip_serializing_none]
258#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
259#[builder(setter(strip_option))]
260pub struct ShippingDetail {
261    /// The name of the person to whom to ship the items. Supports only the full_name property.
262    pub name: Option<ShippingDetailName>,
263    /// The address of the person to whom to ship the items.
264    pub address: Option<Address>,
265}
266
267/// Represents an item.
268#[skip_serializing_none]
269#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
270#[builder(setter(strip_option, into))]
271pub struct Item {
272    /// The item name or title.
273    pub name: String,
274    /// The item price or rate per unit.
275    /// If you specify unit_amount, purchase_units[].amount.breakdown.item_total is required. Must equal unit_amount * quantity for all items.
276    pub unit_amount: Money,
277    /// The item tax for each unit. If tax is specified, purchase_units[].amount.breakdown.tax_total is required. Must equal tax * quantity for all items.
278    pub tax: Option<Money>,
279    /// The item quantity. Must be a whole number.
280    pub quantity: String,
281    /// The detailed item description.
282    pub description: Option<String>,
283    /// The stock keeping unit (SKU) for the item.
284    pub sku: Option<String>,
285    /// The item category type
286    pub category: Option<ItemCategoryType>,
287}
288
289/// The status of the payment authorization.
290#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
291#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
292pub enum AuthorizationStatus {
293    /// The authorized payment is created. No captured payments have been made for this authorized payment.
294    Created,
295    /// The authorized payment has one or more captures against it. The sum of these captured payments is greater than the amount of the original authorized payment.
296    Captured,
297    /// PayPal cannot authorize funds for this authorized payment.
298    Denied,
299    /// The authorized payment has expired.
300    Expired,
301    /// A captured payment was made for the authorized payment for an amount that is less than the amount of the original authorized payment.
302    PartiallyExpired,
303    /// The payment which was authorized for an amount that is less than the originally requested amount.
304    PartiallyCaptured,
305    /// The authorized payment was voided. No more captured payments can be made against this authorized payment.
306    Voided,
307    /// The created authorization is in pending state. For more information, see status.details.
308    Pending,
309}
310
311/// A payment authorization.
312#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
313pub struct AuthorizationWithData {
314    /// The status for the authorized payment.
315    pub status: AuthorizationStatus,
316    /// The details of the authorized order pending status.
317    pub status_details: AuthorizationStatusDetails,
318}
319
320/// The capture status.
321#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
322#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
323pub enum CaptureStatus {
324    /// The funds for this captured payment were credited to the payee's PayPal account.
325    Completed,
326    ///  The funds could not be captured.
327    Declined,
328    /// An amount less than this captured payment's amount was partially refunded to the payer.
329    PartiallyRefunded,
330    /// The funds for this captured payment was not yet credited to the payee's PayPal account. For more information, see status.details.
331    Pending,
332    /// An amount greater than or equal to this captured payment's amount was refunded to the payer.
333    Refunded,
334}
335
336/// Capture status reason.
337#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
338#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
339pub enum CaptureStatusDetailsReason {
340    /// The payer initiated a dispute for this captured payment with PayPal.
341    BuyerComplaint,
342    /// The captured funds were reversed in response to the payer disputing this captured payment with
343    /// the issuer of the financial instrument used to pay for this captured payment.
344    Chargeback,
345    /// The payer paid by an eCheck that has not yet cleared.
346    Echeck,
347    /// Visit your online account. In your **Account Overview**, accept and deny this payment.
348    InternationalWithdrawal,
349    /// No additional specific reason can be provided. For more information about this captured payment, visit your account online or contact PayPal.
350    Other,
351    /// The captured payment is pending manual review.
352    PendingReview,
353    /// The payee has not yet set up appropriate receiving preferences for their account.
354    /// For more information about how to accept or deny this payment, visit your account online.
355    /// This reason is typically offered in scenarios such as when the currency of the captured
356    /// payment is different from the primary holding currency of the payee.
357    ReceivingPreferenceMandatesManualAction,
358    /// The captured funds were refunded.
359    Refunded,
360    /// The payer must send the funds for this captured payment. This code generally appears for manual EFTs.
361    TransactionApprovedAwaitingFunding,
362    /// The payee does not have a PayPal account.
363    Unilateral,
364    /// The payee's PayPal account is not verified.
365    VerificationRequired,
366}
367
368/// Details about the captured payment status.
369#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
370pub struct CaptureStatusDetails {
371    /// The reason why the captured payment status is PENDING or DENIED.
372    pub reason: CaptureStatusDetailsReason,
373}
374
375/// A captured payment.
376#[skip_serializing_none]
377#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone, Builder)]
378#[builder(setter(strip_option))]
379pub struct Capture {
380    /// The status of the captured payment.
381    pub status: CaptureStatus,
382    /// The details of the captured payment status.
383    pub status_details: Option<CaptureStatusDetails>,
384}
385
386/// The status of the refund
387#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
388#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
389pub enum RefundStatus {
390    /// The refund was cancelled.
391    Cancelled,
392    /// The refund is pending. For more information, see status_details.reason.
393    Pending,
394    /// The funds for this transaction were debited to the customer's account.
395    Completed,
396}
397
398/// Refund status reason.
399#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
400#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
401pub enum RefundStatusDetailsReason {
402    /// The customer's account is funded through an eCheck, which has not yet cleared.
403    Echeck,
404}
405
406/// Details about the status of the refund.
407#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
408pub struct RefundStatusDetails {
409    /// The reason why the refund has the PENDING or FAILED status.
410    pub reason: RefundStatusDetailsReason,
411}
412
413/// Exchange rate.
414#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
415pub struct ExchangeRate {
416    /// The source currency from which to convert an amount.
417    pub source_currency: Currency,
418    /// The target currency to which to convert an amount.
419    pub target_currency: Currency,
420    /// The target currency amount. Equivalent to one unit of the source currency. Formatted as integer or decimal value with one to 15 digits to the right of the decimal point.
421    pub value: String,
422}
423
424/// The net breakdown of the refund.
425#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
426pub struct NetAmountBreakdown {
427    /// The converted payable amount.
428    pub converted_amount: Money,
429    /// The exchange rate that determines the amount that was debited from the merchant's PayPal account.
430    pub exchange_rate: ExchangeRate,
431    /// The net amount debited from the merchant's PayPal account.
432    pub payable_amount: Money,
433}
434
435/// The breakdown of the refund.
436#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
437#[builder(setter(strip_option))]
438pub struct SellerPayableBreakdown {
439    /// The amount that the payee refunded to the payer.
440    pub gross_amount: Money,
441    /// The net amount that the payee's account is debited in the transaction currency. The net amount is calculated as gross_amount minus paypal_fee minus platform_fees.
442    pub net_amount: Money,
443    /// An array of breakdown values for the net amount. Returned when the currency of the refund is different from the currency of the PayPal account where the payee holds their funds.
444    pub net_amount_breakdown: Option<Vec<NetAmountBreakdown>>,
445    /// The net amount that the payee's account is debited in the receivable currency. Returned only in cases when the receivable currency is different from transaction currency. Example 'CNY'.
446    pub net_amount_in_receivable_currency: Option<Money>,
447    /// The PayPal fee that was refunded to the payer in the currency of the transaction. This fee might not match the PayPal fee that the payee paid when the payment was captured.
448    pub paypal_fee: Money,
449    /// The PayPal fee that was refunded to the payer in the receivable currency. Returned only in cases when the receivable currency is different from transaction currency. Example 'CNY'.
450    pub paypal_fee_in_receivable_currency: Option<Money>,
451    /// An array of platform or partner fees, commissions, or brokerage fees for the refund.
452    pub platform_fees: Option<Vec<PlatformFee>>,
453    /// The total amount refunded from the original capture to date. For example, if a payer makes a $100 purchase and was refunded $20 a week ago and was refunded $30 in this refund, the gross_amount is $30 for this refund and the total_refunded_amount is $50.
454    pub total_refunded_amount: Money,
455}
456
457/// A refund
458#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
459#[builder(setter(strip_option))]
460pub struct Refund {
461    /// The status of the refund.
462    pub status: RefundStatus,
463    /// The details of the refund status.
464    pub status_details: Option<RefundStatusDetails>,
465    /// The PayPal-generated ID for the refund.
466    pub id: String,
467    /// The amount that the payee refunded to the payer.
468    pub amount: Money,
469    /// The API caller-provided external invoice number for this order. Appears in both the payer's transaction history and the emails that the payer receives.
470    pub invoice_id: Option<String>,
471    /// An array of related HATEOAS links.
472    pub links: Vec<LinkDescription>,
473    /// The reason for the refund. Appears in both the payer's transaction history and the emails that the payer receives.
474    pub note_to_payer: Option<String>,
475    /// The breakdown of the refund.
476    pub seller_payable_breakdown: SellerPayableBreakdown,
477}
478
479/// The comprehensive history of payments for the purchase unit.
480#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
481#[builder(setter(strip_option))]
482pub struct PaymentCollection {
483    /// An array of authorized payments for a purchase unit. A purchase unit can have zero or more authorized payments.
484    #[serde(default)]
485    pub authorizations: Vec<AuthorizationWithData>,
486    /// An array of captured payments for a purchase unit. A purchase unit can have zero or more captured payments.
487    #[serde(default)]
488    pub captures: Vec<Capture>,
489    /// An array of refunds for a purchase unit. A purchase unit can have zero or more refunds.
490    #[serde(default)]
491    pub refunds: Vec<Refund>,
492}
493
494/// Represents either a full or partial order that the payer intends to purchase from the payee.
495#[skip_serializing_none]
496#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
497#[builder(setter(strip_option, into), default)]
498pub struct PurchaseUnit {
499    /// The API caller-provided external ID for the purchase unit. Required for multiple purchase units when you must update the order through PATCH.
500    /// If you omit this value and the order contains only one purchase unit, PayPal sets this value to default.
501    pub reference_id: Option<String>,
502    /// The total order amount with an optional breakdown that provides details, such as the total item amount,
503    /// total tax amount, shipping, handling, insurance, and discounts, if any.
504    ///
505    /// If you specify amount.breakdown, the amount equals item_total plus tax_total plus shipping plus handling plus insurance minus shipping_discount minus discount.
506    ///
507    /// The amount must be a positive number. For listed of supported currencies and decimal precision,
508    /// see the PayPal REST APIs [Currency Codes](https://developer.paypal.com/docs/integration/direct/rest/currency-codes/).
509    pub amount: Amount,
510    /// The merchant who receives payment for this transaction.
511    pub payee: Option<Payee>,
512    /// Any additional payment instructions for PayPal Commerce Platform customers.
513    /// Enables features for the PayPal Commerce Platform, such as delayed disbursement and collection of a platform fee.
514    /// Applies during order creation for captured payments or during capture of authorized payments.
515    pub payment_instruction: Option<PaymentInstruction>,
516    /// The purchase description.
517    pub description: Option<String>,
518    /// The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions.
519    /// Appears in transaction and settlement reports but is not visible to the payer.
520    pub custom_id: Option<String>,
521    /// The API caller-provided external invoice number for this order.
522    /// Appears in both the payer's transaction history and the emails that the payer receives.
523    pub invoice_id: Option<String>,
524    /// The PayPal-generated ID for the purchase unit.
525    /// This ID appears in both the payer's transaction history and the emails that the payer receives.
526    /// In addition, this ID is available in transaction and settlement reports that merchants and API callers can use to reconcile transactions.
527    /// This ID is only available when an order is saved by calling v2/checkout/orders/id/save.
528    pub id: Option<String>,
529    /// The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer's card statement.
530    ///
531    /// More info here: <https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request>
532    pub soft_descriptor: Option<String>,
533    /// An array of items that the customer purchases from the merchant.
534    pub items: Option<Vec<Item>>,
535    /// The name and address of the person to whom to ship the items.
536    pub shipping: Option<ShippingDetail>,
537    /// The comprehensive history of payments for the purchase unit.
538    pub payments: Option<PaymentCollection>,
539}
540
541impl PurchaseUnit {
542    /// Creates a new PurchaseUnit with the required properties.
543    pub fn new(amount: Amount) -> Self {
544        Self {
545            amount,
546            ..Default::default()
547        }
548    }
549}
550
551/// The type of landing page to show on the PayPal site for customer checkout.
552#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
553#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
554pub enum LandingPage {
555    /// When the customer clicks PayPal Checkout, the customer is redirected to a page to log in to PayPal and approve the payment.
556    Login,
557    /// When the customer clicks PayPal Checkout, the customer is redirected to a page
558    /// to enter credit or debit card and other relevant billing information required to complete the purchase.
559    Billing,
560    /// When the customer clicks PayPal Checkout, the customer is redirected to either a page to log in to PayPal and approve
561    /// the payment or to a page to enter credit or debit card and other relevant billing information required to complete the purchase,
562    /// depending on their previous interaction with PayPal.
563    NoPreference,
564}
565
566impl Default for LandingPage {
567    fn default() -> Self {
568        LandingPage::NoPreference
569    }
570}
571
572/// The shipping preference
573#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
574#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
575pub enum ShippingPreference {
576    /// Use the customer-provided shipping address on the PayPal site.
577    GetFromFile,
578    /// Redact the shipping address from the PayPal site. Recommended for digital goods.
579    NoShipping,
580    ///  Use the merchant-provided address. The customer cannot change this address on the PayPal site.
581    SetProvidedAddress,
582}
583
584impl Default for ShippingPreference {
585    fn default() -> Self {
586        ShippingPreference::GetFromFile
587    }
588}
589
590/// Configures a Continue or Pay Now checkout flow.
591#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
592#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
593pub enum UserAction {
594    /// After you redirect the customer to the PayPal payment page, a Continue button appears. Use this option when
595    /// the final amount is not known when the checkout flow is initiated and you want to redirect the customer
596    /// to the merchant page without processing the payment.
597    Continue,
598    /// After you redirect the customer to the PayPal payment page, a Pay Now button appears.
599    /// Use this option when the final amount is known when the checkout is initiated and you want to
600    /// process the payment immediately when the customer clicks Pay Now.
601    PayNow,
602}
603
604impl Default for UserAction {
605    fn default() -> Self {
606        UserAction::Continue
607    }
608}
609
610/// The merchant-preferred payment sources.
611#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
612#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
613pub enum PayeePreferred {
614    /// Accepts any type of payment from the customer.
615    Unrestricted,
616    /// Accepts only immediate payment from the customer.
617    /// For example, credit card, PayPal balance, or instant ACH.
618    /// Ensures that at the time of capture, the payment does not have the `pending` status.
619    ImmediatePaymentRequired,
620}
621
622impl Default for PayeePreferred {
623    fn default() -> Self {
624        PayeePreferred::Unrestricted
625    }
626}
627
628/// A payment method.
629#[skip_serializing_none]
630#[derive(Debug, Default, Serialize, Deserialize, Clone)]
631pub struct PaymentMethod {
632    /// The customer-selected payment method on the merchant site.
633    pub payer_selected: Option<String>,
634    /// The merchant-preferred payment sources.
635    pub payee_preferred: Option<PayeePreferred>,
636}
637
638/// Customize the payer experience during the approval process for the payment with PayPal.
639#[skip_serializing_none]
640#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
641#[builder(setter(strip_option, into), default)]
642pub struct ApplicationContext {
643    /// The label that overrides the business name in the PayPal account on the PayPal site.
644    pub brand_name: Option<String>,
645    /// The BCP 47-formatted locale of pages that the PayPal payment experience shows. PayPal supports a five-character code.
646    ///
647    /// For example, da-DK, he-IL, id-ID, ja-JP, no-NO, pt-BR, ru-RU, sv-SE, th-TH, zh-CN, zh-HK, or zh-TW.
648    pub locale: Option<String>,
649    /// The type of landing page to show on the PayPal site for customer checkout
650    pub landing_page: Option<LandingPage>,
651    /// The shipping preference
652    pub shipping_preference: Option<ShippingPreference>,
653    /// Configures a Continue or Pay Now checkout flow.
654    pub user_action: Option<UserAction>,
655    /// The customer and merchant payment preferences.
656    pub payment_method: Option<PaymentMethod>,
657    /// The URL where the customer is redirected after the customer approves the payment.
658    pub return_url: Option<String>,
659    /// The URL where the customer is redirected after the customer cancels the payment.
660    pub cancel_url: Option<String>,
661}
662
663/// A card used in payment sources.
664#[skip_serializing_none]
665#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
666#[builder(setter(into))]
667pub struct PaymentCard {
668    /// The card number.
669    pub number: String,
670    /// The expiry date.
671    pub expiry: String,
672    /// The card owner name.
673    pub name: String,
674    /// The billing address.
675    pub billing_address: Address,
676}
677
678/// A transaction reference.
679#[skip_serializing_none]
680#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
681#[builder(setter(into))]
682pub struct TransactionReference {
683    /// The transaction id.
684    pub id: String,
685    /// The transaction network, e.g "VISA"
686    pub network: String,
687}
688
689/// A stored credential.
690#[skip_serializing_none]
691#[derive(Debug, Default, Serialize, Deserialize, Clone, Builder)]
692#[builder(setter(into))]
693pub struct StoredCredential {
694    /// The payment initiator, e.g "MERCHANT"
695    pub payment_initiator: String,
696    /// The payment type, e.g "RECURRING"
697    pub payment_type: String,
698    /// The stored credential usage, e.g: SUBSEQUENT
699    pub usage: String,
700    /// The billing address.
701    pub previous_network_transaction_reference: TransactionReference,
702}
703
704/// A order payload to be used when creating an order.
705// TODO: this only appears in the example body, not documented.
706// https://developer.paypal.com/docs/api/orders/v2/#orders_create
707#[skip_serializing_none]
708#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
709#[builder(setter(strip_option))]
710pub struct OrderPaymentSource {
711    /// The card used in the payment.
712    pub card: PaymentCard,
713    /// A stored credential.
714    // TODO: figure out what is this.
715    #[builder(default)]
716    pub stored_credential: Option<StoredCredential>,
717}
718
719/// A order payload to be used when creating an order.
720#[skip_serializing_none]
721#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
722#[builder(setter(strip_option))]
723pub struct OrderPayload {
724    /// The intent to either capture payment immediately or authorize a payment for an order after order creation.
725    pub intent: Intent,
726    /// DEPRECATED. The customer who approves and pays for the order. The customer is also known as the payer.
727    #[builder(default)]
728    pub payer: Option<Payer>,
729    /// An array of purchase units. Each purchase unit establishes a contract between a payer and the payee.
730    /// Each purchase unit represents either a full or partial order that the payer intends to purchase from the payee.
731    pub purchase_units: Vec<PurchaseUnit>,
732    /// Customize the payer experience during the approval process for the payment with PayPal.
733    #[builder(default)]
734    pub application_context: Option<ApplicationContext>,
735    /// The payment source.
736    #[builder(default)]
737    pub payment_source: Option<OrderPaymentSource>,
738}
739
740/// The card brand or network.
741#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
742#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
743pub enum CardBrand {
744    /// Visa card.
745    Visa,
746    /// Mastecard card.
747    Mastercard,
748    /// Discover card.
749    Discover,
750    /// American Express card.
751    Amex,
752    /// Solo debit card.
753    Solo,
754    /// Japan Credit Bureau card.
755    JCB,
756    /// Military Star card.
757    Star,
758    /// Delta Airlines card.
759    Delta,
760    /// Switch credit card.
761    Switch,
762    /// Maestro credit card.
763    Maestro,
764    /// Carte Bancaire (CB) credit card.
765    CbNationale,
766    /// Configoga credit card.
767    Configoga,
768    /// Confidis credit card.
769    Confidis,
770    /// Visa Electron credit card.
771    Electron,
772    /// Cetelem credit card.
773    Cetelem,
774    /// China union pay credit card.
775    ChinaUnionPay,
776}
777
778#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Copy)]
779#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
780#[allow(missing_docs)]
781pub enum CardType {
782    Credit,
783    Debit,
784    Prepaid,
785    Unknown,
786}
787
788/// The payment card to use to fund a payment.
789#[derive(Debug, Serialize, Deserialize, Clone)]
790pub struct CardResponse {
791    /// The last digits of the payment card.
792    pub last_digits: String,
793    /// The card brand or network.
794    pub brand: CardBrand,
795    /// The payment card type.
796    #[serde(rename = "type")]
797    pub card_type: CardType,
798}
799
800/// The customer's wallet used to fund the transaction.
801#[derive(Debug, Serialize, Deserialize, Clone)]
802pub struct WalletResponse {
803    /// Apple Pay Wallet response information.
804    pub apple_pay: CardResponse,
805}
806
807/// The paypal account used to fund the transaction.
808#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
809pub struct PaypalPaymentSourceResponse {
810    /// The name of the payer.
811    pub name: PayerName,
812    /// The email address of the payer.
813    pub email_address: String,
814    /// The account id of the payer.
815    pub account_id: String,
816}
817
818/// The payment source used to fund the payment.
819#[derive(Debug, Serialize, Deserialize, Builder, Default, Clone)]
820#[builder(setter(strip_option), default)]
821pub struct PaymentSourceResponse {
822    /// The payment card to use to fund a payment. Card can be a credit or debit card
823    pub card: Option<CardResponse>,
824    /// The customer's wallet used to fund the transaction.
825    pub wallet: Option<WalletResponse>,
826
827    /// The paypal account used to fund the transaction.
828    pub paypal: Option<PaypalPaymentSourceResponse>,
829}
830
831/// The status of an order.
832#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Copy)]
833#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
834pub enum OrderStatus {
835    /// The order was created with the specified context.
836    Created,
837    /// The order was saved and persisted. The order status continues to be in progress until a capture
838    /// is made with final_capture = true for all purchase units within the order.
839    Saved,
840    /// The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment. For example, a card, bank account, or so on.
841    Approved,
842    /// All purchase units in the order are voided.
843    Voided,
844    /// The payment was authorized or the authorized payment was captured for the order.
845    Completed,
846}
847
848/// An order represents a payment between two or more parties.
849#[skip_serializing_none]
850#[derive(Debug, Serialize, Deserialize, Clone, Builder)]
851#[builder(setter(strip_option))]
852pub struct Order {
853    /// The date and time when the transaction occurred.
854    pub create_time: Option<chrono::DateTime<chrono::Utc>>,
855    /// The date and time when the transaction was last updated.
856    pub update_time: Option<chrono::DateTime<chrono::Utc>>,
857    /// The ID of the order.
858    pub id: String,
859    /// The payment source used to fund the payment.
860    pub payment_source: Option<PaymentSourceResponse>,
861    /// The intent to either capture payment immediately or authorize a payment for an order after order creation.
862    pub intent: Option<Intent>,
863    /// The customer who approves and pays for the order. The customer is also known as the payer.
864    pub payer: Option<Payer>,
865    /// An array of purchase units. Each purchase unit establishes a contract between a customer and merchant.
866    /// Each purchase unit represents either a full or partial order that the customer intends to purchase from the merchant.
867    pub purchase_units: Option<Vec<PurchaseUnit>>,
868    /// The order status.
869    pub status: OrderStatus,
870    /// An array of request-related HATEOAS links. To complete payer approval, use the approve link to redirect the payer.
871    pub links: Vec<LinkDescription>,
872}
873
874/// An invoice number.
875#[derive(Debug, Serialize, Deserialize, Clone)]
876pub struct InvoiceNumber {
877    /// The invoice number.
878    pub invoice_number: String,
879}