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

Adding typing for some missing objects #163

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ It's a **work in progress**. All type definition are take from the **[official d

## 🤔 How to use?


1. Install the package as `devDependencies` using `npm` or `yarn`
1. Install the package as `devDependencies` using `npm` or `yarn`

```sh
npm install --save-dev pagarme-js-types
Expand All @@ -27,19 +26,30 @@ npm install --save-dev pagarme-js-types
...
```

Or if that doesn't work for you, instead of changing the tsconfig.json file,
Or if that doesn't work for you, instead of changing the tsconfig.json file,
just create the following file:

```ts
// src/@types/pagarme.d.ts
import 'pagarme-js-types/src/index';
```

If you are using an older nodejs version, you can add a reference to this lib including on the first line of you file:

```javascript
/// <reference path="node_modules/pagarme-js-types/src/index.ts" />

const pagarme = require('pagarme');
```

See more in the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html).

## 💪 How to contribute

Thanks for give support to this project. To contribute you need to create a fork of this repo and send a Pull Request. Every contributor is mentioned at [Contributors list](#Contributors)

### Structure

All the code are in the `src` folder that follows the same location of Pagar.me lib.
Each *"module"* of Pagar.me lib is a folder that contains at least:

Expand All @@ -50,9 +60,11 @@ Each *"module"* of Pagar.me lib is a folder that contains at least:
Shared interfaces are in the folder called `common` in `src` root.

### Commits

This projects uses [commit lint to checks commit message](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum)

### Sending a PR

Just explains what you are changing and why. I will love if you sent where did you get this information too. Thanks 😍

## To do
Expand Down Expand Up @@ -82,6 +94,7 @@ You can create a PR to contribute, for now these functions are typed:
- [x] validate

### Security

- [x] encrypt

## Contributors ✨
Expand Down
37 changes: 34 additions & 3 deletions src/client/cards/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import {CardCreateOptions, CardFindOptions, CardAllOptions} from "./options";
import {Card} from "./responses";
import { Options } from "../../common/Options";
import { CardCreateOptions, CardFindOptions, CardAllOptions } from "./options";
import { Card } from "./responses";

declare module 'pagarme' {
export namespace client {
export namespace cards {
function all(pagination: CardAllOptions): Promise<Array<Card>>;
/**
* Makes a request to /cards
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-todos-os-cart%C3%B5es)
*/
function all(opts: Options, body: CardAllOptions): Promise<Card[]>;
/**
* Makes a request to /cards
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-todos-os-cart%C3%B5es)
*/
function all(body: CardAllOptions): Promise<Card[]>;

/**
* Creates a card from the given payload.
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request API Reference for this payload (https://pagarme.readme.io/v1/reference#criando-um-cartao)
*/
function create(opts: Options, body: CardCreateOptions): Promise<Card>;
/**
* Creates a card from the given payload.
* @param body The payload for the request API Reference for this payload (https://pagarme.readme.io/v1/reference#criando-um-cartao)
*/
function create(body: CardCreateOptions): Promise<Card>;

/**
* Makes a request to /cards or to /cards/:id
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-cart%C3%A3o-salvo-1)
*/
function find(opts: Options, body: CardFindOptions): Promise<Card>;
/**
* Makes a request to /cards or to /cards/:id
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-cart%C3%A3o-salvo-1)
*/
function find(body: CardFindOptions): Promise<Card>;
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/client/events/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { Options } from "../../common/Options";
import { EventsFindCustomOptions } from './options';

declare module 'pagarme' {
export namespace client {
export namespace events {
function find(opts: any, body: any): any;
function findCustom(opts: any, body: any): any;
/**
*
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-todos-os-eventos-de-uma-transa%C3%A7%C3%A3o)
*/
function find(opts: Options, body: EventsFindCustomOptions): Promise<any[]>;
/**
* Makes a request to /events
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request.
*/
function findCustom(opts: Options, body: object): Promise<any>;
}
}
}
10 changes: 10 additions & 0 deletions src/client/events/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface EventsFindCustomOptions {
// The event ID.
id?: number;
// A transaction ID to get all the events.
transactionId?: number;
// Pagination option for transaction list. Number of transaction in a page
count?: number;
// Pagination option for transaction list. The page index.
page?: number;
}
33 changes: 30 additions & 3 deletions src/client/payables/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import { Payable } from './responses';
import { PayableFindOptions, PayableAllOptions } from './options';
import { Options } from '../../common/Options';

declare module 'pagarme' {
export namespace client {
export namespace payables {
function all(args: PayableAllOptions): Promise<Payable[]>;
function find(opts: PayableFindOptions): Promise<Payable[]>;
function days(opts: any, body: any): any;
/**
* Makes a request to /payables
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. https://docs-beta.pagar.me/v1/reference#retornando-recebíveis
*/
function all(opts: Options, body: object): Promise<Payable[]>;
/**
* Makes a request to /payables
* @param body The payload for the request. https://docs-beta.pagar.me/v1/reference#retornando-recebíveis
*/
function all(body: PayableAllOptions): Promise<Payable[]>;

/**
* Returns a company's payables aggregated by day
* @param opts An options params which is usually already bound by connect functions.
*/
function days(opts: Options): Promise<any>;

/**
* Makes a request to /payables or to /payables/:id
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-receb%C3%ADvel)
*/
function find(opts: Options, body: PayableFindOptions): Promise<Payable[]>;
/**
* Makes a request to /payables or to /payables/:id
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-receb%C3%ADvel)
*/
function find(body: PayableFindOptions): Promise<Payable[]>;
}
}
}
11 changes: 9 additions & 2 deletions src/client/payables/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export interface PayableFindOptions {
transaction_id: string;
// The payable ID. If not sent a
id?: string;
// A transaction ID to get all the payables.
transactionId?: string;
// Pagination option for transaction list. Number of transaction in a page
count?: number;
// Pagination option for transaction list. The page index.
page?: number;
}

export interface PayableAllOptions {
Expand All @@ -14,4 +21,4 @@ export interface PayableAllOptions {
id?: string;
count: number;
page: number;
}
}
31 changes: 27 additions & 4 deletions src/client/paymentLinks/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
import { Options } from "../../common/Options";
import { PaymentLinksAllOptions, PaymentLinksCancelOptions, PaymentLinksCreateOptions, PaymentLinksFindOptions } from './options';

declare module 'pagarme' {
export namespace client {
export namespace paymentLinks {
function all(opts: any, body: any): any;
/**
* Makes a request to /payment_links to get all paymentLinks.
* @param opts An options params which is usually already bound by connect functions.
* @param body
*/
function all(opts: Options, body: PaymentLinksAllOptions): Promise<any>;

function cancel(opts: any, body: any): any;
/**
* Cancels a paymentLink from the given id.
* @param opts An options params which is usually already bound by connect functions.
* @param body
*/
function cancel(opts: Options, body: PaymentLinksCancelOptions): Promise<any>;

function create(opts: any, body: any): any;
/**
* Creates a paymentLink from the given payload.
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://docs.pagar.me/v2017-08-28/reference#criando-um-link-de-pagamento-1)
*/
function create(opts: Options, body: PaymentLinksCreateOptions): Promise<any>;

function find(opts: any, body: any): any;
/**
* Makes a request to /payment_links or to /payment_links/:id
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://docs.pagar.me/v2017-08-28/reference#retornando-links-de-pagamento)
*/
function find(opts: Options, body: PaymentLinksFindOptions): Promise<any>;
}
}
}
31 changes: 31 additions & 0 deletions src/client/paymentLinks/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface PaymentLinksAllOptions {
// Pagination option for paymentLink list. Number of paymentLink in a page
count?: number;
// Pagination option for paymentLink list. The page index.
page?: number;
}

export interface PaymentLinksCancelOptions {
// The paymentLink ID.
id: number;
}

export interface PaymentLinksCreateOptions {
// Name
name: string;
// Value in BRL cents
amount: number;
// Items of purchase
items: object[];
// Payment methos configurations
payment_config: object;
}

export interface PaymentLinksFindOptions {
// The paymentLink ID. If not sent a paymentLink list will be returned instead.
id?: number;
// Pagination option for paymentLink list. Number of paymentLink in a page
count?: number;
// Pagination option for paymentLink list. The page index.
page?: number;
}
31 changes: 27 additions & 4 deletions src/client/plans/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import { Options } from "../../common/Options";
import { PlansAllOptions, PlansCreateOptions, PlansFindOptions, PlansUpdateOptions } from './options';

declare module 'pagarme' {
export namespace client {
export namespace plans {
function all(opts: any, pagination: any): any;
/**
* Makes a request to /plans
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-planos)
*/
function all(opts: Options, body: PlansAllOptions): Promise<any>;

function create(opts: any, body: any): any;
/**
* Creates a plan from the given payload.
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request API Reference for this payload (https://pagarme.readme.io/v1/reference#criando-planos)
*/
function create(opts: Options, body: PlansCreateOptions): Promise<any>;

function find(opts: any, body: any): any;
/**
* Makes a request to /plans or to /plans/:id
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-plano)
*/
function find(opts: Options, body: PlansFindOptions): Promise<any>;

function findAll(a0: any, a1: any, ...args: any[]): any;

function update(opts: any, body: any): any;
/**
* Updates a plans from the given payload.
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request API Reference for this payload (https://pagarme.readme.io/v1/reference#atualizando-planos)
*/
function update(opts: Options, body: PlansUpdateOptions): Promise<any>;
}
}
}
33 changes: 33 additions & 0 deletions src/client/plans/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export interface PlansAllOptions {
// Pagination option to get a list of plans. Number of plans in a page
count?: number;
// Pagination option for a list of plans. The page index.
page?: number;
}

export interface PlansCreateOptions {
// Plan value in BRL cents
amount: number;
// Billing cycle
days: string;
// Plan name
name: string;
}

export interface PlansFindOptions {
// The plan's ID. If not sent a plans list will be returned instead.
id?: number;
// Pagination option to get a list of plans. Number of plans in a page
count?: number;
// Pagination option for a list of plans. The page index.
page?: number;
}

export interface PlansUpdateOptions {
// The plan's ID
id?: number;
// The plan's name
name?: string;
// The number of days to test the plan with no charges
trial_days?: number;
}
18 changes: 16 additions & 2 deletions src/client/postbacks/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { Options } from "../../common/Options";
import { PostbacksFindOptions } from './options';

declare module 'pagarme' {
export namespace client {
export namespace postbacks {
function find(opts: any, body: any): any;
function redeliver(opts: any, body: any): any;
/**
*
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#retornando-um-postback)
*/
function find(opts: Options, body: PostbacksFindOptions): any;

/**
* Redeliver a POSTback for a model
* @param opts An options params which is usually already bound by connect functions.
* @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/v1/reference#reenviando-um-postback)
*/
function redeliver(opts: Options, body: any): any;
}
}
}
8 changes: 8 additions & 0 deletions src/client/postbacks/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface PostbacksFindOptions {
// The operation ID.
id?: number;
// A transaction ID to get all the operations.
transactionId?: number;
// A subscription ID
subscriptionId?: number;
}
Loading