paypal_rust/resources/purchase_unit_request.rs
1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::resources::amount_with_breakdown::AmountWithBreakdown;
5use crate::resources::item::Item;
6use crate::resources::payee::Payee;
7use crate::resources::payment_instruction::PaymentInstruction;
8use crate::resources::shipping_detail::ShippingDetail;
9
10#[skip_serializing_none]
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
12pub struct PurchaseUnitRequest {
13 /// The API caller-provided external ID for the purchase unit.
14 /// Required for multiple purchase units when you must update the order through PATCH.
15 /// If you omit this value and the order contains only one purchase unit, PayPal sets this value to default.
16 pub reference_ids: Option<String>,
17
18 /// The total order amount with an optional breakdown that provides details,
19 /// such as the total item amount, total tax amount, shipping, handling,
20 /// insurance, and discounts, if any. If you specify amount.breakdown, the
21 /// amount equals `item_total plus tax_total plus shipping plus handling plus insurance minus shipping_discount minus discount.`
22 /// The amount must be a positive number. For listed of supported currencies
23 /// and decimal precision, see the PayPal REST APIs Currency Codes.
24 pub amount: AmountWithBreakdown,
25
26 /// The merchant who receives payment for this transaction.
27 pub payee: Option<Payee>,
28
29 /// Any additional payment instructions to be consider during payment processing.
30 /// This processing instruction is applicable for Capturing an order or Authorizing an Order.
31 pub payment_instruction: Option<PaymentInstruction>,
32
33 /// The purchase description.
34 pub description: Option<String>,
35
36 /// The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions.
37 /// Appears in transaction and settlement reports but is not visible to the payer.
38 pub custom_id: Option<String>,
39
40 /// The API caller-provided external invoice number for this order.
41 /// Appears in both the payer's transaction history and the emails that the payer receives.
42 pub invoice_id: Option<String>,
43
44 /// The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer's card statement.
45 ///
46 /// If an Order is paid using the "PayPal Wallet", the statement descriptor will appear in following format
47 /// on the payer's card statement: `PAYPAL_prefix+(space)+merchant_descriptor+(space)+ soft_descriptor`
48 ///
49 /// **Note:** The merchant descriptor is the descriptor of the merchant’s payment receiving preferences which can be seen by
50 /// logging into the merchant account https://www.sandbox.paypal.com/businessprofile/settings/info/edit
51 ///
52 /// The PAYPAL prefix uses 8 characters. Only the first 22 characters will be displayed in the statement.
53 /// For example, if:
54 /// The PayPal prefix toggle is PAYPAL .
55 /// The merchant descriptor in the profile is Janes Gift.
56 /// The soft descriptor is 800-123-1234.
57 /// Then, the statement descriptor on the card is PAYPAL Janes Gift 80.
58 pub soft_descriptor: Option<String>,
59
60 /// An array of items that the customer purchases from the merchant.
61 pub items: Vec<Item>,
62
63 /// The name and address of the person to whom to ship the items.
64 pub shipping: Option<ShippingDetail>,
65}
66
67impl PurchaseUnitRequest {
68 #[must_use]
69 pub const fn new(amount: AmountWithBreakdown) -> Self {
70 Self {
71 amount,
72 items: Vec::new(),
73 reference_ids: None,
74 payee: None,
75 payment_instruction: None,
76 description: None,
77 custom_id: None,
78 invoice_id: None,
79 soft_descriptor: None,
80 shipping: None,
81 }
82 }
83
84 pub fn reference_ids(&mut self, reference_ids: String) -> &mut Self {
85 self.reference_ids = Some(reference_ids);
86 self
87 }
88
89 pub fn amount(&mut self, amount: AmountWithBreakdown) -> &mut Self {
90 self.amount = amount;
91 self
92 }
93
94 pub fn payee(&mut self, payee: Payee) -> &mut Self {
95 self.payee = Some(payee);
96 self
97 }
98
99 pub fn payment_instruction(&mut self, payment_instruction: PaymentInstruction) -> &mut Self {
100 self.payment_instruction = Some(payment_instruction);
101 self
102 }
103
104 pub fn description(&mut self, description: String) -> &mut Self {
105 self.description = Some(description);
106 self
107 }
108
109 pub fn custom_id(&mut self, custom_id: String) -> &mut Self {
110 self.custom_id = Some(custom_id);
111 self
112 }
113
114 pub fn invoice_id(&mut self, invoice_id: String) -> &mut Self {
115 self.invoice_id = Some(invoice_id);
116 self
117 }
118
119 pub fn soft_descriptor(&mut self, soft_descriptor: String) -> &mut Self {
120 self.soft_descriptor = Some(soft_descriptor);
121 self
122 }
123
124 pub fn items(&mut self, items: Vec<Item>) -> &mut Self {
125 self.items = items;
126 self
127 }
128
129 pub fn shipping(&mut self, shipping: ShippingDetail) -> &mut Self {
130 self.shipping = Some(shipping);
131 self
132 }
133}