add onApprove endpoint to store order in session

This commit is contained in:
David Remer 2020-04-08 16:23:33 +03:00
parent 7c2bc5a8da
commit 5824a40a08
10 changed files with 128 additions and 13 deletions

View file

@ -1,4 +1,4 @@
import onApprove from "./onApprove";
class CartConfig {
@ -26,12 +26,9 @@ class CartConfig {
return data.data.id;
});
}
const onApprove = (data, actions) => {
return actions.redirect(this.config.redirect);
}
return {
createOrder,
onApprove,
onApprove:onApprove(this),
onError: (error) => {
this.errorHandler.message(error);
}

View file

@ -1,5 +1,6 @@
import ButtonsToggleListener from "./ButtonsToggleListener";
import Product from "./Product";
import onApprove from "./onApprove";
class SingleProductConfig {
constructor(
@ -29,12 +30,10 @@ class SingleProductConfig {
);
observer.init();
}
const onApprove = (data, actions) => {
return actions.redirect(this.config.redirect);
}
return {
createOrder: this.createOrder(),
onApprove,
onApprove: onApprove(this),
onError: (error) => {
this.errorHandler.message(error);
}
@ -123,5 +122,4 @@ class SingleProductConfig {
return this.formElement.classList.contains('grouped_form');
}
}
export default SingleProductConfig;

View file

@ -0,0 +1,22 @@
const onApprove = (context) => {
return (data, actions) => {
return fetch(context.config.ajax.approve_order.endpoint, {
method: 'POST',
body: JSON.stringify({
nonce: context.config.ajax.approve_order.nonce,
order_id:data.orderID
})
}).then((res)=>{
return res.json();
}).then((data)=>{
if (!data.success) {
//Todo: Error handling
return;
}
location.href = context.config.redirect;
});
}
}
export default onApprove;