mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
|
|
||
|
|
||
|
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;
|