2020-04-10 10:34:49 +03:00
|
|
|
import onApprove from './onApproveForPayNow.js';
|
2020-04-28 09:14:05 +03:00
|
|
|
import {payerData} from "./Payer";
|
2020-04-09 09:33:18 +03:00
|
|
|
|
2020-04-10 10:34:49 +03:00
|
|
|
class CheckoutActionHandler {
|
2020-04-09 09:33:18 +03:00
|
|
|
|
|
|
|
constructor(config, errorHandler) {
|
|
|
|
this.config = config;
|
|
|
|
this.errorHandler = errorHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration() {
|
|
|
|
|
|
|
|
const createOrder = (data, actions) => {
|
2020-04-28 09:14:05 +03:00
|
|
|
const payer = payerData();
|
2020-04-09 09:33:18 +03:00
|
|
|
return fetch(this.config.ajax.create_order.endpoint, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
nonce: this.config.ajax.create_order.nonce,
|
2020-04-16 10:29:25 +03:00
|
|
|
payer
|
2020-04-09 09:33:18 +03:00
|
|
|
})
|
|
|
|
}).then(function (res) {
|
|
|
|
return res.json();
|
|
|
|
}).then(function (data) {
|
|
|
|
if (!data.success) {
|
2020-04-23 17:05:44 +03:00
|
|
|
throw Error(data.data);
|
2020-04-09 09:33:18 +03:00
|
|
|
}
|
|
|
|
return data.data.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
createOrder,
|
|
|
|
onApprove:onApprove(this),
|
|
|
|
onError: (error) => {
|
|
|
|
this.errorHandler.message(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:05:44 +03:00
|
|
|
export default CheckoutActionHandler;
|