mpp-sdk
Version:
SDK to talk to the Memento Payments Platform
68 lines (67 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const __1 = require("..");
class WalletEndpoint {
constructor(config, fundingSources, users) {
this.config = config;
this.fundingSources = fundingSources;
this.users = users;
}
getAppleExtensionData() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
// Get auth token
const authToken = yield this.config.storage.retrieveAuthToken();
if (!authToken) {
throw new __1.GeneralError("No auth token");
}
// Get current user
const userResponse = yield this.users.current();
if (!userResponse.data) {
throw new __1.GeneralError("Unable to retrieve user");
}
// Get funding sources
const fsResponse = yield this.fundingSources.list();
if (!fsResponse.data) {
throw new __1.GeneralError("Unable to retrieve funding sources");
}
// Get available cards
let fundingSources = fsResponse.data
.slice()
.filter((element) => element.status !== "closed");
let cards = [];
for (let i = 0; i < fundingSources.length; i++) {
let fundingSource = fundingSources[i];
if (fundingSource &&
fundingSource.card &&
fundingSource.card.type_id !== 3) {
let last4 = fundingSource.card.masked_number.slice(-4);
cards.push({
identifier: fundingSource.id,
title: fundingSource.description || "Kardio",
last4: last4.trim(),
cardHolderName: userResponse.data.full_name,
art: "default",
});
}
}
// Return the data
let data = {
projectId: this.config.projectId || "",
email: userResponse.data.email || "",
authToken: {
token: authToken.token,
expiresAt: authToken.expires_at,
},
cards: cards,
};
return data;
}
catch (error) {
throw new __1.GeneralError(String(error));
}
});
}
}
exports.default = WalletEndpoint;