UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

190 lines 8 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PaymentService = void 0; const query_string_1 = __importDefault(require("query-string")); const types_1 = require("./types"); /** * Service class for payment API calls. Requires an organizer to be set (call to `useOrganizer`) */ class PaymentService { constructor(client, version) { this.client = client; this.version = version; } /** * Returns true if the service is reachable * Currently the * * @returns Services' online status */ health() { return __awaiter(this, void 0, void 0, function* () { try { const res = yield this.client.get(`payment/health`); // ATM there is an issue with the payment service // where the health endpoint response is wrapped in a data object if (res.data.status === 'ok' || res.data.data.status === 'ok') { return { online: true }; } } catch (e) { // Do nothing } return { online: false }; }); } getPublishableKey() { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`payment/${this.version}/payment/config`); return res.data.data; }); } /** * Creates a Stripe Payment Intent for the specified order. * Fails if the order is not in a payable state, or if the booking of seats fails. * Confirms immediately if the order only contains free items. * * @param orderData contains the order id and the desired payment type * @throws `BadRequestError` */ createStripePaymentForOrder(orderData) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ order_id: orderData.orderId, type: orderData.type, }); const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.Stripe}?${query}`, {}); return res.data.data; }); } /** * Creates a payment intent with a custom amount. * Throws for zero and below as amounts. * * @param data contains the order id and the desired payment type * @throws `BadRequestError` */ createStripePayment(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.Stripe}/custom`, data); return res.data.data; }); } /** * Creates a crypto payment for the specified order. * Fails if the order is not in a payable state, or if the booking of seats fails. * Confirms immediately if the order only contains free items. * * @param orderData contains the order id and the desired redirection URLs * @throws `BadRequestError` */ createCryptoPaymentForOrder(orderData_1) { return __awaiter(this, arguments, void 0, function* (orderData, meta = {}) { const query = query_string_1.default.stringify({ order_id: orderData.orderId, type: orderData.type, }); const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.Coinbase}?${query}`, meta); return res.data.data; }); } /** * Creates a crypto payment with a custom amount. * Throws for zero and below as amounts. * * @param data contains the amounts and currencies, with metadata * @throws `BadRequestError` */ createCryptoPayment(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.Coinbase}/custom`, data); return res.data.data; }); } /** * Creates a payment for an order. * Uses OpenPayment/Hobex for the payment. * * @param data contains the amount and additional optional metadata, if you want to prefill the payment form * @returns the payment id and timestamp, which can be used for instantiating the payment form */ createOpenPaymentForOrder(order, data) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ order_id: order.orderId, }); const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.OpenPayment}?${query}`, data); return res.data.data; }); } /** * Creates a payment intent with a custom amount. * Uses OpenPayment/Hobex for the payment. * Throws for zero and below as amounts. * * @param data contains the amount and additional optional metadata, if you want to prefill the payment form * @returns the payment id and timestamp, which can be used for instantiating the payment form */ createOpenPayment(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.OpenPayment}/custom`, data); return res.data.data; }); } /** Checks the current status of the payment */ checkOpenPaymentStatus(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`payment/${this.version}/payment/${types_1.PaymentProvider.OpenPayment}/${id.id}`); return res.data.data; }); } /** Returns the Braintree token */ getBraintreeToken() { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`payment/${this.version}/payment/${types_1.PaymentProvider.Braintree}/token`); return res.data.data; }); } createBraintreePaymentForOrder(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`payment/${this.version}/payment/${types_1.PaymentProvider.Braintree}`, data); return res.data.data; }); } /** * Create a PayPal payout. Only available to the orderbook service ATM. * * @param data contains the data for the emails and amounts to pay out * @throws `BadRequestError` */ createPayout(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`payment/${this.version}/payment/paypal/payout`, data); return res.data.data; }); } /** * Manually confirms order * * @param data.id ID of the order to manually confirm */ confirmOrderManually(data) { return __awaiter(this, void 0, void 0, function* () { yield this.client.post(`payment/${this.version}/payment/on-site/confirm`, data); }); } } exports.PaymentService = PaymentService; //# sourceMappingURL=service.js.map