diff --git a/src/lib/rest/payment_profiles/create/index.ts b/src/lib/rest/payment_profiles/create/index.ts new file mode 100644 index 0000000..58b694c --- /dev/null +++ b/src/lib/rest/payment_profiles/create/index.ts @@ -0,0 +1,24 @@ +import { Http } from '@/lib/http' +import type { + PaymentProfilesCreateRequest, + PaymentProfilesCreateResponse +} from './protocols' + +export const create = async ({ + config, + body +}: PaymentProfilesCreateRequest): Promise => { + return await Http.fetch( + '/v1/payment_profiles', + { + method: 'POST', + headers: { + Authorization: `Basic ${Buffer.from(`${config.key}:`).toString( + 'base64' + )}` + }, + body: JSON.stringify(body), + ...config.options + } + ) +} diff --git a/src/lib/rest/payment_profiles/create/protocols.ts b/src/lib/rest/payment_profiles/create/protocols.ts new file mode 100644 index 0000000..9c8996d --- /dev/null +++ b/src/lib/rest/payment_profiles/create/protocols.ts @@ -0,0 +1,20 @@ +import type { ApiResponse, Options } from '@/protocols' +import type { VindiClient } from '@/vindi-client' +import type { + PaymentProfilesCreateBody, + PaymentProfilesReturn +} from '../protocols' + +export declare interface PaymentProfilesCreateRequest + extends Exclude { + config: VindiClient +} + +export declare interface PaymentProfilesCreateData { + body: PaymentProfilesCreateBody + requestOptions?: Options +} + +export declare interface PaymentProfilesCreateResponse extends ApiResponse { + payment_profile: PaymentProfilesReturn +} diff --git a/src/lib/rest/payment_profiles/index.ts b/src/lib/rest/payment_profiles/index.ts index 7fe80bb..898f786 100644 --- a/src/lib/rest/payment_profiles/index.ts +++ b/src/lib/rest/payment_profiles/index.ts @@ -1,4 +1,9 @@ import type { VindiClient } from '@/vindi-client' +import { create } from './create' +import type { + PaymentProfilesCreateData, + PaymentProfilesCreateResponse +} from './create/protocols' import { inactivate } from './inactivate' import type { PaymentProfilesInactivateData, @@ -38,4 +43,17 @@ export class PaymentProfiles { this.config.options = { ...this.config.options, ...requestOptions } return inactivate({ config: this.config, params, id }) } + + /** + * Vindi Create Payment Profile. + * + * @see {@link https://vindi.github.io/api-docs/dist/#/payment_profiles/postV1PaymentProfiles More Information} + */ + create( + paymentProfilesCreateData: PaymentProfilesCreateData + ): Promise { + const { requestOptions, body } = paymentProfilesCreateData + this.config.options = { ...this.config.options, ...requestOptions } + return create({ body, config: this.config }) + } } diff --git a/src/lib/rest/payment_profiles/protocols.ts b/src/lib/rest/payment_profiles/protocols.ts index 0e52459..6a7310e 100644 --- a/src/lib/rest/payment_profiles/protocols.ts +++ b/src/lib/rest/payment_profiles/protocols.ts @@ -10,6 +10,12 @@ export declare interface PaymentProfilesBody { remove_permanentrly: boolean } +export declare interface PaymentProfilesCreateBody { + gateway_token: string + customer_id: number + payment_method_code: string +} + export interface PaymentProfilesReturn { id: number status: string