-
Notifications
You must be signed in to change notification settings - Fork 137
Closed
Description
Given partial PaymentDetailsUpdate, should we object merge with whatever the sheet is showing?
Problem
Given:
const details = {...}; // total, shippingOptions, displayItems, etc.
const request = new PaymentRequest(methods, details, options);
// later
request.addEventListener("shippingaddresschange", ev =>{
ev.updateWith(new Promise(async resolve => {
const total = await calculateNewShippingCost(request.shippingAddress);
resolve({total}); // Partial update, just the total
});
});So, details initially populates the payment sheet with a total, displayItems, shippingOptions etc.
Today, ev.updateWith({total}) being called causes displayItems, shippingOptions, etc. to all get trashed - and only the total updates. Obviously, that's not great.
Proposal
The proposal is that when updateWith() is called, we do a property spread over the original object, so old properties values are retained, and new properties are added (or nulled/emptied out).
Basically, this would be the browser code:
// `newData` what is sent in when via ev.updateWith() resolves
sheet.addEventListener("updatepaymentsheet", ({newData}) => {
// merge the existing data with the new data, so creates a partial update
const updatedData = {...sheet.getCurrentData(), ...newData};
sheet.render(updatedData);
});cc @aestes, @rsolomakhin, @michelle