Skip to content

Commit

Permalink
[ECP-8486] Update quote totals and set tax included value in the expr…
Browse files Browse the repository at this point in the history
…ess Apple Pay checkout (#38)

* setup correctly updating the quote with the up-to-date shipping information

* set some breakpoints to debug via gitpod

* [PW-8486] Call shipping-information to set the quote and update the final amount with tax included value

* Update view/frontend/web/js/applepay/button.js

Co-authored-by: Peter Ojo <[email protected]>

* Update view/frontend/web/js/applepay/button.js

Co-authored-by: Peter Ojo <[email protected]>

* [PW-8486] Remove debug statements

* [PW-8486] Fix formatting

---------

Co-authored-by: RokPopov <[email protected]>
Co-authored-by: Peter Ojo <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent ed6d52f commit cd0feee
Showing 1 changed file with 64 additions and 17 deletions.
81 changes: 64 additions & 17 deletions view/frontend/web/js/applepay/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,44 @@ define([
self.shippingMethod = result[i].method_code;
}
}

let address = {
'countryId': self.shippingAddress.country_id,
'region': self.shippingAddress.region,
'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region),
'postcode': self.shippingAddress.postcode
};


// Create payload to get totals
let totalsPayload = {
'addressInformation': {
'address': {
'countryId': self.shippingAddress.country_id,
'region': self.shippingAddress.region,
'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region),
'postcode': self.shippingAddress.postcode
},
'address': address,
'shipping_method_code': self.shippingMethods[shippingMethods[0].identifier].method_code,
'shipping_carrier_code': self.shippingMethods[shippingMethods[0].identifier].carrier_code
}
};

// Create payload to update quote
let shippingInformationPayload = {
'addressInformation': {
...totalsPayload.addressInformation,
'shipping_address': address,
'billing_address': address
}
};

delete shippingInformationPayload.addressInformation.address;
setShippingInformation(shippingInformationPayload, this.isProductView);

setTotalsInfo(totalsPayload, this.isProductView)
.done((response) => {
let applePayShippingContactUpdate = {};

applePayShippingContactUpdate.newShippingMethods = shippingMethods;
applePayShippingContactUpdate.newTotal = {
label: $t('Grand Total'),
amount: response.grand_total.toString()
amount: (response.grand_total + response.tax_amount).toString()
};
applePayShippingContactUpdate.newLineItems = [
{
Expand All @@ -317,6 +333,15 @@ define([
amount: shippingMethods[0].amount.toString()
}
];

if (response.tax_amount > 0) {
applePayShippingContactUpdate.newLineItems.push({
type: 'final',
label: $t('Tax'),
amount: response.tax_amount.toString()
})
}

resolve(applePayShippingContactUpdate);
// Pass shipping methods back
}).fail((e) => {
Expand All @@ -328,29 +353,42 @@ define([

onShippingMethodSelect: function (resolve, reject, event) {
let self = this;

let shippingMethod = event.shippingMethod;
let payload = {

let address = {
'countryId': self.shippingAddress.country_id,
'region': self.shippingAddress.region,
'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region),
'postcode': self.shippingAddress.postcode
};

let totalsPayload = {
'addressInformation': {
'address': {
'countryId': self.shippingAddress.country_id,
'region': self.shippingAddress.region,
'regionId': getRegionId(self.shippingAddress.country_id, self.shippingAddress.region),
'postcode': self.shippingAddress.postcode
},
'address': address,
'shipping_method_code': self.shippingMethods[shippingMethod.identifier].method_code,
'shipping_carrier_code': self.shippingMethods[shippingMethod.identifier].carrier_code
}
};

setTotalsInfo(payload, this.isProductView)
let shippingInformationPayload = {
'addressInformation': {
...totalsPayload.addressInformation,
'shipping_address': address,
'billing_address': address
}
};

delete shippingInformationPayload.addressInformation.address;
setShippingInformation(shippingInformationPayload, this.isProductView);

setTotalsInfo(totalsPayload, this.isProductView)
.done((response) => {
let applePayShippingMethodUpdate = {};

applePayShippingMethodUpdate.newTotal = {
type: 'final',
label: $t('Grand Total'),
amount: response.grand_total.toString()
amount: (response.grand_total + response.tax_amount).toString()
};
applePayShippingMethodUpdate.newLineItems = [
{
Expand All @@ -364,6 +402,15 @@ define([
amount: shippingMethod.amount.toString()
}
];

if (response.tax_amount > 0) {
applePayShippingMethodUpdate.newLineItems.push({
type: 'final',
label: $t('Tax'),
amount: response.tax_amount.toString()
})
}

self.shippingMethod = shippingMethod.identifier;
resolve(applePayShippingMethodUpdate);
}).fail((e) => {
Expand Down

0 comments on commit cd0feee

Please sign in to comment.