Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snd 675 connect usct backend to a new version of mifos #53

Merged
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
31 changes: 16 additions & 15 deletions docs/data-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ The data model is described in the diagram.


## Beneficiaries
| Name | Type | Modifiers | Description |
|:------------------------------|:----------------------:|:----------|:--------------------------------:|
| id [PK] | integer | NOT NULL | Primary key |
| person_id [FK] | integer | NOT NULL | foundational id forign key |
| package_id [FK] | integer | NOT NULL | Package id forign key |
| payment_status | character varying(255) | NOT NULL | [Payment status](status.md) |
| functional_id | character varying(255) | NOT NULL | Functional id of the beneficiary |
| payment_onboarding_status | character varying(255) | NOT NULL | Onboarding request status. |
| payment_onboarding_request_id | character varying(255) | NOT NULL | Onboarding request id. |
| Name | Type | Modifiers | Description |
|:------------------------------|:----------------------:|:----------|:------------------------------------------------------:|
| id [PK] | integer | NOT NULL | Primary key |
| person_id [FK] | integer | NOT NULL | foundational id forign key |
| package_id [FK] | integer | NOT NULL | Package id forign key |
| payment_status | character varying(255) | NOT NULL | [Payment status](status.md) |
| functional_id | character varying(255) | NOT NULL | Public version of the foundation id. [More information](https://govstack-global.atlassian.net/wiki/spaces/GH/pages/239370263/Authentication+and+Cross-BB+Authorization) |
| payment_onboarding_status | character varying(255) | NOT NULL | Onboarding request status. |
| payment_onboarding_request_id | character varying(255) | NOT NULL | Onboarding request id. |

## Candidates

| Name | Type | Modifiers | Description |
|:--------------------|:-------------:|:----------|:--------------------------------------------:|
| id [PK] | integer | NOT NULL | Primary key |
| person_id [FK] | integer | | |
| openimis_package_id | integer array | | Ids of [packages](packages.md) from OpenIMIS |
| emulator_package_id | integer array | | Ids of [packages](packages.md) from emulator |
| Name | Type | Modifiers | Description |
|:--------------------|:-------------:|:-----------------|:--------------------------------------------------:|
| id [PK] | integer | NOT NULL | Primary key |
| person_id [FK] | integer | | |
| openimis_package_id | integer array | | Ids of [packages](packages.md) from OpenIMIS |
| emulator_package_id | integer array | | Ids of [packages](packages.md) from emulator |
| is_beneficiary | boolean | NOT NULL | Status changes when candidate become a beneficiary |


## Payment Disbursement
Expand Down
157 changes: 147 additions & 10 deletions docs/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is a driver backend application for

## Application logic

### Enrollment officer sequence of steps

```mermaid
sequenceDiagram
Civil servant ->> USCT-backend: Sign in
Expand All @@ -23,12 +25,21 @@ sequenceDiagram
USCT-backend ->>Consent BB: Civil servant may apply for consent
end
Civil servant ->> USCT-backend: When consent record is in place, create new beneficiary and remove beneficiary from candidates list
USCT-backend ->> Payment BB: Automatically register beneficiary in payment system if not registered
USCT-backend ->> Payment BB: Automatically update beneficiary in payment system if registered
Civil servant ->> USCT-backend: Order payment
USCT-backend ->> Payment BB: Automatically validate prepayment
USCT-backend ->> Payment BB: Automatically make bulk payment
USCT-backend -->> Civil servant: Return result
USCT-backend -->> Civil servant: Beneficiary was created


```

### Payment officer sequence of steps

```mermaid
sequenceDiagram
Civil servant ->> USCT-backend: Chose a beneficiary from the list
Civil servant ->> USCT-backend: Order payment
participant im as Information mediator

USCT-backend ->> Payment BB: Automatically make bulk payment
USCT-backend -->> Civil servant: Payment was done
```

## Authentication / Authorization
Expand Down Expand Up @@ -63,7 +74,6 @@ Mosip uses Foundational ID (VID)

| VID / username | Role | Description |
|---------------------------------|--------------------|-----------------------------------------------------|
| 7495681570 / registry-officer | REGISTRY_OFFICER | Officer responsible for creating/editing candidates |
| 9038952310 / enrollment-officer | ENROLLMENT_OFFICER | Officer responsible for enrollment |
| 2405176278 / payment-officer | PAYMENT_OFFICER | Officer responsible for payment |

Expand Down Expand Up @@ -98,9 +108,9 @@ Supported payment Building blocks are:
* [Implementation](https://github.com/GovStackWorkingGroup/sandbox-bb-payments/tree/main/emulator/implementation)
* [Documentation](https://github.com/GovStackWorkingGroup/sandbox-bb-payments/tree/main/emulator/docs)
* Mifos Payment Hub
* [API spec](https://govstack.gitbook.io/bb-payments/) version 2.0 (In Development!)
* Implementation (in progress)
* Documentation (in progress)
* [API spec](https://govstack.gitbook.io/bb-payments/)
* [Implementation](https://github.com/openMF)
* [Documentation](https://docs.mifos.org/)

Environment variable is used to define which service to use:

Expand Down Expand Up @@ -135,6 +145,133 @@ Environment variables for global configuration:
| JWS_TENANT_PRIVATE_KEY | More information in PaymentHub Documentation ( TBD ) | Default private key from [HERE](https://github.com/openMF/ph-ee-connector-common/blob/master/src/main/resources/application-jws.yaml) |
| PAYMENTHUB_PAYMENT_MODE | More information in PaymentHub Documentation ( TBD ) | mojaloop |
| PAYMENTHUB_IM_HEADER | Header value for Information Mediator Building Block request header "X-Road-Client". More [Information](https://govstack.gitbook.io/bb-information-mediation/v/information-mediation-1.0/). | SANDBOX/ORG/CLIENT/TEST |
### Swagger

https://app.swaggerhub.com/apis/myapi943/payment-hub_ap_is/1.0


### Installation

`helm install my-ph-ee-g2psandbox g2p-sandbox-1-5/ph-ee-g2psandbox --version 1.5.0 --create-namespace --namespace paymenthub`

#### Post Deployment Steps
The Post_installation_Job is automated through a Kubernetes job in the helm chart. it will create secrets for ElasticSearch and Kibana. and Upload the BPMN. However, The following steps can be used to create Secrets and upload BPMN Manually.

##### Create the required secrets for Elasticsearch and Kibana

Use https://github.com/openMF/ph-ee-env-labs/tree/master/helm/es-secret and https://github.com/openMF/ph-ee-env-labs/tree/master/helm/kibana-secret you can create a secret for Elasticsearch and Kibana. The command used to create a secret is

1. auth
2. make secrets NAMESPACE=paymenthub

##### Upload BPMN
https://mifos.gitbook.io/docs/payment-hub-ee/overview/installation-instructions/configuration-instructions/deploy-bpmns-with-multiple-dfsp-ids


1. The Payment Hub EE business logic is always driven by the BPMN workflows included in the git repositories. It's not only possible but often necessary to customize these flows to meet the business requirements of a specific environment.

2. Deploying the workflows to the K8S cluster is a separate step, which can be done either manually for each business flow, or using a shell script like this (actual example from the project's CI server):

3. In the below example tenants are picked up from the array declared and for N number of tenants the script will run for N number of times and Internal field separator will convert array into string and store in $t.

4. Zeebe command line tools (the zbctl binary) are also required for deploying the BPMN workflows if Zeebe Operations service is not deployed. This is part of the Zeebe releases and can be downloaded from the Zeebe release page at https://github.com/zeebe-io/zeebe/releases.

5. BPMN deployment should be done with corresponding release version which can be obtained from release notes

6. In the below script HOST should be replaced with the zeebe ops(port-forwarded) url from your cluster.

```bash
#!/bin/bash
HOST="http://localhost:5000/zeebe/upload"

deploy(){
cmd="curl --insecure --location --request POST $HOST \
--header 'Platform-TenantId: $2' \
--form 'file=@\"$PWD/$1\"'"
echo "$cmd"
eval "$cmd"
}

TENANTS="gorilla,lion,rhino"
IFS=',' read -ra TENANT_ARRAY <<< "$TENANTS"

for t in "${TENANT_ARRAY[@]}"; do
LOC="feel/*.bpmn"
for f in $LOC; do
# Check if "DFSPID" is present in the filename
if echo "$f" | grep -q "DFSPID"; then
# Replace "DFSPID" with the current tenant value in the filename
new_file_name=$(echo "$f" | sed "s/DFSPID/$t/")
else
# If "DFSPID" is not present, use the original name
new_file_name="$f"
fi
deploy "$new_file_name" "$t"
done

LOC2="feel/example/*.bpmn"
for f in $LOC2; do
# Check if "DFSPID" is present in the filename
if echo "$f" | grep -q "DFSPID"; then
# Replace "DFSPID" with the current tenant value in the filename
new_file_name=$(echo "$f" | sed "s/DFSPID/$t/")
else
# If "DFSPID" is not present, use the original name
new_file_name="$f"
fi
deploy "$new_file_name" "$t"
done
done
```


#### Change port for bulk connector from 8443 to 8080 and turn off TLS

**Use it only for demo purpose**


Update config of **ph-ee-connector-bulk** pod

```yaml
- name: SECURITY_JWS_ENABLE
value: "false"
- name: SERVER_PORT
value: "8080"
- name: SERVER_SSL_ENABLED
value: "false"

```

#### Transaction request example:

```bash
curl --location 'https://localhost:8443/batchtransactions?type=raw' \
--header 'X-CallbackURL: https://webhook.site/{webhook}' \
--header 'X-Registering-Institution-ID: 123' \
--header 'Purpose: test payment' \
--header 'X-CorrelationID: 123' \
--header 'Platform-TenantId: gorilla' \
--header 'X-Program-ID: 00' \
--header 'Type: raw' \
--header 'Content-Type: application/json' \
--data ' {
"requestId":"8238482323",
"creditParty": [
{
"key": "msisdn",
"value": "8837461856"
}
],
"paymentMode ": "closedLoop",
"amount": "20.00",
"currency": "SGD",
"descriptionText": "Test Payment"
}'
```

#### Get transactions

http://ph-ee-operations-app:5000/api/v1/batches?page=0&size=10&sortOrder=asc&orderBy=requestFile&Platform-TenantId=gorilla

## IP FILTER
In order to protect by IP callback endpoints, whitelist of IP can be provided by ENV VAR
Expand Down
2 changes: 1 addition & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ paymenthub:
bulk_connector_url: "http://sandbox-xroad-ss2.im-xroad.svc.cluster.local:8080/r1/SANDBOX/GOV/PROVIDER/PAYMENT/bulk-connector"
callback_base_url: "http://backend.usct.svc.cluster.local:8080"
registering_institution_id: 123456
tenant: rhino
tenant: gorilla
program_id: "00"
jws_tenant_private_key: ""
payment_mode: "mojaloop"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package global.govstack.usct.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateBean {
@Bean
public RestTemplate createBean() {
return new RestTemplate();
}
}
11 changes: 11 additions & 0 deletions src/main/java/global/govstack/usct/model/Candidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class Candidate {
@Column(name = "igrant_id")
private String igrantId;

@Column(name = "is_beneficiary", nullable = false)
private boolean isBeneficiary;

public Set<Integer> getOpenImisPackageIds() {
return openImisPackageIds;
}
Expand Down Expand Up @@ -84,4 +87,12 @@ public String getIgrantId() {
public void setIgrantId(String igrantId) {
this.igrantId = igrantId;
}

public boolean getIsBeneficiary() {
return this.isBeneficiary;
}

public void setIsBeneficiary(boolean isBeneficiary) {
this.isBeneficiary = isBeneficiary;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package global.govstack.usct.repositories;

import global.govstack.usct.model.Candidate;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CandidateRepository extends JpaRepository<Candidate, Integer> {}
public interface CandidateRepository extends JpaRepository<Candidate, Integer> {
List<Candidate> findByIsBeneficiary(boolean isBeneficiary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@
@Service
public class BeneficiaryService {
private final BeneficiaryRepository repository;
private final PaymentService paymentService;
private final CandidateService candidateService;
private final PaymentProperties properties;
private final PackageService packageService;
private final ConsentService consentService;

public BeneficiaryService(
BeneficiaryRepository repository,
PaymentService paymentService,
CandidateService candidateService,
PaymentProperties properties,
PackageService packageService,
ConsentService consentService) {
PackageService packageService) {
this.repository = repository;
this.paymentService = paymentService;
this.candidateService = candidateService;
this.properties = properties;
this.packageService = packageService;
this.consentService = consentService;
}

public List<BeneficiaryDto> findAll() {
Expand Down Expand Up @@ -69,8 +63,8 @@ public Beneficiary create(Candidate candidate, int enrolledPackageId) {
beneficiary.setPaymentStatus(PaymentStatus.INITIATE);
beneficiary.setFunctionalId(functionalId);
Beneficiary savedBeneficiary = repository.save(beneficiary);
candidateService.delete(candidate);
paymentService.registerBeneficiary(List.of(savedBeneficiary));
candidate.setIsBeneficiary(true);
candidateService.save(candidate);

return savedBeneficiary;
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/global/govstack/usct/service/CandidateService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package global.govstack.usct.service;

import global.govstack.usct.configuration.IGrantProperties;
import global.govstack.usct.configuration.OpenImisProperties;
import global.govstack.usct.controller.dto.CandidateDto;
import global.govstack.usct.controller.dto.CreateCandidateDto;
Expand All @@ -24,26 +23,23 @@ public class CandidateService {
private final PackageService packageService;
private final ConsentService consentService;
private final OpenImisProperties openImisProperties;
private final IGrantProperties iGrantProperties;

public CandidateService(
CandidateRepository candidateRepository,
PersonService personService,
PackageService packageService,
ConsentService consentService,
OpenImisProperties openImisProperties,
IGrantProperties iGrantProperties) {
OpenImisProperties openImisProperties) {
this.candidateRepository = candidateRepository;
this.personService = personService;
this.packageService = packageService;
this.consentService = consentService;
this.openImisProperties = openImisProperties;
this.iGrantProperties = iGrantProperties;
}

public List<CandidateDto> findAll() {
log.info("Get list of candidates");
List<Candidate> candidates = candidateRepository.findAll();
List<Candidate> candidates = candidateRepository.findByIsBeneficiary(false);
return candidates.stream()
.map(
candidate -> {
Expand Down Expand Up @@ -86,11 +82,6 @@ public void deleteById(Integer id) {
candidateRepository.deleteById(id);
}

public void delete(Candidate candidate) {
log.info("Delete candidate by id: {}", candidate.getId());
candidateRepository.delete(candidate);
}

@Transactional
public Candidate save(CreateCandidateDto createCandidateDto) {
log.info("Create candidate, firstName: {}", createCandidateDto.person().firstName());
Expand Down
Loading