Skip to content

Commit

Permalink
Merge pull request #16 from onready/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Juan Cernadas authored Jun 29, 2020
2 parents 11e2ed7 + 3519355 commit b98d7a5
Show file tree
Hide file tree
Showing 44 changed files with 1,014 additions and 39 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

## VTEX NODE SDK

<p>
<a href="https://www.npmjs.com/package/@onreadydesa/vtex-node-sdk" target="_blank"><img src="https://img.shields.io/npm/v/@onreadydesa/vtex-node-sdk" alt="npm version" height="20"></a>
<img src="https://github.com/onready/vtex-node-sdk/workflows/Node.js%20CI/badge.svg" alt="node-js-ci" height="20">
<img src="https://img.shields.io/npm/dm/@onreadydesa/vtex-node-sdk" alt="downloads" height="20">
<img src="https://img.shields.io/npm/l/@onreadydesa/vtex-node-sdk" alt="license" height="20">
</p>

- :hammer: Built 100% with Typescript.
- :muscle: 0 dependencies. It uses the native `https` Node module.
- :tada: Promise based.
Expand Down Expand Up @@ -91,7 +98,9 @@ Logistics | :white_check_mark: |
Pricing | :white_check_mark: |
Master Data (V2) | :white_check_mark: (*) <em>Attachments API pending</em> |
Catalog | :white_check_mark: |
Search | Comming soon... |
Search | :white_check_mark: |
Payments Gateway | :white_check_mark: |
Suggestions | Comming soon... |
Antifraud Provider | :x: |
Checkout | :x: |
CMS | :x: |
Expand All @@ -101,9 +110,7 @@ Giftcard Hub | :x: |
Giftcard Provider Protocol | :x: |
License Manager | :x: |
Payment Provider Protocol | :x: |
Payments Gateway | :x: |
Rates and Benefits | :x: |
Session Manager | :x: |
Subscriptions (V2) | :x: |
Suggestions | :x: |
VTEX DO | :x: |
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onreadydesa/vtex-node-sdk",
"version": "1.4.0-alpha",
"version": "1.6.0-beta",
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
"author": "Onready",
"private": false,
Expand Down Expand Up @@ -43,17 +43,17 @@
"@babel/preset-typescript": "7.10.1",
"@types/jest": "26.0.3",
"@types/node": "14.0.14",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
"@typescript-eslint/eslint-plugin": "3.5.0",
"@typescript-eslint/parser": "3.5.0",
"babel-jest": "26.1.0",
"eslint": "7.3.1",
"eslint-config-airbnb-base": "14.2.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "23.17.1",
"eslint-plugin-prettier": "3.1.4",
"jest": "26.1.0",
"nock": "12.0.3",
"nock": "13.0.0",
"prettier": "2.0.5",
"rimraf": "3.0.2",
"ts-jest": "26.1.1",
Expand Down
19 changes: 19 additions & 0 deletions src/VTEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { Logistics } from "./modules/logistics";
import { Pricing } from "./modules/pricing";
import { MasterData } from "./modules/master-data/v2";
import { Catalog } from "./modules/catalog";
import { Search } from "./modules/search";
import {
PaymentsGateway,
VtexPaymentsHttpClient,
} from "./modules/payments-gateway";

export class VTEX {
private static buildErrorMessage(paramName: string): string {
Expand Down Expand Up @@ -54,6 +59,16 @@ export class VTEX {
*/
readonly catalog: Catalog;

/**
* Search Module
*/
readonly search: Search;

/**
* Payments Gateway Module
*/
readonly paymentsGateway: PaymentsGateway;

/**
* @param {string} store
* @param {string} appKey
Expand Down Expand Up @@ -81,5 +96,9 @@ export class VTEX {
this.pricing = new Pricing(vtexHttpClient);
this.masterData = new MasterData(vtexHttpClient);
this.catalog = new Catalog(vtexHttpClient);
this.search = new Search(vtexHttpClient);
this.paymentsGateway = new PaymentsGateway(
new VtexPaymentsHttpClient(vtexCredentials)
);
}
}
34 changes: 34 additions & 0 deletions src/modules/payments-gateway/PaymentsGateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { VtexHttpClient } from "../../utils/VtexHttpClient";
import { Installments } from "./apis/installments";
import { Configuration } from "./apis/configuration";
import { TransactionProcess } from "./apis/transaction-process";
import { TransactionFlow } from "./apis/transaction-flow";

export class PaymentsGateway {
/**
* Installments API
*/
readonly installments: Installments;

/**
* Configuration API
*/
readonly configuration: Configuration;

/**
* Transaction Process API
*/
readonly transactionProcess: TransactionProcess;

/**
* Transaction Flow API
*/
readonly transactionFlow: TransactionFlow;

constructor(vtexHttpClient: VtexHttpClient) {
this.installments = new Installments(vtexHttpClient);
this.configuration = new Configuration(vtexHttpClient);
this.transactionProcess = new TransactionProcess(vtexHttpClient);
this.transactionFlow = new TransactionFlow(vtexHttpClient);
}
}
12 changes: 12 additions & 0 deletions src/modules/payments-gateway/VtexPaymentsHttpClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { VtexHttpClient } from "../../utils/VtexHttpClient";
import { VtexCredentials } from "../../VtexCredentials";

export class VtexPaymentsHttpClient extends VtexHttpClient {
/**
* @param {VtexCredentials} vtexCredentials
*/
constructor(vtexCredentials: VtexCredentials) {
super(vtexCredentials);
this.defaultRequestOptions.hostname = `${vtexCredentials.store}.vtexpayments.com.br`;
}
}
126 changes: 126 additions & 0 deletions src/modules/payments-gateway/apis/configuration/Configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { InsertAffiliationRequest } from "./requests/InsertAffiliationRequest";
import { UpdateAffiliationRequest } from "./requests/UpdateAffiliationRequest";
import { InsertRuleRequest } from "./requests/InsertRuleRequest";
import { UpdateRuleRequest } from "./requests/UpdateRuleRequest";
import { AvailablePaymentMethodsResponseItem } from "./responses/AvailablePaymentMethodsResponseItem";

export class Configuration extends AbstractApi {
private static readonly BASE_PATH: string = "/api/pvt";

/**
* Returns all affiliations that your provider can handle.
*/
affiliations(): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/affiliations`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Creates a new affiliation and returns a successful response.
* @param {InsertAffiliationRequest} affiliationData
*/
insertAffiliation(
affiliationData: InsertAffiliationRequest
): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/affiliations`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
affiliationData
);
}

/**
* Updates an existing affiliation.
* @param {string} affiliationId
* @param {InsertAffiliationRequest} affiliationData
*/
updateAffiliation(
affiliationId: string,
affiliationData: UpdateAffiliationRequest
): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/affiliations/${affiliationId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
affiliationData
);
}

/**
* Returns associated data for the specified affiliation Id, like name and implementation, for example.
* @param {string} affiliationId
*/
affiliationById(affiliationId: string): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/affiliations/${affiliationId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Returns all rules conditions your provider can handle.
*/
rules(): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/rules`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Creates a new rule and returns a successful response.
* @param {InsertRuleRequest} ruleData
*/
insertRule(ruleData: InsertRuleRequest): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/rules`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
ruleData
);
}

/**
* Returns rule by specified RuleId.
* @param {string} ruleId
*/
ruleById(ruleId: string): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/rules/${ruleId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Updates an existing rule.
* @param {UpdateRuleRequest} ruleData
*/
updateRule(
ruleId: string,
ruleData: UpdateRuleRequest
): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/rules/${ruleId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
ruleData
);
}

/**
* Deletes rules by specified Id.
* @param {string} ruleId
*/
deleteRule(ruleId: string): Promise<VtexHttpResponse> {
const path = `${Configuration.BASE_PATH}/rules/${ruleId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}

/**
* Returns enabled payment methods, like visa, master, bankissueinvoice that are
* shown for the final user and enabled to receive payment.
*/
availablePaymentMethods(): Promise<
VtexHttpResponse<AvailablePaymentMethodsResponseItem>
> {
const path = `${Configuration.BASE_PATH}/merchants/payment-systems`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}
}
1 change: 1 addition & 0 deletions src/modules/payments-gateway/apis/configuration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Configuration";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface ConfigurationItem {
name?: string;
value?: string;
}

export interface InsertAffiliationRequest {
implementation?: string;
name?: string;
configuration?: Array<ConfigurationItem>;
isdelivered?: boolean;
isConfigured?: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interface SalesChannel {
id?: string;
}

interface PaymentSystem {
id?: number;
name?: string;
implementation?: string;
}

interface Connector {
implementation?: string;
affiliationId?: string;
}

interface Issuer {
name?: string;
}

interface Antifraud {
implementation?: string;
affiliationId?: string;
}

export interface InsertRuleRequest {
name?: string;
salesChannels?: Array<SalesChannel>;
paymentSystem?: PaymentSystem;
connector?: Connector;
issuer?: Issuer;
antifraud?: Antifraud;
installmentOptions?: string;
isSelfAuthorized?: string;
requiresAuthentication?: string;
enabled?: boolean;
installmentsService?: string;
isDefault?: boolean;
beginDate?: string;
endDate?: string;
condition?: string;
multiMerchantList?: string;
country?: string;
dateIntervals?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { InsertAffiliationRequest } from "./InsertAffiliationRequest";

export interface UpdateAffiliationRequest extends InsertAffiliationRequest {
id?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { InsertRuleRequest } from "./InsertRuleRequest";

export interface UpdateRuleRequest extends InsertRuleRequest {
id?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
interface Validator {
regex?: string;
mask?: string;
cardCodeMask?: string;
cardCodeRegex?: string;
weights?: Array<number>;
useCvv?: boolean;
useExpirationDate?: boolean;
useCardHolderName?: boolean;
useBillingAddress?: boolean;
validCardLengths?: string;
}

interface Rule {
id?: string;
connectorImplementation?: string;
antifraudImplementation?: string;
}

export interface AvailablePaymentMethodsResponseItem {
id?: number;
name?: string;
connectorId?: number;
requiresDocument?: boolean;
requiresPhone?: boolean;
implementation?: string;
connectorImplementation?: string;
antifraudConnectorImplementation?: string;
groupName?: string;
isCustom?: boolean;
isSelfAuthorized?: boolean;
allowInstallments?: boolean;
allowMultiple?: boolean;
allowIssuer?: boolean;
allowCountry?: boolean;
allowCommercialPolicy?: boolean;
allowCommercialCondition?: boolean;
allowPeriod?: boolean;
isAvailable?: boolean;
description?: string;
validator?: Validator;
rules?: Array<Rule>;
fields?: string;
dueDate?: string;
allowNotification?: boolean;
affiliationId?: string;
}
Loading

0 comments on commit b98d7a5

Please sign in to comment.