Merge pull request #24 from brianpooe/feature/list-countries
Feature/list countries
This commit is contained in:
commit
14c0fe863e
7 changed files with 143 additions and 56 deletions
|
|
@ -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<PsListStatesResponseModel> {
|
||||
return this.miscellaneousService.listStates(country);
|
||||
}
|
||||
|
||||
@Get('country')
|
||||
listCountries(): Observable<PsListCountriesResponseModel> {
|
||||
return this.miscellaneousService.listCountries();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||
import {
|
||||
PsListBanksRequestModel,
|
||||
PsListBanksResponseModel,
|
||||
PsListCountriesResponseModel,
|
||||
PsListStatesResponseModel,
|
||||
PsMiscellaneousService
|
||||
} from '@devtools-bp/nestjs-paystack';
|
||||
|
|
@ -9,15 +10,21 @@ import { Observable } from 'rxjs';
|
|||
|
||||
@Injectable()
|
||||
export class MiscellaneousService {
|
||||
constructor(private readonly psMiscellaneous: PsMiscellaneousService) {}
|
||||
constructor(
|
||||
private readonly psMiscellaneousService: PsMiscellaneousService
|
||||
) {}
|
||||
|
||||
listBanks(
|
||||
queryParamsPayload: PsListBanksRequestModel
|
||||
): Observable<PsListBanksResponseModel> {
|
||||
return this.psMiscellaneous.listBanks(queryParamsPayload);
|
||||
return this.psMiscellaneousService.listBanks(queryParamsPayload);
|
||||
}
|
||||
|
||||
listCountries(): Observable<PsListCountriesResponseModel> {
|
||||
return this.psMiscellaneousService.listCountries();
|
||||
}
|
||||
|
||||
listStates(country: string): Observable<PsListStatesResponseModel> {
|
||||
return this.psMiscellaneous.listStates(country);
|
||||
return this.psMiscellaneousService.listStates(country);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <span style="color:green;">✔</span>
|
||||
- [x] Validate Account <span style="color:green;">✔</span>
|
||||
- [x] Resolve Card BIN <span style="color:green;">✔</span>
|
||||
- [ ] **Miscellaneous** ⏳
|
||||
- [x] **Miscellaneous** <span style="color:green;">✔</span>
|
||||
- [x] **List Banks** <span style="color:green;">✔</span>
|
||||
- [x] **List Countries** <span style="color:green;">✔</span>
|
||||
- [ ] **List States (AVS)** ⏳
|
||||
- [x] **List States (AVS)** <span style="color:green;">✔</span>
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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<PsListCountriesResponseModel> = 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
|
||||
|
|
|
|||
|
|
@ -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<PsListCountriesResponseModel> {
|
||||
return this.httpService
|
||||
.get<PsListBanksResponseModel>(`country`)
|
||||
.pipe(handleResponseAndError());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue