Skip to content

Commit

Permalink
Merge pull request #10 from lalithkota/develop
Browse files Browse the repository at this point in the history
Modified GCTB according to change on Common G2PConnect Module
  • Loading branch information
shibu-narayanan authored Dec 22, 2023
2 parents 3bcf9ba + 2e6fc19 commit 8b0cb10
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 95 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN groupadd -g ${container_user_gid} ${container_user_group} \

WORKDIR /app

RUN install_packages libpq-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives

RUN chown -R ${container_user}:${container_user_group} /app
USER ${container_user}

Expand Down
Empty file.
18 changes: 18 additions & 0 deletions db_scripts/0.1.0/ddl/02.tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE payment_list (
id integer NOT NULL,
batch_id character varying NOT NULL,
request_id character varying NOT NULL,
request_timestamp timestamp without time zone NOT NULL,
from_fa character varying,
to_fa character varying NOT NULL,
amount character varying NOT NULL,
currency character varying NOT NULL,
status character varying(4) NOT NULL,
file character varying,
error_code character varying(27),
error_msg character varying,
backend_name character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
active boolean NOT NULL
);
9 changes: 9 additions & 0 deletions db_scripts/0.1.0/ddl/03.sequences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE SEQUENCE payment_list_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE payment_list_id_seq OWNED BY payment_list.id;
1 change: 1 addition & 0 deletions db_scripts/0.1.0/ddl/04.defaults.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE ONLY payment_list ALTER COLUMN id SET DEFAULT nextval('payment_list_id_seq'::regclass);
2 changes: 2 additions & 0 deletions db_scripts/0.1.0/ddl/05.constraints.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE ONLY payment_list
ADD CONSTRAINT payment_list_pkey PRIMARY KEY (id);
Empty file.
25 changes: 25 additions & 0 deletions db_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Database Initialization Scripts

### PostgreSQL

- Create a new role/user called "gctbuser" and create a new database called "gctbdb",
with "gctbuser" as the owner.
No need to run this step if Postgres was installed through openg2p's deployment script.
```sql
CREATE ROLE gctbuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'xxxxxx';
CREATE DATABASE gctbdb WITH OWNER = gctbuser CONNECTION LIMIT = -1;
```
- Then run
```sh
DB_HOST="openg2p.sandbox.net" \
DB_USER_PASSWORD="xxxxxx" \
./deploy.sh
```
- The following optional Env vars can also be passed:
- `VERSION="1.0.0"` Do not set this if you want latest version.
- `DB_PORT="5432"` Default is 5432.
- `DB_NAME="mydb"` Default is gctbdb.
- `DB_USER="myuser"` Default is gctbuser.
- `DEPLOY_DDL="false"` Default is true. If false, will not run DDL scripts.
- `DEPLOY_DML="false"` Default is true. If false, will not run DML scripts.
- `LOG_DB_QUERY="true"` Default is false. Logs all Db queries.
86 changes: 86 additions & 0 deletions db_scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

echoerr() {
echo "$@" 1>&2
}

get_scripts_path() {
dirname "$0"
}

get_default_version() {
basename $(ls -d1 $(get_scripts_path)/*/ | tail -n 1)
}

execute_script_in_folder() {
folder_path=$1
for file in $folder_path/* ; do
if [ -d "$file" ]; then
execute_script_in_folder $file
elif [[ $file == *.sh ]]; then
bash $file
elif [[ $file == *.sql || $file == *.psql ]]; then
if [[ $LOG_DB_QUERY == "true" ]]; then
PGPASSWORD="$DB_USER_PASSWORD" \
psql \
-h $DB_HOST \
-p $DB_PORT \
-d $DB_NAME \
-U $DB_USER \
-a -c "$(envsubst < $file)"
else
PGPASSWORD="$DB_USER_PASSWORD" \
psql \
-h $DB_HOST \
-p $DB_PORT \
-d $DB_NAME \
-U $DB_USER \
-c "$(envsubst < $file)"
fi
fi
done
}

if [ -z "$VERSION" ]; then
export VERSION=$(get_default_version)
else
export VERSION="${VERSION%/}"
fi
if [ -z "$DB_HOST" ]; then
echoerr "DB_HOST not given!"
exit 1
fi
if [ -z "$DB_PORT" ]; then
export DB_PORT=5432
fi
if [ -z "$DB_NAME" ]; then
export DB_NAME="gctbdb"
fi
if [ -z "$DB_USER" ]; then
export DB_USER="gctbuser"
fi
if [ -z "$DB_USER_PASSWORD" ]; then
echoerr "DB_USER_PASSWORD not given!"
exit 1
fi
if [ -z "$DEPLOY_DDL" ]; then
export DEPLOY_DDL="true"
fi
if [ -z "$DEPLOY_DML" ]; then
export DEPLOY_DML="true"
fi
if [ -z "$LOG_DB_QUERY" ]; then
export LOG_DB_QUERY="false"
fi

if ! [ -d "$(get_scripts_path)/$VERSION" ]; then
echoerr "Given Version not found!"
exit 1;
fi

if [[ "$DEPLOY_DDL" == "true" ]]; then
execute_script_in_folder $(get_scripts_path)/$VERSION/ddl
fi
if [[ "$DEPLOY_DML" == "true" ]]; then
execute_script_in_folder $(get_scripts_path)/$VERSION/dml
fi
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@
from pydantic import BaseModel, model_validator


class PayerFaPayeeFaMapping(BaseModel):
order: int
"""
Order of payer fa mapping
"""

regex: str
"""
regex to match the payee fa
"""

payer_fa: str
"""
Payer Fa , if the payee fa matches the given regex
"""


class FaBackendMapping(BaseModel):
order: int
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ def __init__(self, **kwargs):
)

async def disburse_sync_disburse(self, request: DisburseHttpRequest):
"""
Make a disbursement request. (G2P Connect compliant API - sync).
- This API does NOT perform the entire disursement process synchronously.
It only receives the disbubrsement request and returns acknowledgement synchronously.
Use the status API to get the actual status of disbursement.
- The payee_fa field in message->disbursements[] can either be FA or ID of the payee,
depending on the bridge configuration.
- If bridge is configured to receive ID in payee_fa, then the bridge will translate ID
to FA using a G2P Connect ID Mapper before making payment
(Depends on the payment backend).
- The payer_fa field in message->disbursements[] is optional in this impl of bridge.
If payer_fa is not given, the bridge will take the default values configured
(Depends on the payment backend).
"""
# Perform any extra validations here
if not request.message.transaction_id:
request.message.transaction_id = str(uuid.uuid4())
Expand Down Expand Up @@ -83,6 +97,22 @@ async def process_disbursement():
)

async def disburse_sync_txn_status(self, request: DisburseTxnStatusHttpRequest):
"""
Get status of a disbursement request. (G2P Connect compliant API - sync).
- The current supported value for txn_type in message->txnstatus_request is "disburse".
- The current supported values for attribute_type in message->txnstatus_request are
"transaction_id" and "reference_id_list".
- To get the status of a particular transaction, pass attribute_type as "transaction_id".
Then attribute_value in message->txnstatus_request expects a transaction id (string).
- To get the status of individual payments within transactions, pass attribute_type is
"reference_id_list".
Then attribute_value in message->txnstatus_request expects a list of reference
ids (payment ids, list of strings).
Errors:
- Code: GCTB-PMS-350. HTTP: 400. Message: attribute_value is supposed to be a string.
- Code: GCTB-PMS-350. HTTP: 400. Message: attribute_value is supposed to be a list.
"""
disburse_status_response = await self.payment_multiplexer.disbursement_status(
request.message
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@


class IdTranslateService(BaseService):
async def translate(self, ids: List[str]) -> List[str]:
async def translate(self, ids: List[str], **kwargs) -> List[str]:
"""
Get an ID and return it.
This method should be implemented in concrete subclasses.
"""
raise NotImplementedError()

def translate_sync(self, ids: List[str], **kwargs) -> List[str]:
"""
Get an ID and return it.
This method should be implemented in concrete subclasses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
value: http://gctb-mojaloop-sdk-payment-backend.gctb/internal/callback/mapper
- name: GCTB_ID_TRANSLATE_MAPPER_RESOLVE_URL
value: http://mapper.spar/v0.1.0/mapper/resolve
- name: GCTB_ID_TRANSLATE_QUEUE_REDIS_HOST
value: gctb-redis-master
- name: GCTB_MOJALOOP_SDK_TRANSFER_URL
value: http://ml-simulators-sim-dfsp1-scheme-adapter.ml:4001/transfers
- name: GCTB_MOJALOOP_SDK_PAYER_ID_VALUE
Expand All @@ -48,25 +50,25 @@ spec:
name: http
protocol: TCP
livenessProbe:
failureThreshold: 5
failureThreshold: 2
httpGet:
path: /ping
port: 8000
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 60
initialDelaySeconds: 5
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 1
readinessProbe:
failureThreshold: 20
failureThreshold: 2
httpGet:
path: /ping
port: 8000
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 30
initialDelaySeconds: 2
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
timeoutSeconds: 1
volumeMounts:
- name: payment-backend-scripts
mountPath: /app/payment_backend
Expand Down
Loading

0 comments on commit 8b0cb10

Please sign in to comment.