From f16d305db84c0c1f060005f2a95a8319edf5e700 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Wed, 24 May 2023 16:16:20 -0300 Subject: [PATCH 01/13] adding typing for subscription routes - fixing payment routes typing --- src/client/payables/bodies.ts | 10 +++++ src/client/payables/namespace.ts | 25 +++++++++-- src/client/payables/options.ts | 17 -------- src/client/subscriptions/bodies.ts | 40 ++++++++++++++++++ src/client/subscriptions/namespace.ts | 61 ++++++++++++++++++++++----- src/common/Authentication.ts | 3 ++ src/common/Options.ts | 10 +++++ 7 files changed, 135 insertions(+), 31 deletions(-) create mode 100644 src/client/payables/bodies.ts delete mode 100644 src/client/payables/options.ts create mode 100644 src/client/subscriptions/bodies.ts create mode 100644 src/common/Options.ts diff --git a/src/client/payables/bodies.ts b/src/client/payables/bodies.ts new file mode 100644 index 0000000..3028857 --- /dev/null +++ b/src/client/payables/bodies.ts @@ -0,0 +1,10 @@ +export interface PayableFindBody { + // 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; +} diff --git a/src/client/payables/namespace.ts b/src/client/payables/namespace.ts index d68cb26..fbc1ce8 100644 --- a/src/client/payables/namespace.ts +++ b/src/client/payables/namespace.ts @@ -1,12 +1,29 @@ import { Payable } from './responses'; -import { PayableFindOptions, PayableAllOptions } from './options'; +import { PayableFindBody } from './bodies'; +import { Options } from '../../common/Options'; declare module 'pagarme' { export namespace client { export namespace payables { - function all(args: PayableAllOptions): Promise; - function find(opts: PayableFindOptions): Promise; - 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; + + /** + * 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; + + /** + * 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: PayableFindBody): Promise; } } } diff --git a/src/client/payables/options.ts b/src/client/payables/options.ts deleted file mode 100644 index 13651fa..0000000 --- a/src/client/payables/options.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface PayableFindOptions { - transaction_id: string; -} - -export interface PayableAllOptions { - createdAt?: string; - amount?: string; - recipient_id?: string; - status?: 'paid' | 'waiting_funds'; - installment?: string; - transaction_id?: string; - payment_date?: string; - type?: 'chargeback' | 'refund' | 'chargeback_refund' | 'credit'; - id?: string; - count: number; - page: number; -} diff --git a/src/client/subscriptions/bodies.ts b/src/client/subscriptions/bodies.ts new file mode 100644 index 0000000..85e8c78 --- /dev/null +++ b/src/client/subscriptions/bodies.ts @@ -0,0 +1,40 @@ +export interface SubscriptionAllBody { + // Pagination option to get a list of subscriptions. Number of subscriptions in a page + count?: number; + // Pagination option for a list of subscriptions. The page index. + page?: number; +} + +export interface SubscriptionCancelBody { + // The subscription's ID + id: number; +} + +export interface SubscriptionCreateTransactionBody { + // The subscription's ID + id: number; +} + +export interface SubscriptionFindBody { + // The subscription's ID. If not sent a subscriptions list will be returned instead. + id?: number; + // Pagination option to get a list of subscriptions. Number of subscriptions in a page + count?: number; + // Pagination option for a list of subscriptions. The page index. + page?: number; +} + +export interface SubscriptionFindTransactionsBody { + // The subscription's ID + id: number; +} + +export interface SubscriptionSettleChargeBody { + // The subscription's ID + id: number; +} + +export interface SubscriptionUpdateBody { + // The subscription's ID + id: number; +} \ No newline at end of file diff --git a/src/client/subscriptions/namespace.ts b/src/client/subscriptions/namespace.ts index e73e27e..ba4df5c 100644 --- a/src/client/subscriptions/namespace.ts +++ b/src/client/subscriptions/namespace.ts @@ -1,23 +1,64 @@ +import { Options } from "../../common/Options"; +import { SubscriptionAllBody, SubscriptionCancelBody, SubscriptionCreateTransactionBody, SubscriptionFindBody, SubscriptionFindTransactionsBody, SubscriptionSettleChargeBody, SubscriptionUpdateBody } from "./bodies"; + declare module 'pagarme' { export namespace client { export namespace subscriptions { - function all(opts: any, body: any): any; - - function cancel(opts: any, body: any): any; + /** + * Makes a request to /subscriptions to get all subscriptions + * @param opts An options params which is usually already bound by connect functions. + * @param body + */ + function all(opts: Options, body: SubscriptionAllBody): Promise; - function create(opts: any, body: any): any; + /** + * Cancels a subscription + * @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#cancelando-uma-assinatura) + */ + function cancel(opts: Options, body: SubscriptionCancelBody): Promise; - function createTransaction(opts: any, body: any): any; + /** + * Creates a subscription 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-assinaturas) + */ + function create(opts: Options, body: object): Promise; - function find(opts: any, body: any): any; + /** + * Creates a transaction for a subscription + * @param opts An options params which is usually already bound by connect functions. + * @param body The payload for the request + */ + function createTransaction(opts: Options, body: SubscriptionCreateTransactionBody): Promise; - function findAll(a0: any, a1: any, ...args: any[]): any; + /** + * Makes a request to /subscriptions or to /subscriptions/: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-uma-assinatura) + */ + function find(opts: Options, body: SubscriptionFindBody): Promise; - function findTransactions(opts: any, body: any): any; + /** + * Gets transactions for a subscription + * @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#transa%C3%A7%C3%B5es-em-uma-assinatura) + */ + function findTransactions(opts: Options, body: SubscriptionFindTransactionsBody): Promise; - function settleCharge(opts: any, body: any): any; + /** + * Skips the next x charges for a subscription + * @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/reference#pulando-cobran%C3%A7as) + */ + function settleCharge(opts: Options, body: SubscriptionSettleChargeBody): Promise; - function update(opts: any, body: any): any; + /** + * Updates a subscription 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-uma-assinatura) + */ + function update(opts: Options, body: SubscriptionUpdateBody): Promise; } } } diff --git a/src/common/Authentication.ts b/src/common/Authentication.ts index 47f3f5b..1523482 100644 --- a/src/common/Authentication.ts +++ b/src/common/Authentication.ts @@ -1,6 +1,9 @@ +import { Options } from './Options'; + export interface Authentication { api_key?: string; encryption_key?: string; email?: string; password?: string; + options?: Options } diff --git a/src/common/Options.ts b/src/common/Options.ts new file mode 100644 index 0000000..c65d4cb --- /dev/null +++ b/src/common/Options.ts @@ -0,0 +1,10 @@ +import { Authentication } from './Authentication'; + +// this object is not officially documented. +// but it is officially used as seen on pagarme-js tests: https://github.com/pagarme/pagarme-js/blob/master/test/runTest.js + +export interface Options { + baseURL?: string; + body?: Authentication; + skipAuthentication?: boolean; +} From 9d5be6af32307cd6655adecc597d520a2975fdf2 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Thu, 25 May 2023 03:16:32 -0300 Subject: [PATCH 02/13] adding typing for transactions --- src/client/transactions/namespace.ts | 83 +++++++++++++++++++++++----- src/client/transactions/options.ts | 23 ++++++++ 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/client/transactions/namespace.ts b/src/client/transactions/namespace.ts index 15a1617..97037db 100644 --- a/src/client/transactions/namespace.ts +++ b/src/client/transactions/namespace.ts @@ -1,50 +1,105 @@ +import { Options } from '../../common/Options'; import { TransactionCreateOptions, TransactionAllOptions, TransactionCalculateInstallmentsAmountOptions, TransactionFindOptions, TransactionCaptureOptions, - TransactionRefundOptions + TransactionRefundOptions, + TransactionCollectPaymentOptions, + TransactionReprocessOptions, + TransactionUpdateOptions } from './options'; import { Transaction, CalculateInstallmentsAmount, CardHashKey } from './responses'; declare module 'pagarme' { export namespace client { export namespace transactions { + /** + * Makes a request to /transactions to get all transactions. + * @param opts An options params which is usually already bound by connect functions. + * @param body + */ function all( - opts: any, + opts: Options, body: TransactionAllOptions ): Promise; + /** + * Calculates the value of each purchase's installments + * @param opts An options params which is usually already bound by connect functions. + * @param body + */ function calculateInstallmentsAmount( - opts: any, + opts: Options, body: TransactionCalculateInstallmentsAmountOptions ): Promise; - function capture(opts: TransactionCaptureOptions): Promise; + /** + * Captures a transaction from the given id. + * @param opts An options params which is usually already bound by connect functions. + * @param body + */ + function capture(opts: Options, body: TransactionCaptureOptions): Promise; - function cardHashKey(opts: any): Promise; + /** + * Create a card hash key + * @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://dash.readme.io/project/pagarme/v1/refs/gerando-card_hash-manualmente-1) + */ + function cardHashKey(opts: Options, body: object): Promise; - function collectPayment(opts: any, body: any): any; + /** + * Sends a payment link to a customer + * @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/reference#notificando-cliente-sobre-boleto-a-ser-pago) + */ + function collectPayment(opts: Options, body: TransactionCollectPaymentOptions): Promise; - function create(opts: TransactionCreateOptions): Promise; + /** + * Creates a transaction 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/reference#criar-transa%C3%A7%C3%A3o) + */ + function create(opts: Options, body: TransactionCreateOptions): Promise; + /** + * Makes a request to /transactions or to /transactions/: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/reference#retornando-transa%C3%A7%C3%B5es) + */ function find( - opts: any, + opts: Options, body: T ): Promise< T extends TransactionFindOptions ? Transaction[] : Transaction >; + /** + * Refunds a transaction from the given id. + * @param body The payload for the request. API Reference for this payload (https://pagarme.readme.io/reference#estorno-de-transa%C3%A7%C3%A3o) + */ function refund(body: TransactionRefundOptions): Promise; - function refund( - opts: any, - body: TransactionRefundOptions - ): Promise; + /** + * Refunds a transaction from the given 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/reference#estorno-de-transa%C3%A7%C3%A3o) + */ + function refund(opts: Options, body: TransactionRefundOptions): Promise; - function reprocess(opts: any, body: any): any; + /** + * Reprocess a transaction from the given id. + * @param opts An options params which is usually already bound by connect functions. + * @param body + */ + function reprocess(opts: Options, body: TransactionReprocessOptions): Promise; - function update(opts: any, body: any): any; + /** + * Updates a transaction from the given payload. + * @param opts An options params which is usually already bound by connect functions. + * @param body The payload for the request. + */ + function update(opts: Options, body: TransactionUpdateOptions): Promise; } } } diff --git a/src/client/transactions/options.ts b/src/client/transactions/options.ts index 4e3089d..a47f774 100644 --- a/src/client/transactions/options.ts +++ b/src/client/transactions/options.ts @@ -106,3 +106,26 @@ interface TransactionFindOptionsById { export type TransactionFindOptions = | TransactionFindOptionsByData | TransactionFindOptionsById; + +export interface TransactionCollectPaymentOptions { + // The transaction id + id: number; + // User email to send the payment request + email: string; +} + +export interface TransactionReprocessOptions { + // The transaction ID. + id: number; + // Should capture the transaction. + capture: boolean; + // Should analyze the transaction. + analyze: boolean; +} + +export interface TransactionUpdateOptions { + // The transaction ID + id: number; + // The transaction status + status: number; +} \ No newline at end of file From 781572980600245dd8f4029cc56599c254181e5d Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Thu, 25 May 2023 03:19:14 -0300 Subject: [PATCH 03/13] reading options --- src/client/payables/bodies.ts | 10 ---------- src/client/payables/namespace.ts | 2 +- src/client/payables/options.ts | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) delete mode 100644 src/client/payables/bodies.ts create mode 100644 src/client/payables/options.ts diff --git a/src/client/payables/bodies.ts b/src/client/payables/bodies.ts deleted file mode 100644 index 3028857..0000000 --- a/src/client/payables/bodies.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface PayableFindBody { - // 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; -} diff --git a/src/client/payables/namespace.ts b/src/client/payables/namespace.ts index fbc1ce8..4968d82 100644 --- a/src/client/payables/namespace.ts +++ b/src/client/payables/namespace.ts @@ -1,5 +1,5 @@ import { Payable } from './responses'; -import { PayableFindBody } from './bodies'; +import { PayableFindOptions } from './options'; import { Options } from '../../common/Options'; declare module 'pagarme' { diff --git a/src/client/payables/options.ts b/src/client/payables/options.ts new file mode 100644 index 0000000..bfcccfd --- /dev/null +++ b/src/client/payables/options.ts @@ -0,0 +1,24 @@ +export interface PayableFindOptions { + // 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 { + createdAt?: string; + amount?: string; + recipient_id?: string; + status?: 'paid' | 'waiting_funds'; + installment?: string; + transaction_id?: string; + payment_date?: string; + type?: 'chargeback' | 'refund' | 'chargeback_refund' | 'credit'; + id?: string; + count: number; + page: number; +} \ No newline at end of file From 3d27b3d9023d47915cbdfcfb947c94cf2418f7e6 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Thu, 25 May 2023 03:20:52 -0300 Subject: [PATCH 04/13] reading options --- src/client/payables/namespace.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/client/payables/namespace.ts b/src/client/payables/namespace.ts index 4968d82..51f306d 100644 --- a/src/client/payables/namespace.ts +++ b/src/client/payables/namespace.ts @@ -1,5 +1,5 @@ import { Payable } from './responses'; -import { PayableFindOptions } from './options'; +import { PayableFindOptions, PayableAllOptions } from './options'; import { Options } from '../../common/Options'; declare module 'pagarme' { @@ -11,6 +11,11 @@ declare module 'pagarme' { * @param body The payload for the request. https://docs-beta.pagar.me/v1/reference#retornando-recebíveis */ function all(opts: Options, body: object): Promise; + /** + * 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; /** * Returns a company's payables aggregated by day @@ -23,7 +28,12 @@ declare module 'pagarme' { * @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: PayableFindBody): Promise; + function find(opts: Options, body: PayableFindOptions): Promise; + /** + * 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; } } } From ceb7f8477ba609bd4b7002832edaa1d71369fdd8 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Thu, 25 May 2023 03:24:11 -0300 Subject: [PATCH 05/13] ok --- src/client/subscriptions/namespace.ts | 16 ++++++++-------- .../subscriptions/{bodies.ts => options.ts} | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) rename src/client/subscriptions/{bodies.ts => options.ts} (68%) diff --git a/src/client/subscriptions/namespace.ts b/src/client/subscriptions/namespace.ts index ba4df5c..10ccfdb 100644 --- a/src/client/subscriptions/namespace.ts +++ b/src/client/subscriptions/namespace.ts @@ -1,5 +1,5 @@ import { Options } from "../../common/Options"; -import { SubscriptionAllBody, SubscriptionCancelBody, SubscriptionCreateTransactionBody, SubscriptionFindBody, SubscriptionFindTransactionsBody, SubscriptionSettleChargeBody, SubscriptionUpdateBody } from "./bodies"; +import { SubscriptionAllOptions, SubscriptionCancelOptions, SubscriptionCreateTransactionOptions, SubscriptionFindOptions, SubscriptionFindTransactionsOptions, SubscriptionSettleChargeOptions, SubscriptionUpdateOptions } from "./options"; declare module 'pagarme' { export namespace client { @@ -9,14 +9,14 @@ declare module 'pagarme' { * @param opts An options params which is usually already bound by connect functions. * @param body */ - function all(opts: Options, body: SubscriptionAllBody): Promise; + function all(opts: Options, body: SubscriptionAllOptions): Promise; /** * Cancels a subscription * @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#cancelando-uma-assinatura) */ - function cancel(opts: Options, body: SubscriptionCancelBody): Promise; + function cancel(opts: Options, body: SubscriptionCancelOptions): Promise; /** * Creates a subscription from the given payload. @@ -30,35 +30,35 @@ declare module 'pagarme' { * @param opts An options params which is usually already bound by connect functions. * @param body The payload for the request */ - function createTransaction(opts: Options, body: SubscriptionCreateTransactionBody): Promise; + function createTransaction(opts: Options, body: SubscriptionCreateTransactionOptions): Promise; /** * Makes a request to /subscriptions or to /subscriptions/: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-uma-assinatura) */ - function find(opts: Options, body: SubscriptionFindBody): Promise; + function find(opts: Options, body: SubscriptionFindOptions): Promise; /** * Gets transactions for a subscription * @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#transa%C3%A7%C3%B5es-em-uma-assinatura) */ - function findTransactions(opts: Options, body: SubscriptionFindTransactionsBody): Promise; + function findTransactions(opts: Options, body: SubscriptionFindTransactionsOptions): Promise; /** * Skips the next x charges for a subscription * @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/reference#pulando-cobran%C3%A7as) */ - function settleCharge(opts: Options, body: SubscriptionSettleChargeBody): Promise; + function settleCharge(opts: Options, body: SubscriptionSettleChargeOptions): Promise; /** * Updates a subscription 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-uma-assinatura) */ - function update(opts: Options, body: SubscriptionUpdateBody): Promise; + function update(opts: Options, body: SubscriptionUpdateOptions): Promise; } } } diff --git a/src/client/subscriptions/bodies.ts b/src/client/subscriptions/options.ts similarity index 68% rename from src/client/subscriptions/bodies.ts rename to src/client/subscriptions/options.ts index 85e8c78..caf9a89 100644 --- a/src/client/subscriptions/bodies.ts +++ b/src/client/subscriptions/options.ts @@ -1,21 +1,21 @@ -export interface SubscriptionAllBody { +export interface SubscriptionAllOptions { // Pagination option to get a list of subscriptions. Number of subscriptions in a page count?: number; // Pagination option for a list of subscriptions. The page index. page?: number; } -export interface SubscriptionCancelBody { +export interface SubscriptionCancelOptions { // The subscription's ID id: number; } -export interface SubscriptionCreateTransactionBody { +export interface SubscriptionCreateTransactionOptions { // The subscription's ID id: number; } -export interface SubscriptionFindBody { +export interface SubscriptionFindOptions { // The subscription's ID. If not sent a subscriptions list will be returned instead. id?: number; // Pagination option to get a list of subscriptions. Number of subscriptions in a page @@ -24,17 +24,17 @@ export interface SubscriptionFindBody { page?: number; } -export interface SubscriptionFindTransactionsBody { +export interface SubscriptionFindTransactionsOptions { // The subscription's ID id: number; } -export interface SubscriptionSettleChargeBody { +export interface SubscriptionSettleChargeOptions { // The subscription's ID id: number; } -export interface SubscriptionUpdateBody { +export interface SubscriptionUpdateOptions { // The subscription's ID id: number; } \ No newline at end of file From ef5d51f8f64d0818a56dff744e830758c8989823 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Fri, 26 May 2023 00:16:11 -0300 Subject: [PATCH 06/13] adding typing for cards --- src/client/cards/namespace.ts | 37 ++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/client/cards/namespace.ts b/src/client/cards/namespace.ts index 9477404..355d9a8 100644 --- a/src/client/cards/namespace.ts +++ b/src/client/cards/namespace.ts @@ -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>; + /** + * 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; + /** + * 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; + /** + * 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 + */ + function create(opts: Options, body: CardCreateOptions): Promise; + /** + * Creates a card from the given payload. + * @param body The payload for the request API Reference for this payload + */ function create(body: CardCreateOptions): Promise; + /** + * 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 + */ + function find(opts: Options, body: CardFindOptions): Promise; + /** + * Makes a request to /cards or to /cards/:id + * @param body The payload for the request. API Reference for this payload + */ function find(body: CardFindOptions): Promise; } } From 53a3b51342cfc3132af728e0bc506dce75c1edb3 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 14:03:21 -0300 Subject: [PATCH 07/13] adding postbacks typing --- src/client/cards/namespace.ts | 8 ++++---- src/client/postbacks/namespace.ts | 18 ++++++++++++++++-- src/client/postbacks/options.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 src/client/postbacks/options.ts diff --git a/src/client/cards/namespace.ts b/src/client/cards/namespace.ts index 355d9a8..caac25b 100644 --- a/src/client/cards/namespace.ts +++ b/src/client/cards/namespace.ts @@ -20,24 +20,24 @@ declare module 'pagarme' { /** * 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 + * @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; /** * Creates a card from the given payload. - * @param body The payload for the request API Reference for this 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; /** * 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 + * @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; /** * Makes a request to /cards or to /cards/:id - * @param body The payload for the request. API Reference for this payload + * @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; } diff --git a/src/client/postbacks/namespace.ts b/src/client/postbacks/namespace.ts index 052a7f4..a972c3d 100644 --- a/src/client/postbacks/namespace.ts +++ b/src/client/postbacks/namespace.ts @@ -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; } } } diff --git a/src/client/postbacks/options.ts b/src/client/postbacks/options.ts new file mode 100644 index 0000000..d2937a6 --- /dev/null +++ b/src/client/postbacks/options.ts @@ -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; +} \ No newline at end of file From 842dc4ccde6ea7480c6294382f4c49201322b227 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 15:37:48 -0300 Subject: [PATCH 08/13] adding security typing --- src/client/security/namespace.ts | 35 ++++++++++++++++++++++++-------- src/client/security/options.ts | 10 +++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/client/security/options.ts diff --git a/src/client/security/namespace.ts b/src/client/security/namespace.ts index 45001a3..efc2700 100644 --- a/src/client/security/namespace.ts +++ b/src/client/security/namespace.ts @@ -1,16 +1,35 @@ +import { Options } from "../../common/Options"; +import { SecurityEncryptOptions } from './options'; + declare module 'pagarme' { export namespace client { export namespace security { - function encrypt(card: { - card_holder_name: string; - card_expiration_date: string; - card_number: string; - card_cvv: string; - }): Promise; + /** + * Encrypt a card object into a card_hash + * @param opts An options params which is usually already bound by connect functions. + * @param card The card object. API Reference for this payload (https://pagarme.readme.io/v1/reference#gerando-card_hash-manualmente) + */ + function encrypt(opts: Options, card: SecurityEncryptOptions): Promise; + /** + * Encrypt a card object into a card_hash + * @param card The card object. API Reference for this payload (https://pagarme.readme.io/v1/reference#gerando-card_hash-manualmente) + */ + function encrypt(card: SecurityEncryptOptions): Promise; - function sign(opts: any, string: any): any; + /** + * Generates a hash signed with your api_key. This is used mainly to validate postbacks, this functions is the same as pagarme.postback.calculatesignature but it already knows your api_key. + * @param opts An options params which is usually already bound by connect functions. + * @param string The string to be hashed. + */ + function sign(opts: Options, string: string): any; - function verify(opts: any, string: any, expected: any): any; + /** + * Verifies a hash signed with your api_key. This is used mainly to validate postbacks, this functions is the same as pagarme.postback.validateSignature but it already knows your api_key. + * @param opts An options params which is usually already bound by connect functions. + * @param string The string to be hashed. + * @param expected The expected result. + */ + function verify(opts: Options, string: string, expected: string): boolean; } } } diff --git a/src/client/security/options.ts b/src/client/security/options.ts new file mode 100644 index 0000000..bf8b142 --- /dev/null +++ b/src/client/security/options.ts @@ -0,0 +1,10 @@ +export interface SecurityEncryptOptions { + // The card's holder name. Example: 'Pedro Paulo' + card_holder_name: string; + // The card's expiration date. Example: '1225' or '12/25' + card_expiration_date: string; + // The card's number. Example: '4111111111111111' + card_number: string; + // The card's cvv. Example: '543' + card_cvv: string; +} \ No newline at end of file From cc66548af08bb6a3f96c32f153ba2438d7017424 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 15:43:26 -0300 Subject: [PATCH 09/13] adding events routes --- src/client/events/namespace.ts | 17 +++++++++++++++-- src/client/events/options.ts | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/client/events/options.ts diff --git a/src/client/events/namespace.ts b/src/client/events/namespace.ts index bb2b028..531c434 100644 --- a/src/client/events/namespace.ts +++ b/src/client/events/namespace.ts @@ -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): 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): any; } } } diff --git a/src/client/events/options.ts b/src/client/events/options.ts new file mode 100644 index 0000000..1d631cd --- /dev/null +++ b/src/client/events/options.ts @@ -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; +} \ No newline at end of file From 28589acac1e0b73d231418294177a6347d635a77 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 15:56:18 -0300 Subject: [PATCH 10/13] adding events and paymentLinks types --- src/client/events/namespace.ts | 4 ++-- src/client/paymentLinks/namespace.ts | 31 ++++++++++++++++++++++++---- src/client/paymentLinks/options.ts | 31 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/client/paymentLinks/options.ts diff --git a/src/client/events/namespace.ts b/src/client/events/namespace.ts index 531c434..0b545d0 100644 --- a/src/client/events/namespace.ts +++ b/src/client/events/namespace.ts @@ -9,13 +9,13 @@ declare module 'pagarme' { * @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): any; + function find(opts: Options, body: EventsFindCustomOptions): Promise; /** * 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): any; + function findCustom(opts: Options, body: object): Promise; } } } diff --git a/src/client/paymentLinks/namespace.ts b/src/client/paymentLinks/namespace.ts index bc0a884..5a6360a 100644 --- a/src/client/paymentLinks/namespace.ts +++ b/src/client/paymentLinks/namespace.ts @@ -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; - 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; - 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; - 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; } } } diff --git a/src/client/paymentLinks/options.ts b/src/client/paymentLinks/options.ts new file mode 100644 index 0000000..298bca7 --- /dev/null +++ b/src/client/paymentLinks/options.ts @@ -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; +} \ No newline at end of file From c1e3bc89a22b33e6c85a047c36e7758ed133333c Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 16:03:51 -0300 Subject: [PATCH 11/13] adding plan types --- src/client/plans/namespace.ts | 31 +++++++++++++++++++++++++++---- src/client/plans/options.ts | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/client/plans/options.ts diff --git a/src/client/plans/namespace.ts b/src/client/plans/namespace.ts index cb4c064..945db4b 100644 --- a/src/client/plans/namespace.ts +++ b/src/client/plans/namespace.ts @@ -1,15 +1,38 @@ +import { Options } from "../../common/Options"; +import { PlansAllOptions, 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; - 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: object): Promise; - 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; 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; } } } diff --git a/src/client/plans/options.ts b/src/client/plans/options.ts new file mode 100644 index 0000000..860a112 --- /dev/null +++ b/src/client/plans/options.ts @@ -0,0 +1,24 @@ +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 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; +} From 3d4de7842a75c759fd3e761c6e9cdaa951c0b2e3 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 16:07:10 -0300 Subject: [PATCH 12/13] adding plan create body --- src/client/plans/namespace.ts | 4 ++-- src/client/plans/options.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client/plans/namespace.ts b/src/client/plans/namespace.ts index 945db4b..1af1b41 100644 --- a/src/client/plans/namespace.ts +++ b/src/client/plans/namespace.ts @@ -1,5 +1,5 @@ import { Options } from "../../common/Options"; -import { PlansAllOptions, PlansFindOptions, PlansUpdateOptions } from './options'; +import { PlansAllOptions, PlansCreateOptions, PlansFindOptions, PlansUpdateOptions } from './options'; declare module 'pagarme' { export namespace client { @@ -16,7 +16,7 @@ declare module 'pagarme' { * @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: object): Promise; + function create(opts: Options, body: PlansCreateOptions): Promise; /** * Makes a request to /plans or to /plans/:id diff --git a/src/client/plans/options.ts b/src/client/plans/options.ts index 860a112..4617938 100644 --- a/src/client/plans/options.ts +++ b/src/client/plans/options.ts @@ -5,6 +5,15 @@ export interface PlansAllOptions { 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; From 0a5ddd284238716e89ba9bc0792cbd8bf103a191 Mon Sep 17 00:00:00 2001 From: Ezequiel Ramos Date: Sat, 27 May 2023 16:22:41 -0300 Subject: [PATCH 13/13] ok --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14526e1..5c0ce69 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 +/// + +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: @@ -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 @@ -82,6 +94,7 @@ You can create a PR to contribute, for now these functions are typed: - [x] validate ### Security + - [x] encrypt ## Contributors ✨