2020-04-08 16:23:33 +03:00
|
|
|
import onApprove from "./onApprove";
|
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,
|
|
|
|
purchase_units:[]
|
|
|
|
})
|
|
|
|
}).then(function (res) {
|
|
|
|
return res.json();
|
|
|
|
}).then(function (data) {
|
|
|
|
if (!data.success) {
|
|
|
|
//Todo: Error handling
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return data.data.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
createOrder,
|
2020-04-08 16:23:33 +03:00
|
|
|
onApprove:onApprove(this),
|
2020-04-08 12:33:34 +03:00
|
|
|
onError: (error) => {
|
|
|
|
this.errorHandler.message(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CartConfig;
|