Skip to content

Commit

Permalink
feat: adds a single consult endpoint (#11)
Browse files Browse the repository at this point in the history
* feat: adds a single consult endpoint

* fix: fixes tests

* fix: deletes yarn-error file

Co-authored-by: Aaron Perez <[email protected]>
  • Loading branch information
AaronPerezPerez and Aaron Perez authored Jun 11, 2021
1 parent e3b2a58 commit 2cd1aa9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
.idea
lib
.vscode
.env
yarn-error.log
4 changes: 2 additions & 2 deletions src/Arcus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Arcus', () => {
it('getBillers', async () => {
const billers = await arcus.getBillers();

expect(billers).toHaveLengthWithin(120, 150);
expect(billers).toHaveLengthWithin(100, 130);

const totalPlay = billers.find(billerTotalPlay);
const telcel = billers.find(billerTelcel);
Expand All @@ -37,7 +37,7 @@ describe('Arcus', () => {
it('getBillersUtilities', async () => {
const utilities = await arcus.getBillersUtilities();

expect(utilities).toHaveLengthWithin(70, 90);
expect(utilities).toHaveLengthWithin(60, 80);

const totalPlay = utilities.find(billerTotalPlay);

Expand Down
20 changes: 19 additions & 1 deletion src/Arcus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { ArcusBillPaymentCreateResponse } from './typings/ArcusBillPaymentCreate
import { generateBody } from './utils/generateBody';
import fetch, { Response } from 'node-fetch';
import { ArcusBillerUtility } from './typings/ArcusBillerUtility';
import { ArcusSingleConsultParams } from './typings/ArcusSingleConsultParams';
import { PostSingleConsultResponse } from './typings/PostSingleConsultResponse';

/**
* Arcus Fintech JS client
Expand Down Expand Up @@ -283,6 +285,22 @@ export class Arcus {
.then((data) => camelize<ArcusTransaction>(data));
}

/**
* Consult an utility bill in Arcus with an account number. Account number bills are mostly to make payments without providing personal information.
*/
singleConsult(params: ArcusSingleConsultParams) {
const path = '/single/consult';

return this.http(this.config.baseURL + path, {
method: 'POST',
body: generateBody(params),
headers: this.generateDefaultHeaders(path),
})
.then(Arcus.dealWithErrors)
.then(Arcus.extractJson)
.then((data) => camelize<ArcusTransaction>(data));
}

/**
* This endpoint retrieves a specific transaction.
*/
Expand Down Expand Up @@ -311,6 +329,6 @@ export class Arcus {
})
.then(Arcus.dealWithErrors)
.then(Arcus.extractJson)
.then((data) => camelize<ArcusTransaction>(data));
.then((data) => camelize<PostSingleConsultResponse>(data));
}
}
20 changes: 10 additions & 10 deletions src/__snapshots__/Arcus.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Arcus getAccount 1`] = `
Object {
"balance": 9991243.39,
"balance": 9982715.67,
"currency": "MXN",
"minimumBalance": 0,
"name": "rabbit",
Expand Down Expand Up @@ -160,18 +160,18 @@ Object {

exports[`Arcus getTransactionsList 1`] = `
Object {
"accountNumber": "256863285",
"amount": 12.21,
"accountNumber": "9080798098",
"amount": 20,
"amountCurrency": "MXN",
"amountUsd": 0.61,
"createdAt": "2021-01-26T09:44:35Z",
"externalId": "84bce950-c878-483e-aeca-41217f969301",
"amountUsd": 1,
"createdAt": "2021-06-02T12:15:17Z",
"externalId": "00f2b0bc-d3ee-491e-b844-4f7a36b4d24d",
"fxRate": 1,
"hoursToFulfill": 24,
"id": 100034581,
"hoursToFulfill": 0,
"id": 100149594,
"status": "fulfilled",
"ticketText": "Pago realizado exitosamente Auth: 1611654275",
"totalUsd": 0.61,
"ticketText": "Pago realizado exitosamente Auth: 1622636117",
"totalUsd": 1,
"transactionFee": 0,
"type": "transaction",
}
Expand Down
4 changes: 4 additions & 0 deletions src/typings/ArcusSingleConsultParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type ArcusSingleConsultParams = {
billerId: number;
accountNumber: string;
};
14 changes: 14 additions & 0 deletions src/typings/PostSingleConsultResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ArcusCurrency } from './ArcusCurrency';

export type PostSingleConsultResponse = {
accountNumber: number;
billerId: number;
billAmount: number;
billAmountCurrency: ArcusCurrency.MXN;
fxRate: number;
billAmountUsd: number;
billAmountChainCurrency: number;
paymentTransactionFee: number;
paymentTotalUsd: number;
paymentTotalChainCurrency: number;
};

0 comments on commit 2cd1aa9

Please sign in to comment.