@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
63 lines • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createNewOrder = exports.createOrder = void 0;
var tslib_1 = require("tslib");
var JSONResponseHandler_1 = tslib_1.__importDefault(require("@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler"));
var constants_1 = require("./constants");
var utils_1 = require("./utils");
var sales_1 = tslib_1.__importDefault(require("./sales"));
var order_1 = require("./order");
var enforceRecaptcha_1 = tslib_1.__importDefault(require("./enforceRecaptcha"));
function createOrder(email, phone, billingAddress, firstName, lastName, secondLastName, shippingAddress, recaptchaToken) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2, createNewOrder(billingAddress, email, phone, firstName, lastName, secondLastName, shippingAddress, recaptchaToken)];
});
});
}
exports.createOrder = createOrder;
function createNewOrder(billingAddress, email, phone, firstName, lastName, secondLastName, shippingAddress, recaptchaToken) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
return [2, (0, enforceRecaptcha_1.default)(recaptchaToken).then(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var body, options;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
body = JSON.stringify((0, utils_1.cleanPayload)({
email: email,
phone: phone,
billingAddress: billingAddress,
firstName: firstName,
lastName: lastName,
secondLastName: secondLastName,
shippingAddress: shippingAddress,
'recaptcha-token': recaptchaToken
}));
return [4, (0, utils_1.getOptions)({
method: 'POST',
headers: constants_1.headers,
body: body
})];
case 1:
options = _a.sent();
return [2, fetch("".concat(sales_1.default.apiOrigin, "/sales/public/v1/checkout/order"), options)
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, order_1.isOrderResponse)(json)) {
sales_1.default.currentOrder = json;
return json;
}
else {
throw json;
}
})];
}
});
}); })];
});
});
}
exports.createNewOrder = createNewOrder;
//# sourceMappingURL=createOrder.js.map