Configure the button from the bootstrappers

This should give us the flexibility to overwrite default configuration option on context level
This commit is contained in:
Mészáros Róbert 2020-04-10 10:34:49 +03:00
parent 42fe525a0b
commit 4e0a4b8edb
9 changed files with 86 additions and 78 deletions

View file

@ -0,0 +1,39 @@
import onApprove from './onApproveForPayNow.js';
class CheckoutActionHandler {
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,
onApprove:onApprove(this),
onError: (error) => {
this.errorHandler.message(error);
}
}
}
}
export default CheckoutActionHandler;