|
| 1 | +import { AbstractApi } from "../../../AbstractApi"; |
| 2 | +import { VtexHttpResponse } from "../../../../utils/VtexHttpResponse"; |
| 3 | +import { SetSingleCustomFieldValueRequest } from "./requests/SetSingleCustomFieldValueRequest"; |
| 4 | + |
| 5 | +export class CustomData extends AbstractApi { |
| 6 | + private static readonly BASE_PATH: string = "/api/checkout/pub/orderForm"; |
| 7 | + |
| 8 | + /** |
| 9 | + * Your account may create apps, which contain custom fields, through the Update orderForm configuration request. |
| 10 | + * The values of these custom fields can then be updated by this request.To do that, you need to inform the ID |
| 11 | + * of the app you created with the configuration API (appId). In the body of the request, for each field created |
| 12 | + * in this app (appFieldName) you will inform a value (appFieldValue). |
| 13 | + * @param {string} orderFormId |
| 14 | + * @param {string} appId |
| 15 | + * @param {object} data |
| 16 | + */ |
| 17 | + setMultipleCustomFieldValues( |
| 18 | + orderFormId: string, |
| 19 | + appId: string, |
| 20 | + data: object |
| 21 | + ): Promise<VtexHttpResponse> { |
| 22 | + const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}`; |
| 23 | + return this.vtexHttpClient.performRequest( |
| 24 | + path, |
| 25 | + this.HTTP_METHODS.PUT, |
| 26 | + data |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Your account may create apps, which contain custom fields, through the Update orderForm configuration request. |
| 32 | + * The value of a specific custom field can then be updated by this request. To do that, you need to inform in the |
| 33 | + * URL the ID of the app you created with the configuration API (appId). |
| 34 | + * In the body of the request, you will inform the new value (appFieldValue, passed through the body) of the |
| 35 | + * specific field created in this app (identified by the appFieldName parameter, passed through the URL). |
| 36 | + * @param {string} orderFormId |
| 37 | + * @param {string} appId |
| 38 | + * @param {string} appFieldName |
| 39 | + * @param {SetSingleCustomFieldValueRequest} data |
| 40 | + */ |
| 41 | + setSingleCustomFieldValue( |
| 42 | + orderFormId: string, |
| 43 | + appId: string, |
| 44 | + appFieldName: string, |
| 45 | + data: SetSingleCustomFieldValueRequest |
| 46 | + ): Promise<VtexHttpResponse> { |
| 47 | + const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`; |
| 48 | + return this.vtexHttpClient.performRequest( |
| 49 | + path, |
| 50 | + this.HTTP_METHODS.PUT, |
| 51 | + data |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Your account may create apps, which contain custom fields, through the Update orderForm configuration request. |
| 57 | + * The value of a specific custom field can then be updated by this request. To do that, you need to inform in the |
| 58 | + * URL the ID of the app you created with the configuration API (appId). |
| 59 | + * You also need to iform the specific field created in this app (identified by the appFieldName parameter, also |
| 60 | + * passed through the URL) whose value you want to remove. |
| 61 | + * @param {string} orderFormId |
| 62 | + * @param {string} appId |
| 63 | + * @param {string} appFieldName |
| 64 | + */ |
| 65 | + deleteSingleCustomFieldValue( |
| 66 | + orderFormId: string, |
| 67 | + appId: string, |
| 68 | + appFieldName: string |
| 69 | + ): Promise<VtexHttpResponse> { |
| 70 | + const path = `${CustomData.BASE_PATH}/${orderFormId}/customData/${appId}/${appFieldName}`; |
| 71 | + return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE); |
| 72 | + } |
| 73 | +} |
0 commit comments