Skip to content

Commit

Permalink
Create Payment Profile Method #5
Browse files Browse the repository at this point in the history
* feat: add new method to create new payment profiles
* Merge branch 'AlphaLawless:main' into main
* refactor: refactor payment profile create body
  • Loading branch information
AlphaLawless authored Jun 19, 2024
2 parents a4b7c54 + bd8abfe commit ed9dae4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib/rest/payment_profiles/create/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Http } from '@/lib/http'
import type {
PaymentProfilesCreateRequest,
PaymentProfilesCreateResponse
} from './protocols'

export const create = async ({
config,
body
}: PaymentProfilesCreateRequest): Promise<PaymentProfilesCreateResponse> => {
return await Http.fetch<PaymentProfilesCreateResponse>(
'/v1/payment_profiles',
{
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(`${config.key}:`).toString(
'base64'
)}`
},
body: JSON.stringify(body),
...config.options
}
)
}
20 changes: 20 additions & 0 deletions src/lib/rest/payment_profiles/create/protocols.ts
Original file line number Diff line number Diff line change
@@ -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<PaymentProfilesCreateData, 'requestOptions'> {
config: VindiClient
}

export declare interface PaymentProfilesCreateData {
body: PaymentProfilesCreateBody
requestOptions?: Options
}

export declare interface PaymentProfilesCreateResponse extends ApiResponse {
payment_profile: PaymentProfilesReturn
}
18 changes: 18 additions & 0 deletions src/lib/rest/payment_profiles/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<PaymentProfilesCreateResponse> {
const { requestOptions, body } = paymentProfilesCreateData
this.config.options = { ...this.config.options, ...requestOptions }
return create({ body, config: this.config })
}
}
6 changes: 6 additions & 0 deletions src/lib/rest/payment_profiles/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed9dae4

Please sign in to comment.