/** * PagarmeApiSDKLib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { ApiResponse, RequestOptions } from '../core'; import { CreateTokenRequest, createTokenRequestSchema, } from '../models/createTokenRequest'; import { GetTokenResponse, getTokenResponseSchema, } from '../models/getTokenResponse'; import { optional, string } from '../schema'; import { BaseController } from './baseController'; export class TokensController extends BaseController { /** * @param publicKey Public key * @param request Request for creating a token * @param idempotencyKey * @return Response from the API call */ async createToken( publicKey: string, request: CreateTokenRequest, idempotencyKey?: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('POST'); const mapped = req.prepareArgs({ publicKey: [publicKey, string()], request: [request, createTokenRequestSchema], idempotencyKey: [idempotencyKey, optional(string())], }); req.header('idempotency-key', mapped.idempotencyKey); req.json(mapped.request); req.appendTemplatePath`/tokens?appId=${mapped.publicKey}`; req.authenticate(false); return req.callAsJson(getTokenResponseSchema, requestOptions); } /** * Gets a token from its id * * @param id Token id * @param publicKey Public key * @return Response from the API call */ async getToken( id: string, publicKey: string, requestOptions?: RequestOptions ): Promise> { const req = this.createRequest('GET'); const mapped = req.prepareArgs({ id: [id, string()], publicKey: [publicKey, string()], }); req.appendTemplatePath`/tokens/${mapped.id}?appId=${mapped.publicKey}`; req.authenticate(false); return req.callAsJson(getTokenResponseSchema, requestOptions); } }