Skip to content

Commit

Permalink
Merge pull request #166 from poozlehq/159-stripe
Browse files Browse the repository at this point in the history
New integration: Stripe
  • Loading branch information
saimanoj authored Aug 26, 2023
2 parents ccbbd13 + 31a6820 commit 4aa4484
Show file tree
Hide file tree
Showing 56 changed files with 5,179 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENGINE_VERSION=0.1.7-alpha
ENGINE_VERSION=0.1.8-alpha

# POSTGRES
POSTGRES_USER=docker
Expand Down
4 changes: 2 additions & 2 deletions engine-idk/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@poozle/engine-idk",
"version": "0.1.44",
"version": "0.1.45",
"description": "Used to develop integrations for Poozle",
"license": "MIT",
"author": "Poozle <[email protected]>",
"main": "./idk/index.js",
"module": "./idk/index.esm.js",
"keywords": [],
"keywords": [ ],
"scripts": {
"build": "rollup -c",
"lint": "eslint --ext js,ts,tsx src",
Expand Down
1 change: 1 addition & 0 deletions engine-idk/src/common_models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './ticketing';
export * from './mail';
export * from './documentation';
export * from './calendar';
export * from './payments';
90 changes: 90 additions & 0 deletions engine-idk/src/common_models/payments/charges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

export interface Address {
city: string;
country: string;
line1: string;
line2: string;
postal_code: number;
}

export interface BillingDetails {
address: Address;
email: string;
name: string;
phone: string;
}

export interface PaymentMethod {
type: PaymentMethodType;
details: PaymentDetails;
}

export interface PaymentDetails {
[key: string]: any;
}

export interface Outcome {
network_status: string;
reason: string;
risk_level: string;
seller_message: string;
type: string;
}

export interface Charge {
id: string;
amount: string;
amount_refunded: string;
application: string;
application_fee_amount: string;
billing_details: BillingDetails;
captured: boolean;
created_at: string;
currency: string;
description: string;
disputed: boolean;
failure_code: string;
failure_message: string;
invoice: string;
metadata: any;
outcome: Outcome;
paid: boolean;
payment_method: PaymentMethod;
email: string;
contact: string;
status: PaymentMethodStatus;
}

export enum PaymentMethodType {
ach_credit_transfer = 'ach_credit_transfer',
ach_debit = 'ach_debit',
acss_debit = 'acss_debit',
alipay = 'alipay',
au_becs_debit = 'au_becs_debit',
bancontact = 'bancontact',
card = 'card',
card_present = 'card_present',
eps = 'eps',
giropay = 'giropay',
ideal = 'ideal',
klarna = 'klarna',
multibanco = 'multibanco',
p24 = 'p24',
sepa_debit = 'sepa_debit',
sofort = 'sofort',
stripe_account = 'stripe_account',
wechat = 'wechat',
netbank = 'netbank',
wallet = 'wallet',
emi = 'emi',
upi = 'upi',
}

export enum PaymentMethodStatus {
created = 'created',
authorized = 'authorized',
succeeded = 'succeeded',
refunded = 'refunded',
failed = 'failed',
}
75 changes: 75 additions & 0 deletions engine-idk/src/common_models/payments/disputes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

export interface Dispute {
id: string;
amount: string;
charge_id: string;
currency: string;
reason: string;
evidence: Evidence;
status: string;
priority: string;
is_charge_refundable: boolean;
created_at: string;
}

export interface Evidence {
access_activity_log: string;
billing_address: string;
cancellation_policy: string[];
cancellation_policy_disclosure: string;
cancellation_rebuttal: string;
customer_communication: string[];
customer_email_address: string;
customer_name: string;
customer_purchase_ip: string;
customer_signature: string[];
duplicate_charge_documentation: string[];
duplicate_charge_explanation: string;
duplicate_charge_id: string;
product_description: string;
receipt: string[];
refund_policy: string[];
refund_policy_disclosure: string;
refund_refusal_explanation: string;
service_date: string;
service_documentation: string[];
shipping_address: string;
shipping_carrier: string;
shipping_date: string;
shipping_documentation: string[];
shipping_tracking_number: string;
uncategorized_file: string[];
uncategorized_text: string;
due_by: string;
has_evidence: boolean;
past_due: boolean;
submission_count: string;
}

export enum DisputeReason {
bank_cannot_process = 'bank_cannot_process',
check_returned = 'check_returned',
credit_not_processed = 'credit_not_processed',
customer_initiated = 'customer_initiated',
debit_not_authorized = 'debit_not_authorized',
duplicate = 'duplicate',
fraudulent = 'fraudulent',
general = 'general',
incorrect_account_details = 'incorrect_account_details',
insufficient_funds = 'insufficient_funds',
product_not_received = 'product_not_received',
product_unacceptable = 'product_unacceptable',
subscription_canceled = 'subscription_canceled',
unrecognize = 'unrecognize',
}

export enum DisputeStatus {
warning_needs_response = 'warning_needs_response',
warning_under_review = 'warning_under_review',
warning_closed = 'warning_closed',
needs_response = 'needs_response',
under_review = 'under_review',
won = 'won',
lost = 'lost',
}
4 changes: 4 additions & 0 deletions engine-idk/src/common_models/payments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

export * from './charges';
export * from './disputes';
2 changes: 1 addition & 1 deletion engine-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@nestjs/swagger": "^6.3.0",
"@paciolan/remote-module-loader": "^3.0.2",
"@poozle/engine-edk": "^0.2.0",
"@poozle/engine-idk": "^0.1.43",
"@poozle/engine-idk": "^0.1.45",
"@prisma/client": "^4.9.0",
"@temporalio/client": "^1.8.1",
"@vegardit/prisma-generator-nestjs-dto": "^1.5.1",
Expand Down
1 change: 1 addition & 0 deletions engine-server/prisma/dbml/schema.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Enum IntegrationType {
ACCOUNTING
ATS
STORAGE
PAYMENTS
}

Ref: Workspace.userId > User.userId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "IntegrationType" ADD VALUE 'PAYMENTS';
1 change: 1 addition & 0 deletions engine-server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,5 @@ enum IntegrationType {
ACCOUNTING
ATS
STORAGE
PAYMENTS
}
50 changes: 44 additions & 6 deletions engine-server/src/common/knex/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function getBaseQuery<T>(
where: Record<string, string>,
SELECT_KEYS: string[],
raw: boolean,
join?: Record<string, string | string[]>,
) {
const knex = Knex({
client: 'pg',
Expand All @@ -24,12 +25,29 @@ export function getBaseQuery<T>(
},
});

const query = knex
let query = knex
.withSchema(workspaceName)
.table<T>(table)
.select(getSelectKeys(SELECT_KEYS, raw))
.where(where);

if (join) {
const joinSelectedKeys = join.selectedKeys as string[];
query = query
.leftJoin(
join.tableName as string,
`${join.tableName}.${join.joinColumn}`,
`${table}.${join.sourceColumn}`,
)
.select(
knex.raw(
`json_build_object(${joinSelectedKeys
.map((key: any) => `'${key}', ${join.tableName}.${key}`)
.join(', ')}) as ${join.selectedColumnName}`,
),
);
}

return query;
}

Expand Down Expand Up @@ -60,25 +78,45 @@ export async function getObjectFromDb(
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function applyDateFilter(query: any, queryParams: any) {
export function applyDateFilter(
query: any,
queryParams: any,
databaseName: string,
) {
// Conditionally apply the created_after filter if not null
if (queryParams.created_after) {
query = query.where('created_at', '>=', queryParams.created_after);
query = query.where(
`${databaseName}.created_at`,
'>=',
queryParams.created_after,
);
}

// Conditionally apply the created_before filter if not null
if (queryParams.created_before) {
query = query.where('created_at', '<=', queryParams.created_before);
query = query.where(
`${databaseName}.created_at`,
'<=',
queryParams.created_before,
);
}

// Conditionally apply the updated_after filter if not null
if (queryParams.updated_after) {
query = query.where('updated_at', '>=', queryParams.updated_after);
query = query.where(
`${databaseName}.updated_at`,
'>=',
queryParams.updated_after,
);
}

// Conditionally apply the updated_before filter if not null
if (queryParams.updated_before) {
query = query.where('updated_at', '<=', queryParams.updated_before);
query = query.where(
`${databaseName}.updated_at`,
'<=',
queryParams.updated_before,
);
}

return query;
Expand Down
2 changes: 2 additions & 0 deletions engine-server/src/modules/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { WorkspaceModule } from 'modules/workspace/workspace.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CalendarModule } from 'modules/categories/calendar/calendar.module';
import { PaymentsModule } from 'modules/categories/payments/payment.module';

@Module({
imports: [
Expand All @@ -49,6 +50,7 @@ import { CalendarModule } from 'modules/categories/calendar/calendar.module';
MailModule,
DocumentationModule,
CalendarModule,
PaymentsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/** Copyright (c) 2023, Poozle, all rights reserved. **/

import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { IntegrationType } from '@prisma/client';

import { IntegrationAccount } from '@@generated/integrationAccount/entities';

import { GetIntegrationAccount } from 'common/decorators/integration_account.decorator';

import { AuthGuard } from 'modules/auth/auth.guard';

import {
ChargeQueryParams,
GetChargeQueryParams,
PathParamsWithChargeId,
ChargeResponse,
ChargesResponse,
} from './charge.interface';
import { ChargeService } from './charge.service';

@Controller({
version: '1',
path: 'payments/charges',
})
@ApiTags('Payments')
export class ChargeController {
constructor(private chargeService: ChargeService) {}

@Get()
@UseGuards(new AuthGuard())
async getCharges(
@Query() query: ChargeQueryParams,
@GetIntegrationAccount(IntegrationType.PAYMENTS)
integrationAccount: IntegrationAccount,
): Promise<ChargesResponse> {
const chargeResponse = await this.chargeService.getCharges(
integrationAccount,
query,
);

return chargeResponse;
}

@Get(':charge_id')
async getCharge(
@Query() query: GetChargeQueryParams,
@Param()
params: PathParamsWithChargeId,
@GetIntegrationAccount(IntegrationType.PAYMENTS)
integrationAccount: IntegrationAccount,
): Promise<ChargeResponse> {
const chargeResponse = await this.chargeService.getCharge(
integrationAccount,
query,
params,
);

return chargeResponse;
}
}
Loading

0 comments on commit 4aa4484

Please sign in to comment.