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

40 lines
993 B
JavaScript
Raw Normal View History

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