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

refactor: 2060 remove notifyThirdpartyAboutTransfer #64

Merged
merged 9 commits into from
Mar 17, 2021
Merged
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
20,802 changes: 20,779 additions & 23 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@
"@mojaloop/central-services-health": "^11.0.0",
"@mojaloop/central-services-metrics": "^9.5.0",
"@mojaloop/central-services-shared": "^11.5.9",
"@mojaloop/sdk-standard-components": "^15.2.1",
"@mojaloop/sdk-standard-components": "^15.4.0",
"@types/axios": "^0.14.0",
"@types/convict": "^5.2.2",
"@types/hapi": "^18.0.5",
@@ -142,11 +142,11 @@
"nodemon": "^2.0.7",
"npm-audit-resolver": "^2.2.1",
"npm-check-updates": "^11.1.4",
"openapi-response-validator": "^7.2.3",
"openapi-typescript": "^2.4.2",
"redis-mock": "0.52.0",
"source-map-support": "0.5.19",
"standard-version": "^9.1.1",
"openapi-response-validator": "^7.2.3",
"openapi-typescript": "^2.4.2",
"swagger-cli": "^4.0.4",
"ts-jest": "^26.5.1"
}
6 changes: 3 additions & 3 deletions src/handlers/inbound/thirdpartyRequests/transactions.ts
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ import { InboundThirdpartyTransactionPostRequest } from '~/models/thirdparty.tra
*/
async function post (_context: Context, request: Request, h: StateResponseToolkit): Promise<ResponseObject> {
const transactionRequest = request.payload as InboundThirdpartyTransactionPostRequest

const pispId = request.headers['FSPIOP-Source']
// input validation - mocked
if (!(await verifyConsentId(transactionRequest.consentId)) ||
!(await verifyPispId(request.headers['FSPIOP-Source'])) ||
@@ -60,14 +60,14 @@ async function post (_context: Context, request: Request, h: StateResponseToolki

const modelConfig: InboundThridpartyTransactionsModelConfig = {
logger: h.getLogger(),
sdkRequests: h.getSDKRequests(),
sdkOutgoingRequests: h.getSDKOutgoingRequests(),
mojaloopRequests: h.getMojaloopRequests(),
thirdpartyRequests: h.getThirdpartyRequests()
}
const model = new InboundThridpartyTransactionsModel(modelConfig)
// don't await on promise to be resolved
setImmediate(async () => {
const result = await model.requestToPayTransfer(transactionRequest)
const result = await model.requestToPayTransfer(transactionRequest, pispId)
modelConfig.logger.push({ result }).info('requestToPayTransfer done')

// TODO: should we process result somewhere ? PUT ?
2 changes: 1 addition & 1 deletion src/handlers/outbound/thirdpartyTransaction/partyLookup.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ async function post (_context: any, request: Request, h: StateResponseToolkit):
logger: h.getLogger(),
thirdpartyRequests: h.getThirdpartyRequests(),
mojaloopRequests: h.getMojaloopRequests(),
sdkRequests: h.getSDKRequests()
sdkOutgoingRequests: h.getSDKOutgoingRequests()
}
const exists = await existsInKVS(modelConfig)
if (exists) {
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ async function post (_context: any, request: Request, h: StateResponseToolkit):
logger: h.getLogger(),
thirdpartyRequests: h.getThirdpartyRequests(),
mojaloopRequests: h.getMojaloopRequests(),
sdkRequests: h.getSDKRequests()
sdkOutgoingRequests: h.getSDKOutgoingRequests()
}

// load model
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ async function post (_context: any, request: Request, h: StateResponseToolkit):
logger: h.getLogger(),
thirdpartyRequests: h.getThirdpartyRequests(),
mojaloopRequests: h.getMojaloopRequests(),
sdkRequests: h.getSDKRequests()
sdkOutgoingRequests: h.getSDKOutgoingRequests()
}

// load model
35 changes: 21 additions & 14 deletions src/models/inbound/thirdparty.transactions.model.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
--------------
******/

import { SDKRequests } from '~/shared/sdk-requests'
import { SDKOutgoingRequests } from '~/shared/sdk-outgoing-requests'
import {
Logger as SDKLogger,
MojaloopRequests,
@@ -36,12 +36,11 @@ import {
OutboundRequestToPayTransferPostRequest,
OutboundRequestToPayTransferPostResponse
} from '../thirdparty.transactions.interface'
import config from '~/shared/config'
import { ThirdpartyTransactionStatus } from '../pispTransaction.interface'

export interface InboundThridpartyTransactionsModelConfig {
logger: SDKLogger.Logger
sdkRequests: SDKRequests
sdkOutgoingRequests: SDKOutgoingRequests
mojaloopRequests: MojaloopRequests
thirdpartyRequests: ThirdpartyRequests
}
@@ -58,18 +57,23 @@ export class InboundThridpartyTransactionsModel {
return this.config.logger
}

protected get sdkRequests (): SDKRequests {
return this.config.sdkRequests
protected get sdkOutgoingRequests (): SDKOutgoingRequests {
return this.config.sdkOutgoingRequests
}

protected get mojaloopRequests (): MojaloopRequests {
return this.config.mojaloopRequests
}

protected get thirdpartyRequests (): ThirdpartyRequests {
return this.config.thirdpartyRequests
}

// RequestToPay endpoint was used by POC PISPTransaction code
// TODO: use it when PISPMerchantTransaction flow will be implemented in future
async requestToPayTransfer (
inRequest: InboundThirdpartyTransactionPostRequest
inRequest: InboundThirdpartyTransactionPostRequest,
pispId: string
): Promise<OutboundRequestToPayTransferPostResponse> {
this.logger.push({ inRequest }).info('requestToPayTransfer: inRequest')
// propagate make the requestToPayTransfer on outbound sdk-scheme-adapter
@@ -101,20 +105,23 @@ export class InboundThridpartyTransactionsModel {
}
this.logger.push({ requestToPayTransfer }).info('requestToPayTransfer: requestToPayTransfer')

const response = await this.sdkRequests.requestToPayTransfer(
const response = await this.sdkOutgoingRequests.requestToPayTransfer(
requestToPayTransfer
) as OutboundRequestToPayTransferPostResponse

this.logger.push({ response }).info('requestToPayTransfer: response')

// optionally notify via PATCH
if (config.SHARED.SDK_NOTIFY_ABOUT_TRANSFER_URI) {
const transactionStatus: ThirdpartyTransactionStatus = {
transactionId: inRequest.transactionRequestId,
transactionRequestState: 'ACCEPTED'
}
await this.sdkRequests.notifyThirdpartyAboutTransfer(transactionStatus, inRequest.transactionRequestId)
// notifyThirdpartyAboutTransfer via PATCH
const transactionStatus: ThirdpartyTransactionStatus = {
transactionId: inRequest.transactionRequestId,
transactionRequestState: 'ACCEPTED',
transactionState: 'COMPLETED'
}
await this.thirdpartyRequests.patchThirdpartyRequestsTransactions(
transactionStatus,
inRequest.transactionRequestId,
pispId
)

return response
}
7 changes: 4 additions & 3 deletions src/models/pispTransaction.interface.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ import { Method } from 'javascript-state-machine'
import { ErrorInformation } from '~/interface/types'
import { ControlledStateMachine, StateData, PersistentModelConfig } from '~/models/persistent.model'
import { PubSub } from '~/shared/pub-sub'
import { SDKRequests } from '~/shared/sdk-requests'
import { SDKOutgoingRequests } from '~/shared/sdk-outgoing-requests'

export enum RequestPartiesInformationState {
COMPLETED = 'COMPLETED',
@@ -82,7 +82,7 @@ export interface PISPTransactionModelConfig extends PersistentModelConfig {
pubSub: PubSub
thirdpartyRequests: ThirdpartyRequests
mojaloopRequests: MojaloopRequests
sdkRequests: SDKRequests
sdkOutgoingRequests: SDKOutgoingRequests
}

// derived from request body specification
@@ -123,7 +123,8 @@ export interface ThirdpartyTransactionInitiateResponse {

export interface ThirdpartyTransactionStatus {
transactionId: string
transactionRequestState: 'RECEIVED' | 'PENDING' | 'ACCEPTED' | 'REJECTED'
transactionRequestState: 'RECEIVED' | 'PENDING' | 'ACCEPTED' | 'REJECTED',
transactionState: 'RECEIVED' | 'PENDING' | 'COMPLETED' | 'REJECTED'
}

export interface ThirdpartyTransactionApproveResponse {
8 changes: 4 additions & 4 deletions src/models/pispTransaction.model.ts
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ import {
ThirdpartyTransactionStatus
} from './pispTransaction.interface'
import inspect from '~/shared/inspect'
import { SDKRequests } from '~/shared/sdk-requests'
import { SDKOutgoingRequests } from '~/shared/sdk-outgoing-requests'
import { HTTPResponseError } from '~/shared/http-response-error'

export class InvalidPISPTransactionDataError extends Error {
@@ -119,8 +119,8 @@ export class PISPTransactionModel
return this.config.mojaloopRequests
}

get sdkRequests (): SDKRequests {
return this.config.sdkRequests
get sdkOutgoingRequests (): SDKOutgoingRequests {
return this.config.sdkOutgoingRequests
}

static notificationChannel (phase: PISPTransactionPhase, transactionRequestId: string): string {
@@ -139,7 +139,7 @@ export class PISPTransactionModel

try {
// call GET /parties on sdk-scheme-adapter Outbound service
const response = this.data.payeeResolved = await this.sdkRequests.requestPartiesInformation(
const response = this.data.payeeResolved = await this.sdkOutgoingRequests.requestPartiesInformation(
partyIdType, partyIdentifier, partySubIdOrType
) as RequestPartiesInformationResponse

11 changes: 5 additions & 6 deletions src/server/plugins/state.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ import { logger } from '~/shared/logger'
import config from '~/shared/config'
import { PISPBackendRequests } from '~/shared/pisp-backend-requests'
import { DFSPBackendRequests } from '~/shared/dfsp-backend-requests'
import { SDKRequests } from '~/shared/sdk-requests'
import { SDKOutgoingRequests } from '~/shared/sdk-outgoing-requests'
import { Scheme } from '~/shared/http-scheme'

export interface StateResponseToolkit extends ResponseToolkit {
@@ -47,7 +47,7 @@ export interface StateResponseToolkit extends ResponseToolkit {
getWSO2Auth: () => SDK.WSO2Auth
getPISPBackendRequests: () => PISPBackendRequests
getDFSPBackendRequests: () => DFSPBackendRequests
getSDKRequests: () => SDKRequests
getSDKOutgoingRequests: () => SDKOutgoingRequests
}

export const StatePlugin = {
@@ -132,14 +132,13 @@ export const StatePlugin = {
getScopesPath: config.SHARED.DFSP_BACKEND_GET_SCOPES_PATH
})

const sdkRequests = new SDKRequests({
const sdkOutgoingRequests = new SDKOutgoingRequests({
logger,
dfspId: config.SHARED.DFSP_ID,
uri: config.SHARED.SDK_OUTGOING_URI,
scheme: config.SHARED.SDK_OUTGOING_HTTP_SCHEME as Scheme,
requestPartiesInformationPath: config.SHARED.SDK_PARTIES_INFORMATION_URI,
requestToPayTransferPath: config.SHARED.SDK_REQUEST_TO_PAY_TRANSFER_URI,
notifyAboutTransferPath: config.SHARED.SDK_NOTIFY_ABOUT_TRANSFER_URI
requestToPayTransferPath: config.SHARED.SDK_REQUEST_TO_PAY_TRANSFER_URI
})

try {
@@ -156,7 +155,7 @@ export const StatePlugin = {
server.decorate('toolkit', 'getWSO2Auth', (): SDK.WSO2Auth => wso2Auth)
server.decorate('toolkit', 'getPISPBackendRequests', (): PISPBackendRequests => pispBackendRequests)
server.decorate('toolkit', 'getDFSPBackendRequests', (): DFSPBackendRequests => dfspBackendRequests)
server.decorate('toolkit', 'getSDKRequests', (): SDKRequests => sdkRequests)
server.decorate('toolkit', 'getSDKOutgoingRequests', (): SDKOutgoingRequests => sdkOutgoingRequests)

// disconnect from redis when server is stopped
server.events.on('stop', async () => {
45 changes: 10 additions & 35 deletions src/shared/sdk-requests.ts → src/shared/sdk-outgoing-requests.ts
Original file line number Diff line number Diff line change
@@ -32,35 +32,32 @@ import {
OutboundRequestToPayTransferPostResponse
} from '../models/thirdparty.transactions.interface'
import {
ThirdpartyTransactionStatus,
RequestPartiesInformationResponse
} from '~/models/pispTransaction.interface'
export interface SDKRequestConfig extends HttpRequestsConfig {
// TODO: SDK Requests Interfaces: MojaloopRequests & ThridpartyRequests
export interface SDKOutgoingRequestsConfig extends HttpRequestsConfig {
dfspId: string
requestPartiesInformationPath: string
requestToPayTransferPath: string
notifyAboutTransferPath: string
}

/**
* @class SDKRequest
* @class SDKOutgoingRequest
* @description tiny wrapper dedicated to make requests to SDK scheme adapter Outgoing
* and SDK MojaloopRequest/ThirdpartyRequest interfaces
*
*/
export class SDKRequests extends HttpRequests {
export class SDKOutgoingRequests extends HttpRequests {
// we want this constructor for better code support
// eslint-disable-next-line no-useless-constructor
constructor (config: SDKRequestConfig) {
constructor (config: SDKOutgoingRequestsConfig) {
super(config)
}

// GETTERS

// config getter
// polymorphism for getters can be handy and saves a lot of type casting
protected get config (): SDKRequestConfig {
return super.config as unknown as SDKRequestConfig
protected get config (): SDKOutgoingRequestsConfig {
return super.config as unknown as SDKOutgoingRequestsConfig
}

// requestToPayTransfer path getter
@@ -73,11 +70,6 @@ export class SDKRequests extends HttpRequests {
return this.config.requestToPayTransferPath
}

// notifyAboutTransfer path getter
get notifyAboutTransferPath (): string {
return this.config.notifyAboutTransferPath
}

// dfspId getter
get dfspId (): string {
return this.config.dfspId
@@ -86,34 +78,17 @@ export class SDKRequests extends HttpRequests {
// REQUESTS
/**
* TODO: these requests will be used by DFSPTransactionModel
* // these two will be done by calling ThirdpartyRequests interface, so not implemented here
* notifyThirdpartyAboutRejectedAuthorization
* notifyThirdpartyAboutTransfer
* // synchronous calls to SDKOutgoing
* requestAuthorization
* requestQuote,
* requestThirdpartyTransaction
* requestTransfer,
* requestVerifyAuthorization
*
* */
async notifyThirdpartyAboutTransfer (
request: ThirdpartyTransactionStatus,
id: string
): Promise<void> {
// TODO: replace by thirdpartyRequests.patchThridpartyRequestTransaction
return this.loggedRequest<void>({
// uri: this.prependScheme(config.SHARED.NOTIFY_ABOUT_TRANSFER_URI.replace('{ID}', id)),
uri: this.prependScheme(this.notifyAboutTransferPath.replace('{ID}', id)),
method: 'PATCH',
body: requests.common.bodyStringifier(request),
headers: {
...this.headers,
// 'fspiop-source': this.config.SHARED.DFSP_ID
'fspiop-source': this.dfspId
},

agent: this.agent
})
}

async requestPartiesInformation (
type: string, id: string, subId?: string
@@ -141,7 +116,7 @@ export class SDKRequests extends HttpRequests {
})
}

// TODO drop it and replace by requestTransfer
// TODO: drop it and replace by requestTransfer
async requestToPayTransfer (
request: OutboundRequestToPayTransferPostRequest
): Promise<OutboundRequestToPayTransferPostResponse | void> {
3 changes: 2 additions & 1 deletion test/unit/handlers/inbound-pispTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -26,7 +26,8 @@ describe('Inbound PISP transaction handlers', (): void => {

const approveResponse: ThirdpartyTransactionStatus = {
transactionId: 'x42ec534-ae48-6575-g6a9-tad2955b8065',
transactionRequestState: 'ACCEPTED'
transactionRequestState: 'ACCEPTED',
transactionState: 'COMPLETED'
}
const errorResponse = {
errorInformation: {
3 changes: 2 additions & 1 deletion test/unit/handlers/outbound-api.test.ts
Original file line number Diff line number Diff line change
@@ -117,7 +117,8 @@ const initiateResponse: tpAPI.Schemas.AuthorizationsPostRequest = {
}
const approveResponse: ThirdpartyTransactionStatus = {
transactionId: 'b51ec534-ee48-4575-b6a9-ead2955b8069',
transactionRequestState: 'ACCEPTED'
transactionRequestState: 'ACCEPTED',
transactionState: 'COMPLETED'
}

jest.mock('redis')
2 changes: 1 addition & 1 deletion test/unit/handlers/outbound-pispTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ describe('Outbound PISP transaction handlers', () => {
getLogger: jest.fn(() => mockLogger()),
getThirdpartyRequests: jest.fn(),
getMojaloopRequests: jest.fn(),
getSDKRequests: jest.fn(),
getSDKOutgoingRequests: jest.fn(),
response: jest.fn(() => ({
code: jest.fn((code: number) => ({
statusCode: code
Loading