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 - } - } -} diff --git a/package.json b/package.json index 57d412f..92f911e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "cielo", "version": "2.2.5", "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", 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/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, {}) } } 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. */