-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from onready/develop
Develop
- Loading branch information
Showing
44 changed files
with
1,014 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
src/modules/payments-gateway/apis/configuration/Configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./Configuration"; |
12 changes: 12 additions & 0 deletions
12
src/modules/payments-gateway/apis/configuration/requests/InsertAffiliationRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/modules/payments-gateway/apis/configuration/requests/InsertRuleRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/modules/payments-gateway/apis/configuration/requests/UpdateAffiliationRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/modules/payments-gateway/apis/configuration/requests/UpdateRuleRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
47 changes: 47 additions & 0 deletions
47
...ules/payments-gateway/apis/configuration/responses/AvailablePaymentMethodsResponseItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.