mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import onApprove from '../OnApproveHandler/onApproveForPayNow.js';
|
|
import {payerData} from "../Helper/PayerData";
|
|
|
|
class CheckoutActionHandler {
|
|
|
|
constructor(config, errorHandler) {
|
|
this.config = config;
|
|
this.errorHandler = errorHandler;
|
|
}
|
|
|
|
configuration() {
|
|
|
|
const createOrder = (data, actions) => {
|
|
const payer = payerData();
|
|
return fetch(this.config.ajax.create_order.endpoint, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
nonce: this.config.ajax.create_order.nonce,
|
|
payer
|
|
})
|
|
}).then(function (res) {
|
|
return res.json();
|
|
}).then(function (data) {
|
|
if (!data.success) {
|
|
throw Error(data.data);
|
|
}
|
|
return data.data.id;
|
|
});
|
|
}
|
|
return {
|
|
createOrder,
|
|
onApprove:onApprove(this),
|
|
onError: (error) => {
|
|
this.errorHandler.message(error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default CheckoutActionHandler;
|