Skip to content

Commit

Permalink
Merge pull request #66 from banzeh/fix/63
Browse files Browse the repository at this point in the history
Fix/63
  • Loading branch information
banzeh authored May 26, 2020
2 parents a0810c0 + d5cfc2c commit 4f6e721
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 73 deletions.
41 changes: 0 additions & 41 deletions index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/class/bank-slip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BankSlipCreateResponseModel> {
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<BankSlipCreateResponseModel>(options, request);
return this.util.request<BankSlipCreateResponseModel>(options, request);
}
}
8 changes: 4 additions & 4 deletions src/class/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenizeResponseModel> {
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<TokenizeResponseModel>(options, request);
return this.util.request<TokenizeResponseModel>(options, request);
}
}
21 changes: 10 additions & 11 deletions src/class/creditcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionCreditCardResponseModel> {
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<TransactionCreditCardResponseModel>(options, transaction);
return this.util.request<TransactionCreditCardResponseModel>(options, transaction);
}

public captureSaleTransaction(transaction: CaptureRequestModel): Promise<CaptureResponseModel> {
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,
Expand All @@ -38,19 +38,18 @@ export class CreditCard {
options.path = `${options.path}?amount=${transaction.amount}`;
}

return util.request<CaptureResponseModel>(options, {});
return this.util.request<CaptureResponseModel>(options, {});
}

public cancelTransaction(cancelTransactionRequest: CancelTransactionRequestModel): Promise<CancelTransactionResponseModel> {
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<CancelTransactionResponseModel>(options, {})
return this.util.request<CancelTransactionResponseModel>(options, {})
}
}
7 changes: 4 additions & 3 deletions src/class/debit-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebitCardSimpleTransactionResponseModel> {
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<DebitCardSimpleTransactionResponseModel>(options, transaction);
return this.util.request<DebitCardSimpleTransactionResponseModel>(options, transaction);
}
}
7 changes: 4 additions & 3 deletions src/class/eletronic-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EletronicTransferCreateResponseModel> {
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<EletronicTransferCreateResponseModel>(options, request);
return this.util.request<EletronicTransferCreateResponseModel>(options, request);
}
}
12 changes: 6 additions & 6 deletions src/class/recurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecurrentCreateResponse> {
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<RecurrentCreateResponse>(options, params);
return this.util.request<RecurrentCreateResponse>(options, params);
}

public modifyCustomer(params: RecurrentModifyCustomerModel): Promise<IHttpResponse> {
Expand Down Expand Up @@ -105,14 +106,13 @@ export class Recurrent {
};

private modify<T>(params: {path: string, data: string | CustomerModel | PaymentRecurrentModifyModel | number}): Promise<IHttpResponse> {
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);
}

}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 4f6e721

Please sign in to comment.