@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
38 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
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 SingletonFetch_1 = tslib_1.__importDefault(require("../serviceHelpers/SingletonFetch"));
var sales_1 = tslib_1.__importDefault(require("./sales"));
var order_1 = require("./order");
function initializePayment(orderNumber, paymentMethodID, options) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var url, fetchOptions;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(sales_1.default.apiOrigin, "/sales/public/v1/checkout/order/").concat(orderNumber, "/payment/").concat(paymentMethodID);
if (options && options.applePayValidationUrl) {
url = url + "?validationURL=".concat(options.applePayValidationUrl);
}
return [4, (0, utils_1.getOptions)({ method: 'GET', headers: constants_1.headers, options: options })];
case 1:
fetchOptions = _a.sent();
return [2, (0, SingletonFetch_1.default)(url, fetchOptions, 'initializePayment')
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, order_1.isInitializedPayment)(json)) {
return json;
}
else {
throw json;
}
})];
}
});
});
}
exports.default = initializePayment;
//# sourceMappingURL=initializePayment.js.map