Skip to content

Commit

Permalink
META-189: initialize Using simple order response
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfos committed May 16, 2024
1 parent 70f21eb commit f15421a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/initialize/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
setPublicOrderId,
setShopIdentifier,
checkApiResponse,
IInitializeSimpleOrderResponse,
} from 'src';

/**
Expand All @@ -20,12 +21,12 @@ import {
* @param shopIdentifier Identification for the shop in which the order is on
* @param environment Set the environment where the library will be working on.
*/
export async function initialize(initData: IInitializeOrderResponse, shopIdentifier: string, environment: IEnvironment): Promise<IApiReturnObject> {
export async function initialize(initData: IInitializeOrderResponse | IInitializeSimpleOrderResponse, shopIdentifier: string, environment: IEnvironment): Promise<IApiReturnObject> {
const {jwt_token: jwt, public_order_id: publicOrderId} = initData;
const returnObject = {...baseReturnObject};
returnObject.success = true;
returnObject.response = initData;
const keysToCheck = [keysToTestFromResponse.applicationState, keysToTestFromResponse.initial_data, keysToTestFromResponse.jwt_token, keysToTestFromResponse.public_order_id];
const keysToCheck = [keysToTestFromResponse.jwt_token, keysToTestFromResponse.public_order_id];
const returnValue = checkApiResponse(returnObject, keysToCheck);
if(!returnValue.success) {
return returnValue;
Expand Down
9 changes: 8 additions & 1 deletion src/types/apiInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IApiSuccessResponse {
IDeleteDiscountResponse |
IGetPaymentIframeUrl |
IInitializeOrderResponse |
IInitializeSimpleOrderResponse |
ICssStylingPaymentIframeResponse |
ICheckInventoryResponse |
IAddPaymentResponse |
Expand Down Expand Up @@ -120,7 +121,7 @@ export interface IApiReturnObject {
status: number;
success: boolean;
error: null | IFetchError;
response: null | IApiResponse | IApiBatchResponse;
response: null | IApiResponse | IApiBatchResponse | IInitializeSimpleOrderResponse;
}

export interface IFetchCallback extends Function {
Expand All @@ -134,6 +135,12 @@ export interface IInitializeOrderResponse {
public_order_id: string
}

export interface IInitializeSimpleOrderResponse {
flow_settings: Record<string, unknown>;
jwt_token: string;
public_order_id: string;
}

export interface ICssStylingPaymentIframeResponse {
style_sheet: IStyleSheet
}
Expand Down

0 comments on commit f15421a

Please sign in to comment.