Skip to content

Commit

Permalink
sch-1925 (#87)
Browse files Browse the repository at this point in the history
* invoices update

* openapi

* use api for invoices
  • Loading branch information
tenub authored Oct 7, 2024
1 parent 1ce58cb commit 6dd9c4d
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 26 deletions.
4 changes: 4 additions & 0 deletions components/src/api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ models/FlagResponseData.ts
models/GetSetupIntentResponse.ts
models/HydrateComponentResponse.ts
models/InvoiceResponseData.ts
models/ListInvoicesParams.ts
models/ListInvoicesResponse.ts
models/PaymentMethodResponseData.ts
models/PlanDetailResponseData.ts
models/PlanEntitlementResponseData.ts
Expand All @@ -52,5 +54,7 @@ models/RuleDetailResponseData.ts
models/RuleResponseData.ts
models/SetupIntentResponseData.ts
models/StripeEmbedInfo.ts
models/UpdatePaymentMethodRequestBody.ts
models/UpdatePaymentMethodResponse.ts
models/index.ts
runtime.ts
130 changes: 130 additions & 0 deletions components/src/api/apis/CheckoutApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import type {
CheckoutResponse,
GetSetupIntentResponse,
HydrateComponentResponse,
ListInvoicesResponse,
PreviewCheckoutResponse,
UpdatePaymentMethodRequestBody,
UpdatePaymentMethodResponse,
} from "../models/index";
import {
ApiErrorFromJSON,
Expand All @@ -32,8 +35,14 @@ import {
GetSetupIntentResponseToJSON,
HydrateComponentResponseFromJSON,
HydrateComponentResponseToJSON,
ListInvoicesResponseFromJSON,
ListInvoicesResponseToJSON,
PreviewCheckoutResponseFromJSON,
PreviewCheckoutResponseToJSON,
UpdatePaymentMethodRequestBodyFromJSON,
UpdatePaymentMethodRequestBodyToJSON,
UpdatePaymentMethodResponseFromJSON,
UpdatePaymentMethodResponseToJSON,
} from "../models/index";

export interface CheckoutRequest {
Expand All @@ -48,10 +57,19 @@ export interface HydrateComponentRequest {
componentId: string;
}

export interface ListInvoicesRequest {
limit?: number;
offset?: number;
}

export interface PreviewCheckoutRequest {
changeSubscriptionRequestBody: ChangeSubscriptionRequestBody;
}

export interface UpdatePaymentMethodRequest {
updatePaymentMethodRequestBody: UpdatePaymentMethodRequestBody;
}

/**
*
*/
Expand Down Expand Up @@ -223,6 +241,60 @@ export class CheckoutApi extends runtime.BaseAPI {
return await response.value();
}

/**
* List invoices
*/
async listInvoicesRaw(
requestParameters: ListInvoicesRequest,
initOverrides?: RequestInit | runtime.InitOverrideFunction,
): Promise<runtime.ApiResponse<ListInvoicesResponse>> {
const queryParameters: any = {};

if (requestParameters["limit"] != null) {
queryParameters["limit"] = requestParameters["limit"];
}

if (requestParameters["offset"] != null) {
queryParameters["offset"] = requestParameters["offset"];
}

const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && this.configuration.apiKey) {
headerParameters["X-Schematic-Api-Key"] = await this.configuration.apiKey(
"X-Schematic-Api-Key",
); // ApiKeyAuth authentication
}

const response = await this.request(
{
path: `/components/invoices`,
method: "GET",
headers: headerParameters,
query: queryParameters,
},
initOverrides,
);

return new runtime.JSONApiResponse(response, (jsonValue) =>
ListInvoicesResponseFromJSON(jsonValue),
);
}

/**
* List invoices
*/
async listInvoices(
requestParameters: ListInvoicesRequest = {},
initOverrides?: RequestInit | runtime.InitOverrideFunction,
): Promise<ListInvoicesResponse> {
const response = await this.listInvoicesRaw(
requestParameters,
initOverrides,
);
return await response.value();
}

/**
* Preview checkout
*/
Expand Down Expand Up @@ -280,4 +352,62 @@ export class CheckoutApi extends runtime.BaseAPI {
);
return await response.value();
}

/**
* Update payment method
*/
async updatePaymentMethodRaw(
requestParameters: UpdatePaymentMethodRequest,
initOverrides?: RequestInit | runtime.InitOverrideFunction,
): Promise<runtime.ApiResponse<UpdatePaymentMethodResponse>> {
if (requestParameters["updatePaymentMethodRequestBody"] == null) {
throw new runtime.RequiredError(
"updatePaymentMethodRequestBody",
'Required parameter "updatePaymentMethodRequestBody" was null or undefined when calling updatePaymentMethod().',
);
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters["Content-Type"] = "application/json";

if (this.configuration && this.configuration.apiKey) {
headerParameters["X-Schematic-Api-Key"] = await this.configuration.apiKey(
"X-Schematic-Api-Key",
); // ApiKeyAuth authentication
}

const response = await this.request(
{
path: `/checkout/paymentmethod/update`,
method: "POST",
headers: headerParameters,
query: queryParameters,
body: UpdatePaymentMethodRequestBodyToJSON(
requestParameters["updatePaymentMethodRequestBody"],
),
},
initOverrides,
);

return new runtime.JSONApiResponse(response, (jsonValue) =>
UpdatePaymentMethodResponseFromJSON(jsonValue),
);
}

/**
* Update payment method
*/
async updatePaymentMethod(
requestParameters: UpdatePaymentMethodRequest,
initOverrides?: RequestInit | runtime.InitOverrideFunction,
): Promise<UpdatePaymentMethodResponse> {
const response = await this.updatePaymentMethodRaw(
requestParameters,
initOverrides,
);
return await response.value();
}
}
72 changes: 72 additions & 0 deletions components/src/api/models/ListInvoicesParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* tslint:disable */
/* eslint-disable */
/**
* Schematic API
* Schematic API
*
* The version of the OpenAPI document: 0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { mapValues } from "../runtime";
/**
* Input parameters
* @export
* @interface ListInvoicesParams
*/
export interface ListInvoicesParams {
/**
* Page limit (default 100)
* @type {number}
* @memberof ListInvoicesParams
*/
limit?: number;
/**
* Page offset (default 0)
* @type {number}
* @memberof ListInvoicesParams
*/
offset?: number;
}

/**
* Check if a given object implements the ListInvoicesParams interface.
*/
export function instanceOfListInvoicesParams(
value: object,
): value is ListInvoicesParams {
return true;
}

export function ListInvoicesParamsFromJSON(json: any): ListInvoicesParams {
return ListInvoicesParamsFromJSONTyped(json, false);
}

export function ListInvoicesParamsFromJSONTyped(
json: any,
ignoreDiscriminator: boolean,
): ListInvoicesParams {
if (json == null) {
return json;
}
return {
limit: json["limit"] == null ? undefined : json["limit"],
offset: json["offset"] == null ? undefined : json["offset"],
};
}

export function ListInvoicesParamsToJSON(
value?: ListInvoicesParams | null,
): any {
if (value == null) {
return value;
}
return {
limit: value["limit"],
offset: value["offset"],
};
}
87 changes: 87 additions & 0 deletions components/src/api/models/ListInvoicesResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* tslint:disable */
/* eslint-disable */
/**
* Schematic API
* Schematic API
*
* The version of the OpenAPI document: 0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { mapValues } from "../runtime";
import type { ListInvoicesParams } from "./ListInvoicesParams";
import {
ListInvoicesParamsFromJSON,
ListInvoicesParamsFromJSONTyped,
ListInvoicesParamsToJSON,
} from "./ListInvoicesParams";
import type { InvoiceResponseData } from "./InvoiceResponseData";
import {
InvoiceResponseDataFromJSON,
InvoiceResponseDataFromJSONTyped,
InvoiceResponseDataToJSON,
} from "./InvoiceResponseData";

/**
*
* @export
* @interface ListInvoicesResponse
*/
export interface ListInvoicesResponse {
/**
* The returned resources
* @type {Array<InvoiceResponseData>}
* @memberof ListInvoicesResponse
*/
data: Array<InvoiceResponseData>;
/**
*
* @type {ListInvoicesParams}
* @memberof ListInvoicesResponse
*/
params: ListInvoicesParams;
}

/**
* Check if a given object implements the ListInvoicesResponse interface.
*/
export function instanceOfListInvoicesResponse(
value: object,
): value is ListInvoicesResponse {
if (!("data" in value) || value["data"] === undefined) return false;
if (!("params" in value) || value["params"] === undefined) return false;
return true;
}

export function ListInvoicesResponseFromJSON(json: any): ListInvoicesResponse {
return ListInvoicesResponseFromJSONTyped(json, false);
}

export function ListInvoicesResponseFromJSONTyped(
json: any,
ignoreDiscriminator: boolean,
): ListInvoicesResponse {
if (json == null) {
return json;
}
return {
data: (json["data"] as Array<any>).map(InvoiceResponseDataFromJSON),
params: ListInvoicesParamsFromJSON(json["params"]),
};
}

export function ListInvoicesResponseToJSON(
value?: ListInvoicesResponse | null,
): any {
if (value == null) {
return value;
}
return {
data: (value["data"] as Array<any>).map(InvoiceResponseDataToJSON),
params: ListInvoicesParamsToJSON(value["params"]),
};
}
2 changes: 1 addition & 1 deletion components/src/api/models/PaymentMethodResponseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { mapValues } from "../runtime";
/**
*
* The created resource
* @export
* @interface PaymentMethodResponseData
*/
Expand Down
9 changes: 9 additions & 0 deletions components/src/api/models/PlanDetailResponseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export interface PlanDetailResponseData {
* @memberof PlanDetailResponseData
*/
id: string;
/**
*
* @type {boolean}
* @memberof PlanDetailResponseData
*/
isDefault: boolean;
/**
*
* @type {BillingPriceResponseData}
Expand Down Expand Up @@ -132,6 +138,7 @@ export function instanceOfPlanDetailResponseData(
if (!("features" in value) || value["features"] === undefined) return false;
if (!("icon" in value) || value["icon"] === undefined) return false;
if (!("id" in value) || value["id"] === undefined) return false;
if (!("isDefault" in value) || value["isDefault"] === undefined) return false;
if (!("name" in value) || value["name"] === undefined) return false;
if (!("planType" in value) || value["planType"] === undefined) return false;
if (!("updatedAt" in value) || value["updatedAt"] === undefined) return false;
Expand Down Expand Up @@ -166,6 +173,7 @@ export function PlanDetailResponseDataFromJSONTyped(
),
icon: json["icon"],
id: json["id"],
isDefault: json["is_default"],
monthlyPrice:
json["monthly_price"] == null
? undefined
Expand Down Expand Up @@ -199,6 +207,7 @@ export function PlanDetailResponseDataToJSON(
),
icon: value["icon"],
id: value["id"],
is_default: value["isDefault"],
monthly_price: BillingPriceResponseDataToJSON(value["monthlyPrice"]),
name: value["name"],
plan_type: value["planType"],
Expand Down
Loading

0 comments on commit 6dd9c4d

Please sign in to comment.