show buttons on mini-cart and cart

This commit is contained in:
David Remer 2020-04-08 12:33:34 +03:00
parent cc732840b1
commit 41f86426d8
6 changed files with 125 additions and 39 deletions

View file

@ -0,0 +1,42 @@
class CartConfig {
constructor(config, errorHandler) {
this.config = config;
this.errorHandler = errorHandler;
}
configuration() {
const createOrder = (data, actions) => {
return fetch(this.config.ajax.create_order.endpoint, {
method: 'POST',
body: JSON.stringify({
nonce: this.config.ajax.create_order.nonce,
purchase_units:[]
})
}).then(function (res) {
return res.json();
}).then(function (data) {
if (!data.success) {
//Todo: Error handling
return;
}
return data.data.id;
});
}
const onApprove = (data, actions) => {
return actions.redirect(this.config.redirect);
}
return {
createOrder,
onApprove,
onError: (error) => {
this.errorHandler.message(error);
}
}
}
}
export default CartConfig;