-
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 #34 from onready/develop
Develop
- Loading branch information
Showing
47 changed files
with
1,392 additions
and
63 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 { OrderForm } from "./apis/order-form"; | ||
import { CartUpdate } from "./apis/cart-update"; | ||
import { CustomData } from "./apis/custom-data"; | ||
import { Configuration } from "./apis/configuration"; | ||
|
||
export class Checkout { | ||
/** | ||
* Order Form API | ||
*/ | ||
readonly orderForm: OrderForm; | ||
|
||
/** | ||
* Cart Update API | ||
*/ | ||
readonly cartUpdate: CartUpdate; | ||
|
||
/** | ||
* Custom Data API | ||
*/ | ||
readonly customData: CustomData; | ||
|
||
/** | ||
* Configuration API | ||
*/ | ||
readonly configuration: Configuration; | ||
|
||
constructor(vtexHttpClient: VtexHttpClient) { | ||
this.orderForm = new OrderForm(vtexHttpClient); | ||
this.cartUpdate = new CartUpdate(vtexHttpClient); | ||
this.customData = new CustomData(vtexHttpClient); | ||
this.configuration = new Configuration(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,52 @@ | ||
import { AbstractApi } from "../../../AbstractApi"; | ||
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; | ||
import { UpdateCartItemsRequest } from "./requests/UpdateCartItemsRequest"; | ||
import { ChangePriceRequest } from "./requests/ChangePriceRequest"; | ||
|
||
export class CartUpdate extends AbstractApi { | ||
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm"; | ||
|
||
/** | ||
* With the Items Update request you can: | ||
* 1) Add items to the cart | ||
* 2) Change the quantity of one or more items in a specific cart | ||
* 3) Remove items from the cart (by changing their quantity to 0). | ||
* @param {string} orderFormId | ||
* @param {UpdateCartItemsRequest} data | ||
*/ | ||
updateCartItems( | ||
orderFormId: string, | ||
data: UpdateCartItemsRequest | ||
): Promise<VtexHttpResponse> { | ||
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items`; | ||
return this.vtexHttpClient.performRequest( | ||
path, | ||
this.HTTP_METHODS.PATCH, | ||
data | ||
); | ||
} | ||
|
||
/** | ||
* This request changes the price of a specific item in a cart. You need to inform which cart you are | ||
* referring to, by sending its orderFormID; and what is the item whose price you want to change, by | ||
* sending its itemIndex. You also need to pass the new price value in the body. Remember that, to | ||
* use this endpoint, the feature of manual price must be active. To check if it's active, use the | ||
* Get orderForm configuration endpoint. To make it active, use the Update orderForm configuration | ||
* endpoint, making the allowManualPrice field true. | ||
* @param {string} orderFormId | ||
* @param {number} itemIndex | ||
* @param {ChangePriceRequest} data | ||
*/ | ||
changePrice( | ||
orderFormId: string, | ||
itemIndex: number, | ||
data: ChangePriceRequest | ||
): Promise<VtexHttpResponse> { | ||
const path = `${CartUpdate.BASE_PATH}/${orderFormId}/items/${itemIndex}/price`; | ||
return this.vtexHttpClient.performRequest( | ||
path, | ||
this.HTTP_METHODS.PUT, | ||
data | ||
); | ||
} | ||
} |
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 "./CartUpdate"; |
3 changes: 3 additions & 0 deletions
3
src/modules/checkout/apis/cart-update/requests/ChangePriceRequest.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,3 @@ | ||
export interface ChangePriceRequest { | ||
price?: number; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/modules/checkout/apis/cart-update/requests/UpdateCartItemsRequest.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,10 @@ | ||
interface OrderItem { | ||
quantity?: number; | ||
index?: number; | ||
seller?: string; | ||
id?: string; | ||
} | ||
|
||
export interface UpdateCartItemsRequest { | ||
orderItems?: Array<OrderItem>; | ||
} |
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,39 @@ | ||
import { AbstractApi } from "../../../AbstractApi"; | ||
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; | ||
import { UpdateOrderFormConfigurationRequest } from "./requests/UpdateOrderFormConfigurationRequest"; | ||
|
||
export class Configuration extends AbstractApi { | ||
private static readonly BASE_PATH: string = | ||
"/api/checkout/pvt/configuration/orderForm"; | ||
|
||
/** | ||
* Retrieves the settings that are currently applied to every orderForm in the account. | ||
* These settings are defined by the request Update orderForm configuration. | ||
* Always use this request to retrieve the current configuration before performing an update. | ||
* By doing so you ensure that you are modifying only the properties you want. | ||
*/ | ||
getOrderFormConfiguration(): Promise<VtexHttpResponse> { | ||
return this.vtexHttpClient.performRequest( | ||
Configuration.BASE_PATH, | ||
this.HTTP_METHODS.GET | ||
); | ||
} | ||
|
||
/** | ||
* Determines settings that will apply to every orderForm in the account. For example, if you create an app | ||
* using this request, every orderForm of this account will have the custom fields created though it. | ||
* Important: always retrieve the current configuration before performing an update to ensure that you are | ||
* modifying only the properties you want. Otherwise, old values can be overwritten. To retrieve the current | ||
* configuration, use the request Get orderForm configuration. | ||
* @param {UpdateOrderFormConfigurationRequest} data | ||
*/ | ||
updateOrderFormConfiguration( | ||
data: UpdateOrderFormConfigurationRequest | ||
): Promise<VtexHttpResponse> { | ||
return this.vtexHttpClient.performRequest( | ||
Configuration.BASE_PATH, | ||
this.HTTP_METHODS.POST, | ||
data | ||
); | ||
} | ||
} |
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"; |
31 changes: 31 additions & 0 deletions
31
src/modules/checkout/apis/configuration/requests/UpdateOrderFormConfigurationRequest.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,31 @@ | ||
interface PaymentConfiguration { | ||
requiresAuthenticationForPreAuthorizedPaymentOption?: boolean; | ||
allowInstallmentsMerge?: boolean; | ||
} | ||
|
||
interface TaxConfiguration { | ||
url?: string; | ||
authorizationHeader?: string; | ||
allowExecutionAfterErrors?: boolean; | ||
integratedAuthentication?: boolean; | ||
appId?: string; | ||
} | ||
|
||
interface Apps { | ||
id?: string; | ||
fields?: Array<string>; | ||
major?: number; | ||
} | ||
|
||
export interface UpdateOrderFormConfigurationRequest { | ||
paymentConfiguration?: PaymentConfiguration; | ||
taxConfiguration?: TaxConfiguration; | ||
minimumQuantityAccumulatedForItems?: number; | ||
decimalDigitsPrecision?: number; | ||
minimumValueAccumulated?: number; | ||
apps?: Apps; | ||
allowMultipleDeliveries?: boolean; | ||
allowManualPrice?: boolean; | ||
maxNumberOfWhiteLabelSellers?: number; | ||
maskFirstPurchaseData?: boolean; | ||
} |
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,73 @@ | ||
import { AbstractApi } from "../../../AbstractApi"; | ||
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; | ||
import { SetSingleCustomFieldValueRequest } from "./requests/SetSingleCustomFieldValueRequest"; | ||
|
||
export class CustomData extends AbstractApi { | ||
private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm"; | ||
|
||
/** | ||
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request. | ||
* The values of these custom fields can then be updated by this request.To do that, you need to inform the ID | ||
* of the app you created with the configuration API (appId). In the body of the request, for each field created | ||
* in this app (appFieldName) you will inform a value (appFieldValue). | ||
* @param {string} orderFormId | ||
* @param {string} appId | ||
* @param {object} data | ||
*/ | ||
setMultipleCustomFieldValues( | ||
orderFormId: string, | ||
appId: string, | ||
data: object | ||
): Promise<VtexHttpResponse> { | ||
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}`; | ||
return this.vtexHttpClient.performRequest( | ||
path, | ||
this.HTTP_METHODS.PUT, | ||
data | ||
); | ||
} | ||
|
||
/** | ||
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request. | ||
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the | ||
* URL the ID of the app you created with the configuration API (appId). | ||
* In the body of the request, you will inform the new value (appFieldValue, passed through the body) of the | ||
* specific field created in this app (identified by the appFieldName parameter, passed through the URL). | ||
* @param {string} orderFormId | ||
* @param {string} appId | ||
* @param {string} appFieldName | ||
* @param {SetSingleCustomFieldValueRequest} data | ||
*/ | ||
setSingleCustomFieldValue( | ||
orderFormId: string, | ||
appId: string, | ||
appFieldName: string, | ||
data: SetSingleCustomFieldValueRequest | ||
): Promise<VtexHttpResponse> { | ||
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`; | ||
return this.vtexHttpClient.performRequest( | ||
path, | ||
this.HTTP_METHODS.PUT, | ||
data | ||
); | ||
} | ||
|
||
/** | ||
* Your account may create apps, which contain custom fields, through the Update orderForm configuration request. | ||
* The value of a specific custom field can then be updated by this request. To do that, you need to inform in the | ||
* URL the ID of the app you created with the configuration API (appId). | ||
* You also need to iform the specific field created in this app (identified by the appFieldName parameter, also | ||
* passed through the URL) whose value you want to remove. | ||
* @param {string} orderFormId | ||
* @param {string} appId | ||
* @param {string} appFieldName | ||
*/ | ||
deleteSingleCustomFieldValue( | ||
orderFormId: string, | ||
appId: string, | ||
appFieldName: string | ||
): Promise<VtexHttpResponse> { | ||
const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`; | ||
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE); | ||
} | ||
} |
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 "./CustomData"; |
3 changes: 3 additions & 0 deletions
3
src/modules/checkout/apis/custom-data/requests/SetSingleCustomFieldValueRequest.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,3 @@ | ||
export interface SetSingleCustomFieldValueRequest { | ||
value?: any; | ||
} |
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,49 @@ | ||
import { AbstractApi } from "../../../AbstractApi"; | ||
import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; | ||
import { DoOrderFormSimulationRequest } from "./requests/DoOrderFormSimulationRequest"; | ||
|
||
export class OrderForm extends AbstractApi { | ||
private static readonly BASE_PATH: string = "/api/checkout"; | ||
|
||
/** | ||
* The orderForm simulation endpoint is used to simulate a cart in VTEX Checkout. It receives an SKU ID, | ||
* the quantity of items in the cart, the ID of the Seller and the country in ISO ALPHA-3 Code (eg. BRA, USA, ARG). | ||
* It sends back all information about the cart, such as the selling price of each item, rates and benefits data, | ||
* payment and logistics info. This is useful whenever you need to know the avaiability of fulfilling an order | ||
* for a specific cart setting, since the API response will let you know the updated price, inventory and | ||
* shipping data. | ||
* @param {DoOrderFormSimulationRequest} data | ||
*/ | ||
doOrderFormSimulation( | ||
data: DoOrderFormSimulationRequest | ||
): Promise<VtexHttpResponse> { | ||
const path = `${OrderForm.BASE_PATH}/pub/orderforms/simulation`; | ||
return this.vtexHttpClient.performRequest( | ||
path, | ||
this.HTTP_METHODS.POST, | ||
data | ||
); | ||
} | ||
|
||
/** | ||
* This call removes all items from a given cart, leaving it empty. The ID of the specific cart whose | ||
* items you want to remove is passed as an URL paramater, replacing the variable orderFormId in this example. | ||
* The orderFormId is the identification number of a given cart. That is, it's the ID of a specific orderForm. | ||
* @param {string} orderFormId | ||
*/ | ||
removeAllItems(orderFormId: string): Promise<VtexHttpResponse> { | ||
const path = `${OrderForm.BASE_PATH}/pub/orderform/${orderFormId}/items/removeAll`; | ||
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.POST, {}); | ||
} | ||
|
||
/** | ||
* This call removes all user information, leaving the orderForm anonymous. That is, it keeps the items of | ||
* the cart in the orderForm. This call works by creating a new orderForm, setting a new cookie and returning | ||
* a redirect 302 to the cart URL (/checkout/#/orderform). | ||
* @param {string} orderFormId | ||
*/ | ||
removeAllPersonalData(orderFormId: string): Promise<VtexHttpResponse> { | ||
const path = `${OrderForm.BASE_PATH}/changeToAnonymousUser/${orderFormId}`; | ||
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 "./OrderForm"; |
Oops, something went wrong.