Skip to content

Commit

Permalink
Merge pull request #2 from T9404/feature/payment-gate-integration
Browse files Browse the repository at this point in the history
Feature/payment gate integration
  • Loading branch information
T9404 authored Mar 16, 2024
2 parents 7fe3968 + 7d1dca9 commit d11b5d9
Show file tree
Hide file tree
Showing 168 changed files with 4,144 additions and 189 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ POSTGRES_PASSWORD=123
POSTGRES_DRIVER=org.postgresql.Driver

ORIGINATION_DB_NAME=origination
PRODUCT_ENGINE_DB_NAME=fintech-company
PRODUCT_ENGINE_DB_NAME=product-engine
PAYMENT_GATE_DB_NAME=payment-gate
MERCHANT_DB_NAME=merchant
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
branches:
- master
- origination-implement
- feature/payment-gate-integration
push:
branches:
- master
- origination-implement
- feature/payment-gate-integration

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ WORKDIR /api

COPY /build/libs/*.jar api.jar

EXPOSE ${API_PORT}

CMD ["java", "-jar", "api.jar"]
6 changes: 3 additions & 3 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
server:
port: 8083
port: ${API_PORT:8083}

api:
client:
origination:
grpc:
host: ${ORIGINATION_GRPC_HOST}
port: ${ORIGINATION_GRPC_PORT}
host: ${ORIGINATION_GRPC_HOST:localhost}
port: ${ORIGINATION_GRPC_PORT:9094}
97 changes: 76 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ services:
image: postgres:latest
restart: always
environment:
- POSTGRES_MULTIPLE_DATABASES=${ORIGINATION_DB_NAME},"${PRODUCT_ENGINE_DB_NAME}"
- POSTGRES_MULTIPLE_DATABASES=${ORIGINATION_DB_NAME},"${PRODUCT_ENGINE_DB_NAME}","${PAYMENT_GATE_DB_NAME}",${MERCHANT_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- '5433:5432'
- '5432:5432'
volumes:
- ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
- ./postgres-data8:/var/lib/postgresql/data8
- ./create-multiple-postgresql-databases.sh:/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh
networks:
- fintech-network

product-engine:
image: docker-image-product-engine
image: product-engine:latest
build:
context: product-engine
dockerfile: ./Dockerfile
restart: always
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${PRODUCT_ENGINE_DB_NAME}
- SPRING_DATASOURCE_USERNAME=${POSTGRES_USER}
- SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD}
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=${POSTGRES_DRIVER}
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=${PRODUCT_ENGINE_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PRODUCT_ENGINE_PORT=8086
- PRODUCT_ENGINE_GRPC_PORT=9091
ports:
- '8086:8086'
- '9091:9091'
Expand All @@ -36,18 +39,49 @@ services:
networks:
- fintech-network

merchant-provider:
image: merchant-provider:latest
build:
context: merchant-provider
dockerfile: ./Dockerfile
restart: always
environment:
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=${MERCHANT_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PAYMENT_GATE_HOST=payment-gate
- PAYMENT_GATE_PORT=8088
- PAYMENT_GATE_SCHEME=http
- MERCHANT_PROVIDER_PORT=8082
ports:
- '8082:8082'
depends_on:
- db
networks:
- fintech-network

origination:
image: docker-image-origination
image: origination:latest
build:
context: origination
dockerfile: ./Dockerfile
restart: always
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${ORIGINATION_DB_NAME}
- SPRING_DATASOURCE_USERNAME=${POSTGRES_USER}
- SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD}
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=${POSTGRES_DRIVER}
- GRPC_CLIENT_GRPC_SERVER_ADDRESS=static://scoring:9095
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=${ORIGINATION_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- GRPC_SCORING_HOST=scoring
- GRPC_SCORING_PORT=9095
- GRPC_PAYMENT_GATE_HOST=payment-gate
- GRPC_PAYMENT_GATE_PORT=9097
- GRPC_PRODUCT_ENGINE_HOST=product-engine
- GRPC_PRODUCT_ENGINE_PORT=9091
- ORIGINATION_PORT=8084
- ORIGINATION_GRPC_PORT=9094
ports:
- '8084:8084'
- '9094:9094'
Expand All @@ -57,43 +91,64 @@ services:
- fintech-network

payment-gate:
image: docker-image-payment-gate
image: payment-gate:latest
build:
context: payment-gate
dockerfile: ./Dockerfile
restart: always
environment:
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=${PAYMENT_GATE_DB_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- PRODUCT_ENGINE_GRPC_HOST=product-engine
- PRODUCT_ENGINE_GRPC_PORT=9091
- ORIGINATION_GRPC_HOST=origination
- ORIGINATION_GRPC_PORT=9094
- MERCHANT_PROVIDER_HOST=merchant-provider
- MERCHANT_PROVIDER_PORT=8082
- MERCHANT_PROVIDER_SCHEME=http
- PAYMENT_GATE_PORT=8088
- PAYMENT_GATE_GRPC_PORT=9097
- BANK_IDENTIFICATION_NUMBER=TIN7710140671
- BACKOFF_BASE_TIME_MINUTES=10
- BACKOFF_MAX_ATTEMPTS=10
ports:
- '8080:8080'
- '8088:8088'
- '9097:9097'
depends_on:
- db
networks:
- fintech-network

api:
image: docker-image-api
image: api:latest
build:
context: api
dockerfile: ./Dockerfile
restart: always
environment:
- ORIGINATION_GRPC_HOST=origination
- ORIGINATION_GRPC_PORT=9094
- API_PORT=8083
ports:
- '8083:8083'
networks:
- fintech-network

scoring:
image: docker-image-scoring
image: scoring:latest
build:
context: scoring
dockerfile: ./Dockerfile
restart: always
environment:
- PRODUCT_ENGINE_GRPC_HOST=product-engine
- PRODUCT_ENGINE_GRPC_PORT=9091
- GRPC_CLIENT_GRPC_SERVER_ADDRESS=static://product-engine:9091
- GRPC_HOST_PRODUCT_ENGINE=product-engine
- GRPC_PORT_PRODUCT_ENGINE=9091
- SERVER_PORT=8087
- SERVER_PORT_GRPC=9095
- LATE_PAYMENT_THRESHOLD_DAYS=7
ports:
- '8087:8087'
- '9095:9095'
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ postgresql = { module = "org.postgresql:postgresql" }
postgresql-driver = { module = "org.postgresql:postgresql", version = "42.6.0" }
validation = { module = "org.springframework.boot:spring-boot-starter-validation", version.ref = "spring-boot" }
liquibase-core = { module = "org.liquibase:liquibase-core" }
slf4j = { module = "org.slf4j:slf4j-api", version = "1.7.25" }
jdbc = { module = "org.springframework.boot:spring-boot-starter-data-jdbc" }
webflux = { module = "org.springframework.boot:spring-boot-starter-webflux" }

grpc-netty-shaded = { module = "io.grpc:grpc-netty-shaded", version.ref = "grpc" }
grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" }
Expand All @@ -51,3 +52,4 @@ jupiter-testcontainers = { module = "org.testcontainers:junit-jupiter", version
postgresql-testcontainers = { module = "org.testcontainers:postgresql" }
h2database = { module = "com.h2database:h2", version.ref = "h2" }
grps-test = { module = "io.grpc:grpc-testing", version.ref = "grpc" }
rest-assured = { module = "io.rest-assured:rest-assured" }
2 changes: 1 addition & 1 deletion create-multiple-postgresql-databases.sh → init-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
create_user_and_database $db
done
echo "Multiple databases created"
fi
fi
9 changes: 9 additions & 0 deletions merchant-provider/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:17-ea-22-jdk-oracle

WORKDIR /merchant-provider

COPY /build/libs/*.jar merchant-provider.jar

EXPOSE ${MERCHANT_PROVIDER_PORT}

CMD ["java", "-jar", "merchant-provider.jar"]
33 changes: 33 additions & 0 deletions merchant-provider/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
alias(libs.plugins.spring)
alias(libs.plugins.spring.dependency.management)
alias(libs.plugins.liquibase.gradle)
}

repositories {
mavenCentral()
}

dependencies {
implementation libs.spring.web
implementation libs.jdbc
implementation libs.liquibase.core
liquibaseRuntime libs.postgresql
runtimeOnly libs.postgresql

compileOnly libs.lombok
annotationProcessor libs.lombok

implementation libs.webflux

testImplementation libs.jupiter
testImplementation libs.spring.boot.starter.test
testImplementation libs.testcontainers
testImplementation libs.jupiter.testcontainers
testImplementation libs.postgresql.testcontainers
testImplementation libs.rest.assured
}

test {
useJUnitPlatform()
}
24 changes: 24 additions & 0 deletions merchant-provider/doc/MerchantProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Merchant Provider

## Overview

The Merchant Provider (MP) is responsible for managing payment methods.
It is also responsible for the disbursement and receipt of funds for merchant.
The MP is responsible for both sending money to merchants and accepting payments through a Payment Provider.

MP utilizes gRPC for seamless communication with the Payment Engine. You can find a contract in `src/main/proto`

## Architecture Overview

Link to the architecture diagram: [Architecture Diagram](https://miro.com/app/board/uXjVNWFTMec=/?share_link_id=279324309467)


## Folder Structure

Following a [hybrid]((https://priyalwalpita.medium.com/software-architecture-patterns-layered-architecture-a3b89b71a057)) (layered) architecture.

## Dependencies

All dependencies used by the project can be found in the `build.gradle` files (both in the root and this module).

You can find the versions of the dependencies in the `gradle/libs.versions.toml` in the root.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.academy.fintech.mp;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.netty.NettyAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication(
exclude = {
GsonAutoConfiguration.class,
MultipartAutoConfiguration.class,
WebSocketServletAutoConfiguration.class,
NettyAutoConfiguration.class,
}
)
public class MerchantProviderApplication {

public static void main(String[] args) {
new SpringApplicationBuilder(MerchantProviderApplication.class)
.beanNameGenerator(new FullyQualifiedAnnotationBeanNameGenerator())
.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.academy.fintech.mp.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class WebClientConfig {

@Bean
public WebClient webClient() {
return WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.academy.fintech.mp.core.common;

import lombok.Getter;

@Getter
public class BusinessException extends RuntimeException {
private final EventInfo eventInfo;

public BusinessException(EventInfo eventInfo, String message) {
super(message);
this.eventInfo = eventInfo;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.academy.fintech.mp.core.common;

import org.slf4j.event.Level;
import org.springframework.http.HttpStatus;

public interface EventInfo {
HttpStatus getStatus();

Level getLevel();
}

Loading

0 comments on commit d11b5d9

Please sign in to comment.