Skip to content

Commit

Permalink
Add API to bulk-add SKUs to a basket, optionally with a discount (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkachel authored Jan 14, 2025
1 parent 55a040e commit a0eb3d4
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 1 deletion.
186 changes: 186 additions & 0 deletions frontends/api/src/generated/v0/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,56 @@ export const CountryCodeEnum = {
export type CountryCodeEnum =
(typeof CountryCodeEnum)[keyof typeof CountryCodeEnum]

/**
* Serializer for creating a basket with products. (For OpenAPI spec.)
* @export
* @interface CreateBasketWithProductsRequest
*/
export interface CreateBasketWithProductsRequest {
/**
*
* @type {string}
* @memberof CreateBasketWithProductsRequest
*/
system_slug: string
/**
*
* @type {Array<CreateBasketWithProductsSkuRequest>}
* @memberof CreateBasketWithProductsRequest
*/
skus: Array<CreateBasketWithProductsSkuRequest>
/**
*
* @type {boolean}
* @memberof CreateBasketWithProductsRequest
*/
checkout: boolean
/**
*
* @type {string}
* @memberof CreateBasketWithProductsRequest
*/
discount_code: string
}
/**
* Defines the schema for a SKU in the CreateBasketWithProductsSerializer.
* @export
* @interface CreateBasketWithProductsSkuRequest
*/
export interface CreateBasketWithProductsSkuRequest {
/**
*
* @type {string}
* @memberof CreateBasketWithProductsSkuRequest
*/
sku: string
/**
*
* @type {number}
* @memberof CreateBasketWithProductsSkuRequest
*/
quantity: number
}
/**
* Really basic serializer for the payload that we need to send to CyberSource.
* @export
Expand Down Expand Up @@ -4226,6 +4276,59 @@ export const PaymentsApiAxiosParamCreator = function (
options: localVarRequestOptions,
}
},
/**
* Creates or updates a basket for the current user, adding the selected product.
* @param {CreateBasketWithProductsRequest} CreateBasketWithProductsRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
paymentsBasketsCreateWithProductsCreate: async (
CreateBasketWithProductsRequest: CreateBasketWithProductsRequest,
options: RawAxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'CreateBasketWithProductsRequest' is not null or undefined
assertParamExists(
"paymentsBasketsCreateWithProductsCreate",
"CreateBasketWithProductsRequest",
CreateBasketWithProductsRequest,
)
const localVarPath = `/api/v0/payments/baskets/create_with_products/`
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL)
let baseOptions
if (configuration) {
baseOptions = configuration.baseOptions
}

const localVarRequestOptions = {
method: "POST",
...baseOptions,
...options,
}
const localVarHeaderParameter = {} as any
const localVarQueryParameter = {} as any

localVarHeaderParameter["Content-Type"] = "application/json"

setSearchParams(localVarUrlObj, localVarQueryParameter)
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {}
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
}
localVarRequestOptions.data = serializeDataIfNeeded(
CreateBasketWithProductsRequest,
localVarRequestOptions,
configuration,
)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
}
},
/**
* Returns or creates a basket for the current user and system.
* @param {string} system_slug
Expand Down Expand Up @@ -4666,6 +4769,39 @@ export const PaymentsApiFp = function (configuration?: Configuration) {
configuration,
)(axios, operationBasePath || basePath)
},
/**
* Creates or updates a basket for the current user, adding the selected product.
* @param {CreateBasketWithProductsRequest} CreateBasketWithProductsRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async paymentsBasketsCreateWithProductsCreate(
CreateBasketWithProductsRequest: CreateBasketWithProductsRequest,
options?: RawAxiosRequestConfig,
): Promise<
(
axios?: AxiosInstance,
basePath?: string,
) => AxiosPromise<BasketWithProduct>
> {
const localVarAxiosArgs =
await localVarAxiosParamCreator.paymentsBasketsCreateWithProductsCreate(
CreateBasketWithProductsRequest,
options,
)
const index = configuration?.serverIndex ?? 0
const operationBasePath =
operationServerMap[
"PaymentsApi.paymentsBasketsCreateWithProductsCreate"
]?.[index]?.url
return (axios, basePath) =>
createRequestFunction(
localVarAxiosArgs,
globalAxios,
BASE_PATH,
configuration,
)(axios, operationBasePath || basePath)
},
/**
* Returns or creates a basket for the current user and system.
* @param {string} system_slug
Expand Down Expand Up @@ -4946,6 +5082,23 @@ export const PaymentsApiFactory = function (
)
.then((request) => request(axios, basePath))
},
/**
* Creates or updates a basket for the current user, adding the selected product.
* @param {PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
paymentsBasketsCreateWithProductsCreate(
requestParameters: PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest,
options?: RawAxiosRequestConfig,
): AxiosPromise<BasketWithProduct> {
return localVarFp
.paymentsBasketsCreateWithProductsCreate(
requestParameters.CreateBasketWithProductsRequest,
options,
)
.then((request) => request(axios, basePath))
},
/**
* Returns or creates a basket for the current user and system.
* @param {PaymentsApiPaymentsBasketsForSystemRetrieveRequest} requestParameters Request parameters.
Expand Down Expand Up @@ -5113,6 +5266,20 @@ export interface PaymentsApiPaymentsBasketsCreateFromProductCreateRequest {
readonly system_slug: string
}

/**
* Request parameters for paymentsBasketsCreateWithProductsCreate operation in PaymentsApi.
* @export
* @interface PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest
*/
export interface PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest {
/**
*
* @type {CreateBasketWithProductsRequest}
* @memberof PaymentsApiPaymentsBasketsCreateWithProductsCreate
*/
readonly CreateBasketWithProductsRequest: CreateBasketWithProductsRequest
}

/**
* Request parameters for paymentsBasketsForSystemRetrieve operation in PaymentsApi.
* @export
Expand Down Expand Up @@ -5281,6 +5448,25 @@ export class PaymentsApi extends BaseAPI {
.then((request) => request(this.axios, this.basePath))
}

/**
* Creates or updates a basket for the current user, adding the selected product.
* @param {PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof PaymentsApi
*/
public paymentsBasketsCreateWithProductsCreate(
requestParameters: PaymentsApiPaymentsBasketsCreateWithProductsCreateRequest,
options?: RawAxiosRequestConfig,
) {
return PaymentsApiFp(this.configuration)
.paymentsBasketsCreateWithProductsCreate(
requestParameters.CreateBasketWithProductsRequest,
options,
)
.then((request) => request(this.axios, this.basePath))
}

/**
* Returns or creates a basket for the current user and system.
* @param {PaymentsApiPaymentsBasketsForSystemRetrieveRequest} requestParameters Request parameters.
Expand Down
60 changes: 60 additions & 0 deletions openapi/specs/v0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,32 @@ paths:
schema:
$ref: '#/components/schemas/BasketWithProduct'
description: ''
/api/v0/payments/baskets/create_with_products/:
post:
operationId: payments_baskets_create_with_products_create
description: Creates or updates a basket for the current user, adding the selected
product.
tags:
- payments
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateBasketWithProductsRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/CreateBasketWithProductsRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/CreateBasketWithProductsRequest'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/BasketWithProduct'
description: ''
/api/v0/payments/baskets/for_system/{system_slug}/:
get:
operationId: payments_baskets_for_system_retrieve
Expand Down Expand Up @@ -1402,6 +1428,40 @@ components:
- Yemen
- Zambia
- Zimbabwe
CreateBasketWithProductsRequest:
type: object
description: Serializer for creating a basket with products. (For OpenAPI spec.)
properties:
system_slug:
type: string
minLength: 1
skus:
type: array
items:
$ref: '#/components/schemas/CreateBasketWithProductsSkuRequest'
checkout:
type: boolean
discount_code:
type: string
minLength: 1
required:
- checkout
- discount_code
- skus
- system_slug
CreateBasketWithProductsSkuRequest:
type: object
description: Defines the schema for a SKU in the CreateBasketWithProductsSerializer.
properties:
sku:
type: string
minLength: 1
quantity:
type: integer
minimum: 1
required:
- quantity
- sku
CyberSourceCheckout:
type: object
description: Really basic serializer for the payload that we need to send to
Expand Down
16 changes: 16 additions & 0 deletions payments/serializers/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,19 @@ class CyberSourceCheckoutSerializer(serializers.Serializer):
payload = serializers.DictField()
url = serializers.CharField()
method = serializers.CharField()


class CreateBasketWithProductsSkuSerializer(serializers.Serializer):
"""Defines the schema for a SKU in the CreateBasketWithProductsSerializer."""

sku = serializers.CharField()
quantity = serializers.IntegerField(min_value=1)


class CreateBasketWithProductsSerializer(serializers.Serializer):
"""Serializer for creating a basket with products. (For OpenAPI spec.)"""

system_slug = serializers.CharField()
skus = CreateBasketWithProductsSkuSerializer(many=True)
checkout = serializers.BooleanField()
discount_code = serializers.CharField()
Loading

0 comments on commit a0eb3d4

Please sign in to comment.