mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 19:48:52 +08:00
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:
parent
42fe525a0b
commit
4e0a4b8edb
9 changed files with 86 additions and 78 deletions
|
@ -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;
|
Loading…
Add table
Add a link
Reference in a new issue