mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-10 23:42:39 +08:00
init
This commit is contained in:
parent
ba97d7143d
commit
779eb31e4e
53 changed files with 8475 additions and 0 deletions
39
modules.local/ppcp-button/resources/js/modules/UpdateCart.js
Normal file
39
modules.local/ppcp-button/resources/js/modules/UpdateCart.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
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;
|
Loading…
Add table
Add a link
Reference in a new issue