From a8baa311db504d52680402578d497a29693a82c8 Mon Sep 17 00:00:00 2001 From: Flavio Takeuchi Date: Tue, 26 May 2020 20:05:50 -0300 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20altera=C3=A7=C3=A3o=20da=20bibl?= =?UTF-8?q?ioteca=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/class/cards.ts | 8 ++++---- src/class/creditcard.ts | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/class/cards.ts b/src/class/cards.ts index 408aac3..c41dc6c 100644 --- a/src/class/cards.ts +++ b/src/class/cards.ts @@ -5,19 +5,19 @@ import { CieloTransactionInterface } from './../interface/cielo-transaction.inte export class Card { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; constructor(transaction: CieloTransactionInterface) { this.cieloTransactionParams = transaction; + this.util = new Utils(this.cieloTransactionParams); } public createTokenizedCard(request: TokenizeRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: '/1/card', hostname: this.cieloTransactionParams.hostnameTransacao, }); - - return util.request(options, request); + return this.util.request(options, request); } } \ No newline at end of file diff --git a/src/class/creditcard.ts b/src/class/creditcard.ts index 84094f3..70a0fad 100644 --- a/src/class/creditcard.ts +++ b/src/class/creditcard.ts @@ -11,24 +11,24 @@ import { export class CreditCard { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; - constructor(transaction: CieloTransactionInterface) { - this.cieloTransactionParams = transaction; + constructor(cieloTransactionParams: CieloTransactionInterface) { + this.cieloTransactionParams = cieloTransactionParams; + this.util = new Utils(cieloTransactionParams); } public transaction(transaction: TransactionCreditCardRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: "/1/sales", hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, transaction); + return this.util.request(options, transaction); } public captureSaleTransaction(transaction: CaptureRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.PUT, path: `/1/sales/${transaction.paymentId}/capture`, hostname: this.cieloTransactionParams.hostnameTransacao, @@ -38,19 +38,18 @@ export class CreditCard { options.path = `${options.path}?amount=${transaction.amount}`; } - return util.request(options, {}); + return this.util.request(options, {}); } public cancelTransaction(cancelTransactionRequest: CancelTransactionRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); // Caso seja passado o valor do cancelamento, adiciona na url const amount = (cancelTransactionRequest.amount) ? `?amount=${cancelTransactionRequest.amount}` : ''; const path = (cancelTransactionRequest.paymentId) ? `/1/sales/${cancelTransactionRequest.paymentId}/void${amount}` : `/1/sales/OrderId/${cancelTransactionRequest.merchantOrderId}/void${amount}` - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.PUT, path: path, hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, {}) + return this.util.request(options, {}) } } From 25e55d9afefd5f1dcb798ec5978cfd1c4be4e0cd Mon Sep 17 00:00:00 2001 From: Flavio Takeuchi Date: Tue, 26 May 2020 20:06:45 -0300 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20retirada=20de=20arquivo=20desne?= =?UTF-8?q?cess=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 index.js diff --git a/index.js b/index.js deleted file mode 100644 index 3c74798..0000000 --- a/index.js +++ /dev/null @@ -1,41 +0,0 @@ -module.exports = (params) => { - const cielo = require('./lib/cielo')(params) - - return { - creditCard: { - simpleTransaction: cielo.postSalesCielo, - completeTransaction: cielo.postSalesCielo, - authenticationTransaction: cielo.postSalesCielo, - fraudAnalysisTransaction: cielo.postSalesCielo, - cardTokenTransaction: cielo.postSalesCielo, - captureSaleTransaction: cielo.captureSale, - cancelSale: cielo.cancelSale - }, - debitCard: { - simpleTransaction: cielo.postSalesCielo - }, - bankSlip: { - simpleTransaction: cielo.postSalesCielo - }, - boleto: { - sale: cielo.postSalesCielo - }, - recurrentPayments: { - firstScheduledRecurrence: cielo.postSalesCielo, - creditScheduledRecurrence: cielo.postSalesCielo, - authorizing: cielo.postSalesCielo, - modify: new Proxy({}, cielo.modifyingRecurrenceHandler), - consulting: cielo.recurrenceConsulting - }, - cards: { - createTokenizedCard: cielo.createTokenizedCard, - consultaTokenizedCard: cielo.consultaTokenizedCard - }, - consulting: { - sale: cielo.consultaCielo, - storeIndetifier: cielo.consultaCielo, - fraudAnalysis: cielo.consultaCielo, - cardBin: cielo.cardBin - } - } -} From 768b084295c50186b5f74533071427909acdea01 Mon Sep 17 00:00:00 2001 From: Flavio Takeuchi Date: Tue, 26 May 2020 20:26:13 -0300 Subject: [PATCH 3/4] =?UTF-8?q?fix(package.json):=20corrige=20erro=20de=20?= =?UTF-8?q?m=C3=B3dulo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correção da chamada de inicialização do pacote 63 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5f9c43a..b31d3e2 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "cielo", - "version": "2.2.3", + "version": "2.2.4-beta.1", "description": "Client para a API 3.0 da Cielo em node.js", - "main": "dist\\index.js", + "main": "dist/index.js", "scripts": { "test": "npx ts-node node_modules/tape/bin/tape tests/**/*.ts", "release": "standard-version", From 92497407c35362d7bda4b7f75788eada030c1319 Mon Sep 17 00:00:00 2001 From: Flavio Takeuchi Date: Tue, 26 May 2020 20:28:09 -0300 Subject: [PATCH 4/4] refactor: classe Utils como propriedade das classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Retirada das chamadas para classe Utils nas funções para uma propriedade dentro da classe --- src/class/bank-slip.ts | 7 ++++--- src/class/debit-card.ts | 7 ++++--- src/class/eletronic-transfer.ts | 7 ++++--- src/class/recurrent.ts | 12 ++++++------ tsconfig.json | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/class/bank-slip.ts b/src/class/bank-slip.ts index 0f2aca1..f0bfcaf 100644 --- a/src/class/bank-slip.ts +++ b/src/class/bank-slip.ts @@ -7,19 +7,20 @@ import { Utils, IHttpRequestOptions, HttpRequestMethodEnum } from "./utils"; export class BankSlip { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; constructor(transaction: CieloTransactionInterface) { this.cieloTransactionParams = transaction; + this.util = new Utils(this.cieloTransactionParams) } public create(request: BankSlipCreateRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: '/1/sales', hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, request); + return this.util.request(options, request); } } \ No newline at end of file diff --git a/src/class/debit-card.ts b/src/class/debit-card.ts index 05e411a..c42c626 100644 --- a/src/class/debit-card.ts +++ b/src/class/debit-card.ts @@ -4,18 +4,19 @@ import { Utils, IHttpRequestOptions, HttpRequestMethodEnum } from "./utils"; export class DebitCard { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; constructor(transaction: CieloTransactionInterface) { this.cieloTransactionParams = transaction; + this.util = new Utils(this.cieloTransactionParams) } public createSimpleTransaction(transaction: DebitCardSimpleTransactionRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: "/1/sales", hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, transaction); + return this.util.request(options, transaction); } } \ No newline at end of file diff --git a/src/class/eletronic-transfer.ts b/src/class/eletronic-transfer.ts index 7ef0947..ad6f943 100644 --- a/src/class/eletronic-transfer.ts +++ b/src/class/eletronic-transfer.ts @@ -4,19 +4,20 @@ import { EletronicTransferCreateResponseModel, EletronicTransferCreateRequestMod export class EletronicTransfer { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; constructor(transaction: CieloTransactionInterface) { this.cieloTransactionParams = transaction; + this.util = new Utils(this.cieloTransactionParams) } public create(request: EletronicTransferCreateRequestModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: '/1/sales', hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, request); + return this.util.request(options, request); } } \ No newline at end of file diff --git a/src/class/recurrent.ts b/src/class/recurrent.ts index f0d9346..a1c4ca8 100644 --- a/src/class/recurrent.ts +++ b/src/class/recurrent.ts @@ -16,20 +16,21 @@ import { RecurrentModifyPaymentModel } from "../models/recurrent-payment/recurre export class Recurrent { private cieloTransactionParams: CieloTransactionInterface; + private util: Utils; constructor(transaction: CieloTransactionInterface) { this.cieloTransactionParams = transaction; + this.util = new Utils(this.cieloTransactionParams) } public create(params: RecurrentCreateModel): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.POST, path: '/1/sales/', hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.request(options, params); + return this.util.request(options, params); } public modifyCustomer(params: RecurrentModifyCustomerModel): Promise { @@ -105,14 +106,13 @@ export class Recurrent { }; private modify(params: {path: string, data: string | CustomerModel | PaymentRecurrentModifyModel | number}): Promise { - const util = new Utils(this.cieloTransactionParams); - const options: IHttpRequestOptions = util.getHttpRequestOptions({ + const options: IHttpRequestOptions = this.util.getHttpRequestOptions({ method: HttpRequestMethodEnum.PUT, path: params.path, hostname: this.cieloTransactionParams.hostnameTransacao, }); - return util.httpRequest(options, params.data); + return this.util.httpRequest(options, params.data); } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a357919..7430d63 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */