paypal_rust/resources/
order_application_context.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::resources::enums::landing_page::LandingPage;
5use crate::resources::enums::shipping_preference::ShippingPreference;
6use crate::resources::enums::user_action::UserAction;
7use crate::resources::payment_method::PaymentMethod;
8use crate::resources::stored_payment_source::StoredPaymentSource;
9
10#[skip_serializing_none]
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
12pub struct OrderApplicationContext {
13    /// The label that overrides the business name in the PayPal account on the PayPal site.
14    pub brand_name: Option<String>,
15
16    /// The BCP 47-formatted locale of pages that the PayPal payment experience shows. PayPal supports a five-character code.
17    /// 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.
18    pub locale: Option<String>,
19
20    /// The type of landing page to show on the PayPal site for customer checkout.
21    pub landing_page: Option<LandingPage>,
22
23    /// The shipping preference:
24    ///  * Displays the shipping address to the customer.
25    ///  * Enables the customer to choose an address on the PayPal site.
26    ///  * Restricts the customer from changing the address during the payment-approval process.
27    pub shipping_preference: Option<ShippingPreference>,
28
29    /// Configures a Continue or Pay Now checkout flow.
30    pub user_action: Option<UserAction>,
31
32    ///The customer and merchant payment preferences.
33    pub payment_method: Option<PaymentMethod>,
34
35    /// The URL where the customer is redirected after the customer approves the payment.
36    pub return_url: Option<String>,
37
38    /// The URL where the customer is redirected after the customer cancels the payment.
39    pub cancel_url: Option<String>,
40
41    /**
42     * Provides additional details to process a payment using a payment_source that has been stored or is intended to be stored
43     * (also referred to as stored_credential or card-on-file).
44     *
45     * Parameter compatibility:
46     * payment_type=ONE_TIME is compatible only with payment_initiator=CUSTOMER.
47     * usage=FIRST is compatible only with payment_initiator=CUSTOMER.
48     * previous_transaction_reference or previous_network_transaction_reference is compatible only with payment_initiator=MERCHANT.
49     * Only one of the parameters - previous_transaction_reference and previous_network_transaction_reference - can be present in the
50     * request.
51     */
52    pub stored_payment_source: Option<StoredPaymentSource>,
53}
54
55impl OrderApplicationContext {
56    #[must_use]
57    pub const fn new() -> Self {
58        Self {
59            brand_name: None,
60            locale: None,
61            landing_page: None,
62            shipping_preference: None,
63            user_action: None,
64            payment_method: None,
65            return_url: None,
66            cancel_url: None,
67            stored_payment_source: None,
68        }
69    }
70
71    #[must_use]
72    pub fn brand_name(mut self, brand_name: String) -> Self {
73        self.brand_name = Some(brand_name);
74        self
75    }
76
77    #[must_use]
78    pub fn locale(mut self, locale: String) -> Self {
79        self.locale = Some(locale);
80        self
81    }
82
83    #[must_use]
84    pub const fn landing_page(mut self, landing_page: LandingPage) -> Self {
85        self.landing_page = Some(landing_page);
86        self
87    }
88
89    #[must_use]
90    pub const fn shipping_preference(
91        mut self,
92        shipping_preference: ShippingPreference,
93    ) -> OrderApplicationContext {
94        self.shipping_preference = Some(shipping_preference);
95        self
96    }
97
98    #[must_use]
99    pub const fn user_action(mut self, user_action: UserAction) -> OrderApplicationContext {
100        self.user_action = Some(user_action);
101        self
102    }
103
104    #[must_use]
105    pub const fn payment_method(
106        mut self,
107        payment_method: PaymentMethod,
108    ) -> OrderApplicationContext {
109        self.payment_method = Some(payment_method);
110        self
111    }
112
113    #[must_use]
114    pub fn return_url(mut self, return_url: String) -> OrderApplicationContext {
115        self.return_url = Some(return_url);
116        self
117    }
118
119    #[must_use]
120    pub fn cancel_url(mut self, cancel_url: String) -> OrderApplicationContext {
121        self.cancel_url = Some(cancel_url);
122        self
123    }
124
125    #[must_use]
126    pub fn stored_payment_source(
127        mut self,
128        stored_payment_source: StoredPaymentSource,
129    ) -> OrderApplicationContext {
130        self.stored_payment_source = Some(stored_payment_source);
131        self
132    }
133}