UNPKG

@arc-publishing/sdk-sales

Version:
41 lines 2.25 kB
import { __assign, __awaiter, __generator } from "tslib"; import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler'; import { headers } from './constants'; import { getOptions } from './utils'; import SingletonFetch from '../serviceHelpers/SingletonFetch'; import Sales from './sales'; import { isOrderResponse } from './order'; import enforceRecaptcha from './enforceRecaptcha'; export default function finalizePayment(orderNumber, paymentMethodID, token, options, 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 opts; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, getOptions({ method: 'PUT', headers: headers, body: JSON.stringify(__assign(__assign({}, options), { token: token, 'recaptcha-token': recaptchaToken })) })]; case 1: opts = _a.sent(); return [2, SingletonFetch("".concat(Sales.apiOrigin, "/sales/public/v1/checkout/order/").concat(orderNumber, "/payment/").concat(paymentMethodID), opts, 'finalizePayment') .then(JSONResponseHandler) .then(function (json) { if (isOrderResponse(json)) { Sales.currentOrder = json; return json; } else { throw json; } })]; } }); }); })]; }); }); } //# sourceMappingURL=finalizePayment.js.map