diff --git a/addons/payment/static/src/js/express_checkout_form.js b/addons/payment/static/src/js/express_checkout_form.js index 0ad660790f5..8db86628b56 100644 --- a/addons/payment/static/src/js/express_checkout_form.js +++ b/addons/payment/static/src/js/express_checkout_form.js @@ -13,6 +13,7 @@ publicWidget.registry.PaymentExpressCheckoutForm = publicWidget.Widget.extend({ await this._super(...arguments); this.txContext = {}; Object.assign(this.txContext, this.$el.data()); + this.txContext.shippingInfoRequired = !!this.txContext.shippingInfoRequired; const expressCheckoutForms = this._getExpressCheckoutForms(); for (const expressCheckoutForm of expressCheckoutForms) { await this._prepareExpressCheckoutForm(expressCheckoutForm.dataset); @@ -37,16 +38,6 @@ publicWidget.registry.PaymentExpressCheckoutForm = publicWidget.Widget.extend({ ); }, - /** - * Return whether the shipping information is required or not. - * - * For a module to request shipping information to the customer, it must override this method. - * - * @private - * @return {Boolean} - Whether the shipping information is required or not. - */ - _isShippingInformationRequired: () => false, - /** * Prepare the provider-specific express checkout form based on the provided data. * diff --git a/addons/payment/views/payment_templates.xml b/addons/payment/views/payment_templates.xml index 8fd3355fcde..28ab49ce385 100644 --- a/addons/payment/views/payment_templates.xml +++ b/addons/payment/views/payment_templates.xml @@ -325,6 +325,7 @@ - 'currency' - The currency of the transaction, as a `res.currency` record. - 'merchant_name' - The merchant name. - 'access_token' - The access token used to authenticate the partner. + - 'shipping_info_required' - Whether the shipping information is required or not. - 'transaction_route' - The route used to create a transaction when the user clicks Pay. - 'shipping_address_update_route' - The route where available carriers are computed based on the (partial) shipping information @@ -342,6 +343,7 @@ t-att-data-merchant-name="merchant_name" t-att-data-partner-id="partner_id" t-att-data-access-token="payment_access_token" + t-att-data-shipping-info-required="shipping_info_required" t-att-data-transaction-route="transaction_route" t-att-data-shipping-address-update-route="shipping_address_update_route" t-att-data-express-checkout-route="express_checkout_route" diff --git a/addons/payment_stripe/static/src/js/express_checkout_form.js b/addons/payment_stripe/static/src/js/express_checkout_form.js index 565074bda34..bef61ac1921 100644 --- a/addons/payment_stripe/static/src/js/express_checkout_form.js +++ b/addons/payment_stripe/static/src/js/express_checkout_form.js @@ -15,7 +15,7 @@ paymentExpressCheckoutForm.include({ * @returns {Object} The information to be displayed on the payment form. */ _getOrderDetails(deliveryAmount) { - const pending = this._isShippingInformationRequired() && deliveryAmount === undefined; + const pending = this.txContext.shippingInfoRequired && deliveryAmount === undefined; const amount = deliveryAmount ? this.txContext.minorAmount + deliveryAmount : this.txContext.minorAmount; const displayItems = [ @@ -24,7 +24,7 @@ paymentExpressCheckoutForm.include({ amount: this.txContext.minorAmount, }, ]; - if (this._isShippingInformationRequired() && deliveryAmount !== undefined) { + if (this.txContext.shippingInfoRequired && deliveryAmount !== undefined) { displayItems.push({ label: _t("Delivery"), amount: deliveryAmount, @@ -64,7 +64,7 @@ paymentExpressCheckoutForm.include({ requestPayerName: true, // Force fetching the billing address for Apple Pay. requestPayerEmail: true, requestPayerPhone: true, - requestShipping: this._isShippingInformationRequired(), + requestShipping: this.txContext.shippingInfoRequired, ...this._getOrderDetails(), }); if (this.stripePaymentRequests === undefined) { @@ -102,7 +102,7 @@ paymentExpressCheckoutForm.include({ state: ev.paymentMethod.billing_details.address.state, } }; - if (this._isShippingInformationRequired()) { + if (this.txContext.shippingInfoRequired) { addresses.shipping_address = { name: ev.shippingAddress.recipient, phone: ev.shippingAddress.phone, @@ -143,7 +143,7 @@ paymentExpressCheckoutForm.include({ } }); - if (this._isShippingInformationRequired()) { + if (this.txContext.shippingInfoRequired) { // Wait until the express checkout form is loaded for Apple Pay and Google Pay to select // a default shipping address and trigger the `shippingaddresschange` event, so we can // fetch the available shipping options. When the customer manually selects a different diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 626f4e39535..f0bffb6406b 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -1182,13 +1182,14 @@ class WebsiteSale(http.Controller): _express_checkout_route, type='json', methods=['POST'], auth="public", website=True, sitemap=False ) - def process_express_checkout(self, billing_address): + def process_express_checkout(self, billing_address, **kwargs): """ Records the partner information on the order when using express checkout flow. Depending on whether the partner is registered and logged in, either creates a new partner or uses an existing one that matches all received data. - :param dict billing_address: billing information sent by the express payment form. + :param dict billing_address: Billing information sent by the express payment form. + :param dict kwargs: Optional data. This parameter is not used here. :return int: The order's partner id. """ order_sudo = request.website.sale_get_order() diff --git a/addons/website_sale_delivery/controllers/main.py b/addons/website_sale_delivery/controllers/main.py index 2f8c5496bcb..6d41e7537d2 100644 --- a/addons/website_sale_delivery/controllers/main.py +++ b/addons/website_sale_delivery/controllers/main.py @@ -73,18 +73,24 @@ class WebsiteSaleDelivery(WebsiteSale): return super().cart(**post) @http.route() - def process_express_checkout(self, shipping_address, shipping_option, **post): + def process_express_checkout( + self, billing_address, shipping_address=None, shipping_option=None, **kwargs + ): """ Override of `website_sale` to records the shipping information on the order when using express checkout flow. Depending on whether the partner is registered and logged in, either creates a new partner or uses an existing one that matches all received data. - :param dict shipping_address: shipping information sent by the express payment form. - :param dict shipping_option: carrier information sent by the express payment form. - :param dict post: other information used in the parent route. + :param dict billing_address: Billing information sent by the express payment form. + :param dict shipping_address: Shipping information sent by the express payment form. + :param dict shipping_option: Carrier information sent by the express payment form. + :param dict kwargs: Optional data. This parameter is not used here. :return int: The order's partner id. """ + if not (shipping_address and shipping_option): + return super().process_express_checkout(billing_address, **kwargs) + order_sudo = request.website.sale_get_order() # Update the partner with all the information @@ -124,7 +130,7 @@ class WebsiteSaleDelivery(WebsiteSale): # Process the delivery carrier order_sudo._check_carrier_quotation(force_carrier_id=int(shipping_option['id'])) - return super().process_express_checkout(**post) + return super().process_express_checkout(billing_address, **kwargs) @http.route( _express_checkout_shipping_route, type='json', auth='public', methods=['POST'], @@ -251,6 +257,7 @@ class WebsiteSaleDelivery(WebsiteSale): def _get_express_shop_payment_values(self, order, **kwargs): values = super(WebsiteSaleDelivery, self)._get_express_shop_payment_values(order, **kwargs) + values['shipping_info_required'] = not order.only_services values['shipping_address_update_route'] = self._express_checkout_shipping_route return values diff --git a/addons/website_sale_delivery/static/src/js/express_checkout_form.js b/addons/website_sale_delivery/static/src/js/express_checkout_form.js deleted file mode 100644 index b4178cf7ab2..00000000000 --- a/addons/website_sale_delivery/static/src/js/express_checkout_form.js +++ /dev/null @@ -1,14 +0,0 @@ -/** @odoo-module **/ - -import { paymentExpressCheckoutForm } from '@payment/js/express_checkout_form'; - -paymentExpressCheckoutForm.include({ - /** - * Return whether the shipping information is required or not - * - * @private - * @override method from payment.express_form - * @return {Boolean} - Whether the shipping information is required or not - */ - _isShippingInformationRequired: () => true, -});