Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ yarn-error.log*

# IDE - IntelliJ
.idea/
*.iml

# OS
.DS_Store
Expand All @@ -48,4 +49,5 @@ dist
hardhat-dependency-compiler

# cache
cache
cache

9 changes: 5 additions & 4 deletions packages/apps/job-launcher/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ HCAPTCHA_SITE_KEY=10000000-ffff-ffff-ffff-000000000001
HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000

# Stripe
STRIPE_SECRET_KEY=disabled
STRIPE_APP_NAME=Launcher Server Local
STRIPE_APP_VERSION=1.0.0
STRIPE_APP_INFO_URL=http://local.app
PAYMENT_PROVIDER_SECRET_KEY=disabled
PAYMENT_PROVIDER_APP_NAME=Launcher Server Local
PAYMENT_PROVIDER_APP_VERSION=1.0.0
PAYMENT_PROVIDER_APP_INFO_URL=http://local.app
Comment thread
portuu3 marked this conversation as resolved.
PAYMENT_PROVIDER_API_VERSION=2022-11-15

# Sendgrid
SENDGRID_API_KEY=sendgrid-disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NetworkConfigService } from './network-config.service';
import { PGPConfigService } from './pgp-config.service';
import { S3ConfigService } from './s3-config.service';
import { SendgridConfigService } from './sendgrid-config.service';
import { StripeConfigService } from './stripe-config.service';
import { PaymentProviderConfigService } from './payment-provider-config.service';
import { Web3ConfigService } from './web3-config.service';
import { SlackConfigService } from './slack-config.service';
import { VisionConfigService } from './vision-config.service';
Expand All @@ -23,7 +23,7 @@ import { VisionConfigService } from './vision-config.service';
DatabaseConfigService,
Web3ConfigService,
S3ConfigService,
StripeConfigService,
PaymentProviderConfigService,
SendgridConfigService,
CvatConfigService,
PGPConfigService,
Expand All @@ -38,7 +38,7 @@ import { VisionConfigService } from './vision-config.service';
DatabaseConfigService,
Web3ConfigService,
S3ConfigService,
StripeConfigService,
PaymentProviderConfigService,
SendgridConfigService,
CvatConfigService,
PGPConfigService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export const envValidator = Joi.object({
S3_BUCKET: Joi.string(),
S3_USE_SSL: Joi.string(),
// Stripe
STRIPE_SECRET_KEY: Joi.string().required(),
STRIPE_API_VERSION: Joi.string(),
STRIPE_APP_NAME: Joi.string(),
STRIPE_APP_VERSION: Joi.string(),
STRIPE_APP_INFO_URL: Joi.string(),
PAYMENT_PROVIDER_SECRET_KEY: Joi.string().required(),
PAYMENT_PROVIDER_API_VERSION: Joi.string(),
PAYMENT_PROVIDER_APP_NAME: Joi.string(),
PAYMENT_PROVIDER_APP_VERSION: Joi.string(),
PAYMENT_PROVIDER_APP_INFO_URL: Joi.string(),
// SendGrid
SENDGRID_API_KEY: Joi.string().required(),
SENDGRID_FROM_EMAIL: Joi.string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class PaymentProviderConfigService {
constructor(private configService: ConfigService) {}

/**
* The secret key used for authenticating requests to the payment providers API.
* Required
*/
get secretKey(): string {
return this.configService.getOrThrow<string>('PAYMENT_PROVIDER_SECRET_KEY');
}

/**
* The version of the payment providers to use for requests.
* Default: '2022-11-15'
*/
get apiVersion(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_API_VERSION',
'2022-11-15',
);
}

/**
* The name of the application interacting with the payment providers API.
* Default: 'Fortune'
*/
get appName(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_APP_NAME',
'Fortune',
);
}

/**
* The version of the application interacting with the payment providers API.
* Default: '0.0.1'
*/
get appVersion(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_APP_VERSION',
'0.0.1',
);
}

/**
* The URL of the application's information page.
* Default: 'https://hmt.ai'
*/
get appInfoURL(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_APP_INFO_URL',
'https://hmt.ai',
);
}
}

This file was deleted.

6 changes: 0 additions & 6 deletions packages/apps/job-launcher/server/src/common/enums/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export enum PaymentStatus {
SUCCEEDED = 'succeeded',
}

export enum StripePaymentStatus {
CANCELED = 'canceled',
REQUIRES_PAYMENT_METHOD = 'requires_payment_method',
SUCCEEDED = 'succeeded',
}

export enum PaymentSortField {
CREATED_AT = 'created_at',
AMOUNT = 'amount',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RenameStripeCustomerIdColumn1749498615107 implements MigrationInterface {

name = 'RenameStripeCustomerIdColumn1749498615107';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "hmt"."users"
RENAME COLUMN "stripe_customer_id" TO "payment_provider_id"
`);
await queryRunner.query(`
ALTER TABLE "hmt"."users"
RENAME CONSTRAINT "UQ_5ffbe395603641c29e8ce9b4c97" TO "UQ_721ffe5f6051eb5c6ac35321213"
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "hmt"."users"
RENAME CONSTRAINT "UQ_721ffe5f6051eb5c6ac35321213" TO "UQ_5ffbe395603641c29e8ce9b4c97"
`);
await queryRunner.query(`
ALTER TABLE "hmt"."users"
RENAME COLUMN "payment_provider_id" TO "stripe_customer_id"
`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe('JobService', () => {
const fortuneJobDto: JobFortuneDto = createFortuneJobDto();
await expect(
jobService.createJob(
createUser({ stripeCustomerId: null }),
createUser({ paymentProviderId: null }),
FortuneJobType.FORTUNE,
fortuneJobDto,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ export class JobService {
const whitelisted = await this.whitelistService.isUserWhitelisted(user.id);
if (!whitelisted) {
if (
!user.stripeCustomerId ||
!user.paymentProviderId ||
!(await this.paymentService.getDefaultPaymentMethod(
user.stripeCustomerId,
user.paymentProviderId,
))
)
throw new ValidationError(ErrorJob.NotActiveCard);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import { PaymentEntity } from './payment.entity';
import { PaymentStatus, VatType } from '../../common/enums/payment';

export interface ListResult {
entities: PaymentEntity[];
itemCount: number;
}

export interface PaymentMethod {
id: string;
brand: string;
last4: string;
expMonth: number;
expYear: number;
default: boolean;
}

export interface BillingAddress {
line1?: string;
city?: string;
country?: string;
postalCode?: string;
}

export interface CustomerData {
email: string;
name?: string;
address?: BillingAddress;
defaultPaymentMethod?: string;
}

export interface TaxId {
id: string;
type: VatType;
value: string;
}

export interface Invoice {
id: string;
paymentId: string | null;
status?: string;
amountDue: number;
currency: string;
}

export interface CardSetup {
customerId: string;
paymentMethod: string;
}

export interface PaymentData {
customer: string;
id: string;
clientSecret: string | null;
status: PaymentStatus | null;
amount: number;
amountReceived: number;
currency: string;
latestCharge: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { UserEntity } from '../user/user.entity';
import { JobRepository } from '../job/job.repository';
import { UserRepository } from '../user/user.repository';
import { RateModule } from '../rate/rate.module';
import { StripeService } from './providers/stripe/stripe.service';
import { PaymentProvider } from './providers/payment-provider.abstract';

@Module({
imports: [
Expand All @@ -39,7 +41,16 @@ import { RateModule } from '../rate/rate.module';
}),
],
controllers: [PaymentController],
providers: [PaymentService, PaymentRepository, JobRepository, UserRepository],
providers: [
PaymentService,
PaymentRepository,
JobRepository,
UserRepository,
{
provide: PaymentProvider,
useClass: StripeService,
},
],
exports: [PaymentService, PaymentRepository],
})
export class PaymentModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DataSource, In, LessThan, MoreThan } from 'typeorm';
import { PaymentStatus } from '../../common/enums/payment';
import { BaseRepository } from '../../database/base.repository';
import { PaymentEntity } from './payment.entity';
import { ListResult } from '../payment/payment.interface';
import { ListResult } from './payment.interface';
import { GetPaymentsDto } from './payment.dto';
import { convertToDatabaseSortDirection } from '../../database/database.utils';

Expand Down
Loading
Loading