UNPKG

sdksio-postnl-ecommerce-apis-sdk

Version:

Collection of PostNL API's for ecommerce processes

54 lines (51 loc) 1.89 kB
/** * PostNL Ecommerce APIsLib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, RequestOptions } from '../core'; import { CheckoutResponseError } from '../errors/checkoutResponseError'; import { CheckoutResponseInvalidError, } from '../errors/checkoutResponseInvalidError'; import { PostCIFCheckoutServiceMethodNotAllowedError, } from '../errors/postCIFCheckoutServiceMethodNotAllowedError'; import { PostCIFCheckoutServiceTooManyRequestError, } from '../errors/postCIFCheckoutServiceTooManyRequestError'; import { PostCIFCheckoutServiceUnauthorizedError, } from '../errors/postCIFCheckoutServiceUnauthorizedError'; import { CheckoutRequest, checkoutRequestSchema, } from '../models/checkoutRequest'; import { CheckoutResponse, checkoutResponseSchema, } from '../models/checkoutResponse'; import { BaseController } from './baseController'; export class CheckoutController extends BaseController { /** * Checkout * * @param body * @return Response from the API call */ async checkout( body: CheckoutRequest, requestOptions?: RequestOptions ): Promise<ApiResponse<CheckoutResponse>> { const req = this.createRequest('POST', '/shipment/v1/checkout'); const mapped = req.prepareArgs({ body: [body, checkoutRequestSchema] }); req.header('Content-Type', 'application/json'); req.json(mapped.body); req.throwOn(400, CheckoutResponseInvalidError, 'Invalid request'); req.throwOn(401, PostCIFCheckoutServiceUnauthorizedError, 'Invalid apikey'); req.throwOn(405, PostCIFCheckoutServiceMethodNotAllowedError, 'Method not allowed'); req.throwOn(429, PostCIFCheckoutServiceTooManyRequestError, 'Too many requests'); req.throwOn(500, CheckoutResponseError, 'Internal server error'); return req.callAsJson(checkoutResponseSchema, requestOptions); } }