From 497a7a5d3417803fce33184289a1f4d112623c4c Mon Sep 17 00:00:00 2001 From: Brian Pooe Date: Sat, 22 Jul 2023 15:39:35 +0200 Subject: [PATCH 1/4] docs: updated readme for upcoming api endpoints --- libs/nestjs-paystack/README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/nestjs-paystack/README.md b/libs/nestjs-paystack/README.md index a27fc65..bb77b1d 100644 --- a/libs/nestjs-paystack/README.md +++ b/libs/nestjs-paystack/README.md @@ -137,7 +137,13 @@ export class TransactionController { - [ ] **Payment Requests** - [ ] **Settlements** - [ ] **Transaction Recipients** -- [ ] **Transfers** +- [ ] **Transfers** ⏳ + - [ ] **Initiate Transfer** ⏳ + - [ ] **Finalize Transfer** ⏳ + - [ ] **Initiate Bulk Transfer** ⏳ + - [ ] **List Transfer** ⏳ + - [ ] **Fetch Transfer** ⏳ + - [ ] **Verify Transfer** ⏳ - [ ] **Transfers Control** - [ ] **Bulk Charges** - [ ] **Integration** @@ -148,10 +154,10 @@ export class TransactionController { - [x] Resolve Account Number - [x] Validate Account - [x] Resolve Card BIN -- [ ] **Miscellaneous** ⏳ +- [x] **Miscellaneous** ⏳ - [x] **List Banks** - [x] **List Countries** - - [ ] **List States (AVS)** ⏳ + - [x] **List States (AVS)** ## Contributing From c3812d7e84be4ddc704c3b33b7d604f7fb48284b Mon Sep 17 00:00:00 2001 From: Brian Pooe Date: Sat, 22 Jul 2023 15:49:37 +0200 Subject: [PATCH 2/4] feat: added list supported countries api --- .../src/lib/models/miscellaneous/index.ts | 1 + .../ps-list-countries-response.model.ts | 31 +++++ .../ps-miscellaneous.service.spec.ts | 124 +++++++++++------- .../miscellaneous/ps-miscellaneous.service.ts | 12 +- 4 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 libs/nestjs-paystack/src/lib/models/miscellaneous/ps-list-countries-response.model.ts diff --git a/libs/nestjs-paystack/src/lib/models/miscellaneous/index.ts b/libs/nestjs-paystack/src/lib/models/miscellaneous/index.ts index da352e4..c54fd33 100644 --- a/libs/nestjs-paystack/src/lib/models/miscellaneous/index.ts +++ b/libs/nestjs-paystack/src/lib/models/miscellaneous/index.ts @@ -1,3 +1,4 @@ export * from './ps-list-banks-response.model'; export * from './ps-list-banks-request.model'; export * from './ps-list-states-response.model'; +export * from './ps-list-countries-response.model'; diff --git a/libs/nestjs-paystack/src/lib/models/miscellaneous/ps-list-countries-response.model.ts b/libs/nestjs-paystack/src/lib/models/miscellaneous/ps-list-countries-response.model.ts new file mode 100644 index 0000000..ebcf0c3 --- /dev/null +++ b/libs/nestjs-paystack/src/lib/models/miscellaneous/ps-list-countries-response.model.ts @@ -0,0 +1,31 @@ +import { PsBaseModel } from '../common'; + +export interface PsListCountriesResponseModel extends PsBaseModel { + data: PsListCountriesResponseDataModel[] | null; +} + +export interface PsListCountriesResponseDataModel { + id: number; + name: string; + iso_code: string; + default_currency_code: string; + integration_defaults: unknown; + relationships: PsRelationshipsModel; +} + +export interface PsRelationshipsModel { + currency: PsCurrencyOrIntegrationTypeOrPaymentMethodModel; + integration_feature: PsIntegrationFeatureModel; + integration_type: PsCurrencyOrIntegrationTypeOrPaymentMethodModel; + payment_method: PsCurrencyOrIntegrationTypeOrPaymentMethodModel; +} + +export interface PsCurrencyOrIntegrationTypeOrPaymentMethodModel { + type: string; + data?: string[] | null; +} + +export interface PsIntegrationFeatureModel { + type: string; + data?: unknown[] | null; +} diff --git a/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.spec.ts b/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.spec.ts index a00796e..16796a2 100644 --- a/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.spec.ts +++ b/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.spec.ts @@ -4,7 +4,8 @@ import { TestBed } from '@automock/jest'; import { PsListBanksRequestModel, PsListBanksResponseModel, - PsListStatesResponseModel + PsListStatesResponseModel, + PsListCountriesResponseModel } from '../../models'; import { AxiosResponse } from 'axios'; import { fromPartial } from '@total-typescript/shoehorn'; @@ -73,54 +74,6 @@ describe('MiscellaneousService', () => { id: 173, createdAt: '2020-11-24T10:25:07.000Z', updatedAt: '2020-11-24T10:25:07.000Z' - }, - { - name: 'Infinity MFB', - slug: 'infinity-mfb', - code: '50457', - longcode: '', - gateway: null, - pay_with_bank: false, - active: true, - is_deleted: false, - country: 'Nigeria', - currency: 'NGN', - type: 'nuban', - id: 172, - createdAt: '2020-11-24T10:23:37.000Z', - updatedAt: '2020-11-24T10:23:37.000Z' - }, - { - name: 'Paycom', - slug: 'paycom', - code: '999992', - longcode: '', - gateway: null, - pay_with_bank: false, - active: true, - is_deleted: false, - country: 'Nigeria', - currency: 'NGN', - type: 'nuban', - id: 171, - createdAt: '2020-11-24T10:20:45.000Z', - updatedAt: '2020-11-24T10:20:54.000Z' - }, - { - name: 'Petra Mircofinance Bank Plc', - slug: 'petra-microfinance-bank-plc', - code: '50746', - longcode: '', - gateway: null, - pay_with_bank: false, - active: true, - is_deleted: false, - country: 'Nigeria', - currency: 'NGN', - type: 'nuban', - id: 170, - createdAt: '2020-11-24T10:03:06.000Z', - updatedAt: '2020-11-24T10:03:06.000Z' } ] }) @@ -135,6 +88,79 @@ describe('MiscellaneousService', () => { }); }); + describe('listCountries', () => { + it('should get a list of countries that Paystack currently supports', () => { + // Arrange + const response: AxiosResponse = fromPartial( + { + data: fromPartial({ + status: true, + message: 'States retrieved', + data: [ + { + id: 1, + name: 'Nigeria', + iso_code: 'NG', + default_currency_code: 'NGN', + integration_defaults: {}, + relationships: { + currency: { + type: 'currency', + data: ['NGN', 'USD'] + }, + integration_feature: { + type: 'integration_feature', + data: [] + }, + integration_type: { + type: 'integration_type', + data: ['ITYPE_001', 'ITYPE_002', 'ITYPE_003'] + }, + payment_method: { + type: 'payment_method', + data: ['PAYM_001', 'PAYM_002', 'PAYM_003', 'PAYM_004'] + } + } + }, + { + id: 2, + name: 'Ghana', + iso_code: 'GH', + default_currency_code: 'GHS', + integration_defaults: {}, + relationships: { + currency: { + type: 'currency', + data: ['GHS', 'USD'] + }, + integration_feature: { + type: 'integration_feature', + data: [] + }, + integration_type: { + type: 'integration_type', + data: ['ITYPE_004', 'ITYPE_005'] + }, + payment_method: { + type: 'payment_method', + data: ['PAYM_001'] + } + } + } + ] + }) + } + ); + httpService.get.mockReturnValueOnce(of(response)); + + // Act + const observerSpy = subscribeSpyTo(service.listCountries()); + + // Act + expect(observerSpy.getLastValue()).toEqual(response.data); + }); + }); + describe('listStates', () => { it('should get a list of states for a country for address verification', () => { // Arrange diff --git a/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.ts b/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.ts index a8bc352..141d671 100644 --- a/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.ts +++ b/libs/nestjs-paystack/src/lib/services/miscellaneous/ps-miscellaneous.service.ts @@ -4,7 +4,8 @@ import { handleResponseAndError, PsListBanksRequestModel, PsListBanksResponseModel, - PsListStatesResponseModel + PsListStatesResponseModel, + PsListCountriesResponseModel } from '../../models'; import { Observable } from 'rxjs'; @@ -37,4 +38,13 @@ export class PsMiscellaneousService { ) .pipe(handleResponseAndError()); } + + /** + * Gets a list of countries that Paystack currently supports + */ + listCountries(): Observable { + return this.httpService + .get(`country`) + .pipe(handleResponseAndError()); + } } From 9d7cd67fac75d6f30d74383ff9697b0595578517 Mon Sep 17 00:00:00 2001 From: Brian Pooe Date: Sat, 22 Jul 2023 15:54:51 +0200 Subject: [PATCH 3/4] feat: added demo for listing supported countries --- .../miscellaneous/controllers/miscellaneous.controller.ts | 6 ++++++ .../src/app/miscellaneous/services/miscellaneous.service.ts | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/apps/ns-paystack-demo/src/app/miscellaneous/controllers/miscellaneous.controller.ts b/apps/ns-paystack-demo/src/app/miscellaneous/controllers/miscellaneous.controller.ts index 589087a..366b3d4 100644 --- a/apps/ns-paystack-demo/src/app/miscellaneous/controllers/miscellaneous.controller.ts +++ b/apps/ns-paystack-demo/src/app/miscellaneous/controllers/miscellaneous.controller.ts @@ -3,6 +3,7 @@ import { MiscellaneousService } from '../services/miscellaneous.service'; import { PsListBanksRequestModel, PsListBanksResponseModel, + PsListCountriesResponseModel, PsListStatesResponseModel } from '@devtools-bp/nestjs-paystack'; import { Observable } from 'rxjs'; @@ -24,4 +25,9 @@ export class MiscellaneousController { ): Observable { return this.miscellaneousService.listStates(country); } + + @Get('country') + listCountries(): Observable { + return this.miscellaneousService.listCountries(); + } } diff --git a/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts b/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts index 551285e..47fc9cd 100644 --- a/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts +++ b/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { PsListBanksRequestModel, PsListBanksResponseModel, + PsListCountriesResponseModel, PsListStatesResponseModel, PsMiscellaneousService } from '@devtools-bp/nestjs-paystack'; @@ -17,6 +18,10 @@ export class MiscellaneousService { return this.psMiscellaneous.listBanks(queryParamsPayload); } + listCountries(): Observable { + return this.psMiscellaneous.listCountries(); + } + listStates(country: string): Observable { return this.psMiscellaneous.listStates(country); } From 6b42247c2a35404a815962431f074f33cece00f1 Mon Sep 17 00:00:00 2001 From: Brian Pooe Date: Sat, 22 Jul 2023 15:58:20 +0200 Subject: [PATCH 4/4] fix: rename miscellaneous service --- .../miscellaneous/services/miscellaneous.service.ts | 10 ++++++---- libs/nestjs-paystack/README.md | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts b/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts index 47fc9cd..bdae38b 100644 --- a/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts +++ b/apps/ns-paystack-demo/src/app/miscellaneous/services/miscellaneous.service.ts @@ -10,19 +10,21 @@ import { Observable } from 'rxjs'; @Injectable() export class MiscellaneousService { - constructor(private readonly psMiscellaneous: PsMiscellaneousService) {} + constructor( + private readonly psMiscellaneousService: PsMiscellaneousService + ) {} listBanks( queryParamsPayload: PsListBanksRequestModel ): Observable { - return this.psMiscellaneous.listBanks(queryParamsPayload); + return this.psMiscellaneousService.listBanks(queryParamsPayload); } listCountries(): Observable { - return this.psMiscellaneous.listCountries(); + return this.psMiscellaneousService.listCountries(); } listStates(country: string): Observable { - return this.psMiscellaneous.listStates(country); + return this.psMiscellaneousService.listStates(country); } } diff --git a/libs/nestjs-paystack/README.md b/libs/nestjs-paystack/README.md index bb77b1d..44d5578 100644 --- a/libs/nestjs-paystack/README.md +++ b/libs/nestjs-paystack/README.md @@ -154,7 +154,7 @@ export class TransactionController { - [x] Resolve Account Number - [x] Validate Account - [x] Resolve Card BIN -- [x] **Miscellaneous** ⏳ +- [x] **Miscellaneous** - [x] **List Banks** - [x] **List Countries** - [x] **List States (AVS)**