UNPKG

@arc-publishing/sdk-sales

Version:
58 lines 3.09 kB
import { __awaiter, __generator } from "tslib"; import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler'; import { headers } from './constants'; import { getOptions, cleanPayload } from './utils'; import Sales from './sales'; import { isOrderResponse } from './order'; import enforceRecaptcha from './enforceRecaptcha'; export function createOrder(email, phone, billingAddress, firstName, lastName, secondLastName, shippingAddress, recaptchaToken) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, createNewOrder(billingAddress, email, phone, firstName, lastName, secondLastName, shippingAddress, recaptchaToken)]; }); }); } export function createNewOrder(billingAddress, email, phone, firstName, lastName, secondLastName, shippingAddress, recaptchaToken) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2, enforceRecaptcha(recaptchaToken).then(function () { return __awaiter(_this, void 0, void 0, function () { var body, options; return __generator(this, function (_a) { switch (_a.label) { case 0: body = JSON.stringify(cleanPayload({ email: email, phone: phone, billingAddress: billingAddress, firstName: firstName, lastName: lastName, secondLastName: secondLastName, shippingAddress: shippingAddress, 'recaptcha-token': recaptchaToken })); return [4, getOptions({ method: 'POST', headers: headers, body: body })]; case 1: options = _a.sent(); return [2, fetch("".concat(Sales.apiOrigin, "/sales/public/v1/checkout/order"), options) .then(JSONResponseHandler) .then(function (json) { if (isOrderResponse(json)) { Sales.currentOrder = json; return json; } else { throw json; } })]; } }); }); })]; }); }); } //# sourceMappingURL=createOrder.js.map