Skip to content

Commit

Permalink
Merge pull request #30 from onready/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Juan Cernadas authored Jul 6, 2020
2 parents 3009fa1 + 8dff5cc commit 04423fd
Show file tree
Hide file tree
Showing 53 changed files with 988 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ Suggestions | :white_check_mark: |
VTEX DO | :white_check_mark: |
CMS | :white_check_mark: |
Session Manager | :white_check_mark: |
License Manager | :white_check_mark: |
Customer Credit | :white_check_mark: |
Antifraud Provider | :x: |
Checkout | :x: |
Customer Credit | :x: |
Giftcard | :x: |
Giftcard Hub | :x: |
Giftcard Provider Protocol | :x: |
License Manager | :x: |
Payment Provider Protocol | :x: |
Rates and Benefits | :x: |
Subscriptions (V2) | :x: |
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onreadydesa/vtex-node-sdk",
"version": "1.10.0-beta",
"version": "1.12.0-beta",
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
"author": "Onready",
"private": false,
Expand Down Expand Up @@ -43,14 +43,14 @@
"@babel/preset-typescript": "7.10.4",
"@types/jest": "26.0.3",
"@types/node": "14.0.14",
"@typescript-eslint/eslint-plugin": "3.5.0",
"@typescript-eslint/parser": "3.5.0",
"@typescript-eslint/eslint-plugin": "3.6.0",
"@typescript-eslint/parser": "3.6.0",
"babel-jest": "26.1.0",
"eslint": "7.4.0",
"eslint-config-airbnb-base": "14.2.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "23.17.1",
"eslint-plugin-jest": "23.18.0",
"eslint-plugin-prettier": "3.1.4",
"jest": "26.1.0",
"nock": "13.0.2",
Expand Down
14 changes: 14 additions & 0 deletions src/VTEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { VtexDo } from "./modules/vtex-do";
import { Suggestions } from "./modules/suggestions";
import { CMS } from "./modules/CMS";
import { SessionManager } from "./modules/session-manager";
import { LicenseManager } from "./modules/license-manager";
import { CustomerCredit } from "./modules/customer-credit";

export class VTEX {
private static buildErrorMessage(paramName: string): string {
Expand Down Expand Up @@ -93,6 +95,16 @@ export class VTEX {
*/
readonly sessionManager: SessionManager;

/**
* License Manager Module
*/
readonly licenseManager: LicenseManager;

/**
* Customer Credit Module
*/
readonly customerCredit: CustomerCredit;

/**
* @param {string} store
* @param {string} appKey
Expand Down Expand Up @@ -128,5 +140,7 @@ export class VTEX {
this.suggestions = new Suggestions(vtexHttpClient);
this.cms = new CMS(vtexHttpClient);
this.sessionManager = new SessionManager(vtexHttpClient);
this.licenseManager = new LicenseManager(vtexHttpClient);
this.customerCredit = new CustomerCredit(vtexHttpClient);
}
}
27 changes: 27 additions & 0 deletions src/modules/customer-credit/CustomerCredit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { VtexHttpClient } from "../../utils/VtexHttpClient";
import { Invoices } from "./apis/invoices";
import { Account } from "./apis/account";
import { StoreConfiguration } from "./apis/store-configuration";

export class CustomerCredit {
/**
* Invoices API
*/
readonly invoices: Invoices;

/**
* Account API
*/
readonly account: Account;

/**
* Store Configuration API
*/
readonly storeConfiguration: StoreConfiguration;

constructor(vtexHttpClient: VtexHttpClient) {
this.invoices = new Invoices(vtexHttpClient);
this.account = new Account(vtexHttpClient);
this.storeConfiguration = new StoreConfiguration(vtexHttpClient);
}
}
282 changes: 282 additions & 0 deletions src/modules/customer-credit/apis/account/Account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
import { AbstractApi } from "../../../AbstractApi";
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse";
import { SearchAllAccountsResponse } from "./responses/SearchAllAccountsResponse";
import { OpenAnAccountRequest } from "./requests/OpenAnAccountRequest";
import { RetrieveAnAccountByIdResponse } from "./responses/RetrieveAnAccountByIdResponse";
import { UpdateEmailAndDescriptionOfAnAccountRequest } from "./requests/UpdateEmailAndDescriptionOfAnAccountRequest";
import { AccountStatementsResponse } from "./responses/AccountStatementsResponse";
import { OpenOrChangeAccountRequest } from "./requests/OpenOrChangeAccountRequest";
import { OpenOrChangeAccountResponse } from "./responses/OpenOrChangeAccountResponse";
import { ChangeCreditLimitOfAnAccountRequest } from "./requests/ChangeCreditLimitOfAnAccountRequest";
import { DecreaseBalanceOfAnAccountRequest } from "./requests/DecreaseBalanceOfAnAccountRequest";
import { CreatePreAuthorizationRequest } from "./requests/CreatePreAuthorizationRequest";
import { AddAccountHolderRequest } from "./requests/AddAccountHolderRequest";
import { PartialOrTotalRefundSettlementResponse } from "./responses/PartialOrTotalRefundSettlementResponse";

export class Account extends AbstractApi {
private static readonly BASE_PATH: string = "/api/creditcontrol/accounts";

/**
*
* @param {string} params Example: document=09173503401&[email protected]&op=or
*/
searchAllAccounts(
params?: string
): Promise<VtexHttpResponse<SearchAllAccountsResponse>> {
const path = `${Account.BASE_PATH}?${params || ""}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Open an account.
* @param {OpenAnAccountRequest} data
*/
openAnAccount(data: OpenAnAccountRequest): Promise<VtexHttpResponse> {
return this.vtexHttpClient.performRequest(
Account.BASE_PATH,
this.HTTP_METHODS.POST,
data
);
}

/**
* Retrieve an account by id.
* @param {string} creditAccountId
*/
retrieveAnAccountById(
creditAccountId: string
): Promise<VtexHttpResponse<RetrieveAnAccountByIdResponse>> {
const path = `${Account.BASE_PATH}/${creditAccountId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Closes an account.
* @param {string} creditAccountId
*/
closeAnAccount(creditAccountId: string): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}

/**
* Update a checking account.
* @param {string} creditAccountId
* @param {UpdateEmailAndDescriptionOfAnAccountRequest} data
*/
updateEmailAndDescriptionOfAnAccount(
creditAccountId: string,
data: UpdateEmailAndDescriptionOfAnAccountRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Get the account statements.
* @param {string} creditAccountId
*/
accountStatements(
creditAccountId: string
): Promise<VtexHttpResponse<AccountStatementsResponse>> {
const path = `${Account.BASE_PATH}/${creditAccountId}/statements`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
*
* @param {string} accountId
* @param {OpenOrChangeAccountRequest} data
*/
openOrChangeAccount(
accountId: string,
data: OpenOrChangeAccountRequest
): Promise<VtexHttpResponse<OpenOrChangeAccountResponse>> {
const path = `${Account.BASE_PATH}/${accountId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Increase the credit limit of an account.
* @param {string} creditAccountId
* @param {ChangeCreditLimitOfAnAccountRequest} data
*/
changeCreditLimitOfAnAccount(
creditAccountId: string,
data: ChangeCreditLimitOfAnAccountRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/creditlimit`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Create a debit value updating the account BALANCE.
* @param {string} creditAccountId
* @param {string} statementId
* @param {DecreaseBalanceOfAnAccountRequest} data
*/
decreaseBalanceOfAnAccount(
creditAccountId: string,
statementId: string,
data: DecreaseBalanceOfAnAccountRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/statements/${statementId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Debit a value from checking account.
* @param {string} creditAccountId
* @param {string} transactionId
* @param {DecreaseBalanceOfAnAccountRequest} data
*/
createOrUpdateSettlement(
creditAccountId: string,
transactionId: string,
data: DecreaseBalanceOfAnAccountRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/transactions/${transactionId}/settlement`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Authorization hold (also card authorization, preauthorization, or preauth) is the practice that holding
* this balance as unavailable until either the merchant clears the transaction, also called settlement,
* or the hold "falls off." This operation does not appear in statements but the available balance
* will be updated. The result of this operation is generate a preauthorizationId to use in settlement.
* @param {string} creditAccountId
* @param {CreatePreAuthorizationRequest} data
*/
createPreAuthorization(
creditAccountId: string,
data: CreatePreAuthorizationRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/transaction`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
data
);
}

/**
* Authorization hold (also card authorization, preauthorization, or preauth) is the practice that holding
* this balance as unavailable until either the merchant clears the transaction, also called settlement,
* or the hold "falls off." This operation does not appear in statements but the available balance
* will be updated.The result of this operation is generate a preauthorizationId to use in settlement.
* @param {string} creditAccountId
* @param {string} transactionId
* @param {CreatePreAuthorizationRequest} data
*/
createPreAuthorizationUsingId(
creditAccountId: string,
transactionId: string,
data: CreatePreAuthorizationRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/transactions/${transactionId}`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
*
* @param {string} creditAccountId
* @param {string} transactionId
*/
cancelPreAuthorization(
creditAccountId: string,
transactionId: string
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/transactions/${transactionId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}

/**
*
* @param {string} creditAccountId
* @param {AddAccountHolderRequest} data
*/
addAccountHolder(
creditAccountId: string,
data: AddAccountHolderRequest
): Promise<VtexHttpResponse<SearchAllAccountsResponse>> {
const path = `${Account.BASE_PATH}/${creditAccountId}/holders`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
data
);
}

/**
*
* @param {string} creditAccountId
* @param {string} holderId
*/
deleteAccountHolder(
creditAccountId: string,
holderId: string
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/holders/${holderId}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}

/**
* Increase the credit limit of a checking account.
* @param {string} creditAccountId
* @param {ChangeCreditLimitOfAnAccountRequest} data
*/
changeToleranceOfAnAccount(
creditAccountId: string,
data: ChangeCreditLimitOfAnAccountRequest
): Promise<VtexHttpResponse> {
const path = `${Account.BASE_PATH}/${creditAccountId}/tolerance`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.PUT,
data
);
}

/**
* Refund a value from a already settled transaction.
* @param {string} creditAccountId
* @param {string} transactionId
* @param {DecreaseBalanceOfAnAccountRequest} data
*/
partialOrTotalRefundSettlement(
creditAccountId: string,
transactionId: string,
data: DecreaseBalanceOfAnAccountRequest
): Promise<VtexHttpResponse<PartialOrTotalRefundSettlementResponse>> {
const path = `${Account.BASE_PATH}/${creditAccountId}/transactions/${transactionId}/refunds`;
return this.vtexHttpClient.performRequest(
path,
this.HTTP_METHODS.POST,
data
);
}
}
1 change: 1 addition & 0 deletions src/modules/customer-credit/apis/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Account";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface Claims {
email?: string;
}

export interface AddAccountHolderRequest {
claims?: Claims;
}
Loading

0 comments on commit 04423fd

Please sign in to comment.