2020-04-09 19:15:28 +03:00
|
|
|
import onApprove from './onApproveForContinue.js';
|
2020-04-08 12:33:34 +03:00
|
|
|
|
|
|
|
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,
|
2020-04-09 19:15:28 +03:00
|
|
|
purchase_units: [],
|
|
|
|
}),
|
|
|
|
}).then(function(res) {
|
2020-04-08 12:33:34 +03:00
|
|
|
return res.json();
|
2020-04-09 19:15:28 +03:00
|
|
|
}).then(function(data) {
|
2020-04-08 12:33:34 +03:00
|
|
|
if (!data.success) {
|
|
|
|
//Todo: Error handling
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return data.data.id;
|
|
|
|
});
|
2020-04-09 19:15:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const style = this.config.button.style;
|
|
|
|
|
2020-04-08 12:33:34 +03:00
|
|
|
return {
|
|
|
|
createOrder,
|
2020-04-09 19:15:28 +03:00
|
|
|
onApprove: onApprove(this),
|
2020-04-08 12:33:34 +03:00
|
|
|
onError: (error) => {
|
|
|
|
this.errorHandler.message(error);
|
2020-04-09 19:15:28 +03:00
|
|
|
},
|
|
|
|
style,
|
|
|
|
};
|
2020-04-08 12:33:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CartConfig;
|