UNPKG

@walletpack/core

Version:

> TODO: description

151 lines (134 loc) 4.37 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.CreditCardSecureProperties = exports.CreditCardPersonalInformation = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _aesOop = _interopRequireDefault(require("aes-oop")); var _IdGenerator = _interopRequireDefault(require("../util/IdGenerator")); var _Crypto = _interopRequireDefault(require("../util/Crypto")); var _Keychain = _interopRequireDefault(require("./Keychain")); var CreditCardPersonalInformation = /*#__PURE__*/ function () { function CreditCardPersonalInformation() { (0, _classCallCheck2["default"])(this, CreditCardPersonalInformation); this.name = ''; this.email = ''; this.birthdate = ''; this.address = ''; this.city = ''; this.state = ''; this.country = ''; this.zipcode = ''; } (0, _createClass2["default"])(CreditCardPersonalInformation, [{ key: "clone", value: function clone() { return CreditCardPersonalInformation.fromJson(JSON.parse(JSON.stringify(this))); } }], [{ key: "placeholder", value: function placeholder() { return new CreditCardPersonalInformation(); } }, { key: "fromJson", value: function fromJson(json) { return Object.assign(this.placeholder(), json); } }]); return CreditCardPersonalInformation; }(); exports.CreditCardPersonalInformation = CreditCardPersonalInformation; var CreditCardSecureProperties = /*#__PURE__*/ function () { function CreditCardSecureProperties() { (0, _classCallCheck2["default"])(this, CreditCardSecureProperties); this.number = ''; this.authTokens = {}; this.cardHash = ''; this.personalInformation = CreditCardPersonalInformation.placeholder(); } (0, _createClass2["default"])(CreditCardSecureProperties, [{ key: "clone", value: function clone() { return CreditCardSecureProperties.fromJson(JSON.parse(JSON.stringify(this))); } }], [{ key: "placeholder", value: function placeholder() { return new CreditCardSecureProperties(); } }, { key: "fromJson", value: function fromJson(json) { var p = Object.assign(this.placeholder(), json); if (json.hasOwnProperty('personalInformation')) p.personalInformation = CreditCardPersonalInformation.fromJson(json.personalInformation); return p; } }]); return CreditCardSecureProperties; }(); exports.CreditCardSecureProperties = CreditCardSecureProperties; var CreditCard = /*#__PURE__*/ function () { function CreditCard() { (0, _classCallCheck2["default"])(this, CreditCard); this.id = _IdGenerator["default"].text(24); this.name = ''; this.lastFour = ''; this.expiration = ''; this.secure = CreditCardSecureProperties.placeholder(); this.createdAt = +new Date(); } (0, _createClass2["default"])(CreditCard, [{ key: "unique", value: function unique() { return this.id; } }, { key: "clone", value: function clone() { return CreditCard.fromJson(JSON.parse(JSON.stringify(this))); } }, { key: "hash", value: function hash() { this.cardHash = _Crypto["default"].bufferToHash(this.secure.number); } }, { key: "isEncrypted", value: function isEncrypted() { return typeof this.secure === 'string'; } }, { key: "encrypt", value: function encrypt(seed) { if (!this.isEncrypted()) this.secure = _aesOop["default"].encrypt(this.secure, seed); } }, { key: "decrypt", value: function decrypt(seed) { if (this.isEncrypted()) this.secure = _aesOop["default"].decrypt(this.secure, seed); } }], [{ key: "placeholder", value: function placeholder() { return new CreditCard(); } }, { key: "fromJson", value: function fromJson(json) { var p = Object.assign(this.placeholder(), json); if (json.hasOwnProperty('secure')) p.secure = typeof json.secure === 'string' ? json.secure : CreditCardSecureProperties.fromJson(json.secure); return p; } }]); return CreditCard; }(); exports["default"] = CreditCard;