KEMBAR78
updateWith(data) should merge with request.data · Issue #649 · w3c/payment-request · GitHub
Skip to content

updateWith(data) should merge with request.data #649

@marcoscaceres

Description

@marcoscaceres

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions