UNPKG

react-native-sumup-interface

Version:
82 lines (81 loc) 4.09 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CurrencyCodes = void 0; const react_native_1 = require("react-native"); const { SumUpBridge } = react_native_1.NativeModules; var CurrencyCodes; (function (CurrencyCodes) { CurrencyCodes[CurrencyCodes["BGN"] = SumUpBridge.SMPCurrencyCodeBGN] = "BGN"; CurrencyCodes[CurrencyCodes["BRL"] = SumUpBridge.SMPCurrencyCodeBRL] = "BRL"; CurrencyCodes[CurrencyCodes["CHF"] = SumUpBridge.SMPCurrencyCodeCHF] = "CHF"; CurrencyCodes[CurrencyCodes["CLP"] = (react_native_1.Platform.OS === 'android') ? SumUpBridge.SMPCurrencyCodeCLP : null] = "CLP"; CurrencyCodes[CurrencyCodes["CZK"] = SumUpBridge.SMPCurrencyCodeCZK] = "CZK"; CurrencyCodes[CurrencyCodes["DKK"] = SumUpBridge.SMPCurrencyCodeDKK] = "DKK"; CurrencyCodes[CurrencyCodes["EUR"] = SumUpBridge.SMPCurrencyCodeEUR] = "EUR"; CurrencyCodes[CurrencyCodes["GBP"] = SumUpBridge.SMPCurrencyCodeGBP] = "GBP"; CurrencyCodes[CurrencyCodes["HUF"] = SumUpBridge.SMPCurrencyCodeHUF] = "HUF"; CurrencyCodes[CurrencyCodes["NOK"] = SumUpBridge.SMPCurrencyCodeNOK] = "NOK"; CurrencyCodes[CurrencyCodes["PLN"] = SumUpBridge.SMPCurrencyCodePLN] = "PLN"; CurrencyCodes[CurrencyCodes["RON"] = SumUpBridge.SMPCurrencyCodeRON] = "RON"; CurrencyCodes[CurrencyCodes["SEK"] = SumUpBridge.SMPCurrencyCodeSEK] = "SEK"; CurrencyCodes[CurrencyCodes["USD"] = SumUpBridge.SMPCurrencyCodeUSD] = "USD"; })(CurrencyCodes = exports.CurrencyCodes || (exports.CurrencyCodes = {})); class SumUpSDK { static init(key) { SumUpSDK._apiKey = key; if (react_native_1.Platform.OS === 'ios') SumUpBridge.setup(key); } get apiKey() { return SumUpSDK._apiKey; } authenticate() { return (react_native_1.Platform.OS === 'ios') ? SumUpBridge.authenticate() : SumUpBridge.authenticate(SumUpSDK._apiKey); } authenticateWithToken(token) { return (react_native_1.Platform.OS === 'ios') ? SumUpBridge.authenticateWithToken(token) : SumUpBridge.authenticateWithToken(SumUpSDK._apiKey, token); } isLoggedIn() { return SumUpBridge.isLoggedIn(); } logout() { return SumUpBridge.logout(); } prepareForCheckout() { return SumUpBridge.prepareForCheckout(); } checkout(title, totalAmount, currencyCode = CurrencyCodes.GBP, foreignTransactionId = "", token = null) { const request = { 'title': title, 'totalAmount': totalAmount, 'currencyCode': currencyCode, "foreignTransactionId": foreignTransactionId }; return this.isLoggedIn().then((result) => __awaiter(this, void 0, void 0, function* () { if (!result.isLoggedIn) { if (!token) throw new Error('Not logged in. Call "authenticate" or pass the token to this method'); const authResult = yield this.authenticateWithToken(token); if (!authResult.success) throw new Error(`Error while authenticating:${JSON.stringify(authResult)}`); } return SumUpBridge.checkout(request); })); } ; preferences() { return SumUpBridge.preferences(); } } SumUpSDK._apiKey = ''; ; exports.default = SumUpSDK;