@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
173 lines (169 loc) • 6.58 kB
JavaScript
'use strict';
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var classValidator = require('class-validator');
var classValidatorJsonschema = require('class-validator-jsonschema');
var typeorm = require('typeorm');
var isCardExpirationValid = require('../helpers/validators/is-card-expiration-valid.js');
var isLastCardDigitsValid = require('../helpers/validators/is-last-card-digits-valid.js');
var isStripeIdValid = require('../helpers/validators/is-stripe-id-valid.js');
/**
* Card entity
* @description Stipe should store both cards from connect account and from SetupIntent
*/
let Card = class Card {
};
tslib.__decorate([
typeorm.PrimaryGeneratedColumn('uuid'),
classValidator.Allow(),
tslib.__metadata("design:type", String)
], Card.prototype, "id", void 0);
tslib.__decorate([
typeorm.Index('IDX_card_userId', ['userId']),
typeorm.Column({ type: 'varchar', length: 36 }),
classValidator.Length(1, 36),
tslib.__metadata("design:type", String)
], Card.prototype, "userId", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'If payment method exist that Card can be charged and used in paymentIntent for processing payments. Attached to the customer, not connected account',
}),
typeorm.Column({ type: 'varchar', length: 66, default: null }),
isStripeIdValid(),
classValidator.Length(1, 66),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsNullable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "paymentMethodId", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Card fingerprint. Remove duplicates duplicates if same card uses as payment method',
}),
typeorm.Column({ type: 'varchar', length: 30, default: null }),
classValidator.Length(1, 30),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsNullable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "fingerprint", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Last 4 digits',
example: '4242',
}),
typeorm.Column({ type: 'varchar', length: 4 }),
isLastCardDigitsValid(),
classValidator.Length(1, 4),
tslib.__metadata("design:type", String)
], Card.prototype, "lastDigits", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
example: '01/27',
}),
typeorm.Column({ type: 'varchar', length: 5 }),
isCardExpirationValid(),
classValidator.Length(1, 5),
tslib.__metadata("design:type", String)
], Card.prototype, "expired", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
example: 'debit',
description: 'Uses in instant payouts: available only for debit cards',
}),
typeorm.Column({ type: 'varchar', length: 10 }),
classValidator.Length(1, 10),
tslib.__metadata("design:type", String)
], Card.prototype, "funding", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
example: 'visa',
}),
typeorm.Column({ type: 'varchar', length: 20 }),
classValidator.Length(1, 20),
tslib.__metadata("design:type", String)
], Card.prototype, "brand", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Issuer country. Where issuer (e.g. bank) is registered',
examples: ['US', 'BR'],
}),
typeorm.Column({ type: 'varchar', length: 5, default: null }),
classValidator.Length(1, 5),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsNullable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "origin", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Billing country. Where holder (e.g. customer) is registered',
examples: ['US', 'BR'],
}),
typeorm.Column({ type: 'varchar', length: 5, default: null }),
classValidator.Length(1, 5),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsNullable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "country", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Billing postal code. Where holder (e.g. customer) is registered',
examples: ['99301', '95076'],
}),
typeorm.Column({ type: 'varchar', length: 10, default: null }),
classValidator.Length(1, 10),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsNullable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "postalCode", void 0);
tslib.__decorate([
typeorm.Column({ type: 'varchar', length: 100, default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
classValidator.Length(1, 100),
tslib.__metadata("design:type", Object)
], Card.prototype, "holderName", void 0);
tslib.__decorate([
typeorm.Column({ type: 'boolean', default: false }),
classValidator.IsBoolean(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Boolean)
], Card.prototype, "isInstantPayoutAllowed", void 0);
tslib.__decorate([
typeorm.Column({ type: 'json', default: {} }),
classValidator.IsObject(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Object)
], Card.prototype, "params", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: "If it's the first attached user card it should be default",
}),
typeorm.Column({ type: 'boolean', default: false }),
microserviceHelpers.IsUndefinable(),
classValidator.IsBoolean(),
tslib.__metadata("design:type", Boolean)
], Card.prototype, "isDefault", void 0);
tslib.__decorate([
microserviceHelpers.IsTypeormDate(),
typeorm.CreateDateColumn(),
tslib.__metadata("design:type", Date)
], Card.prototype, "createdAt", void 0);
tslib.__decorate([
microserviceHelpers.IsTypeormDate(),
typeorm.UpdateDateColumn(),
tslib.__metadata("design:type", Date)
], Card.prototype, "updatedAt", void 0);
tslib.__decorate([
typeorm.ManyToOne('Customer', 'cards', { onDelete: 'CASCADE' }),
typeorm.JoinColumn({ name: 'userId' }),
tslib.__metadata("design:type", Function)
], Card.prototype, "customer", void 0);
Card = tslib.__decorate([
classValidatorJsonschema.JSONSchema({
properties: {
customer: { $ref: '#/definitions/Customer' },
},
}),
typeorm.Entity()
], Card);
var CardEntity = Card;
module.exports = CardEntity;