woocommerce-paypal-payments/modules.local/ppcp-button/resources/js/modules/UpdateCart.js

39 lines
1,020 B
JavaScript
Raw Normal View History

2020-04-02 08:38:00 +03:00
class UpdateCart {
constructor(endpoint, nonce) {
this.endpoint = endpoint;
this.nonce = nonce;
}
update(onResolve, product, qty, variations) {
return new Promise( (resolve, reject) => {
fetch(
this.endpoint,
{
method: 'POST',
body: JSON.stringify({
nonce: this.nonce,
product,
qty,
variations
})
}
).then(
(result) => {
return result.json();
}
).then( (result) => {
if (! result.success) {
reject(result.data);
return;
}
const resolved = onResolve(result.data);
resolve(resolved);
}
)
});
}
}
export default UpdateCart;