mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
show buttons on mini-cart and cart
This commit is contained in:
parent
cc732840b1
commit
41f86426d8
6 changed files with 125 additions and 39 deletions
42
modules.local/ppcp-button/resources/js/modules/CartConfig.js
Normal file
42
modules.local/ppcp-button/resources/js/modules/CartConfig.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue