Skip to content

Commit fc28144

Browse files
committed
fix: add missing payments methods
1 parent 628040d commit fc28144

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

src/paymentsClient.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import {
2424
SchedulePayment,
2525
PaymentRequestAutomaticPix,
2626
CreatePaymentRequestAutomaticPix,
27+
AutomaticPixPayment,
28+
ScheduleAutomaticPixPaymentRequest,
29+
RetryAutomaticPixPaymentRequest,
30+
AutomaticPixPaymentListResponse,
31+
PaymentPixAutomaticFilters,
2732
} from './types'
2833

2934
/**
@@ -316,4 +321,93 @@ export class PluggyPaymentsClient extends BaseApi {
316321
async cancelScheduledPayments(paymentRequest: string): Promise<void> {
317322
await this.createPostRequest(`payments/requests/${paymentRequest}/schedules/cancel`)
318323
}
324+
325+
/**
326+
* Schedule a new payment for an existing Pix Automático authorization
327+
* @param authorizationId ID of the Pix Automático authorization
328+
* @param payload ScheduleAutomaticPixPaymentRequest
329+
* @returns {AutomaticPixPayment} AutomaticPixPayment object
330+
*/
331+
async scheduleAutomaticPixPayment(
332+
authorizationId: string,
333+
payload: ScheduleAutomaticPixPaymentRequest
334+
): Promise<AutomaticPixPayment> {
335+
return await this.createPostRequest(
336+
`payments/requests/${authorizationId}/automatic-pix/schedule`,
337+
null,
338+
payload
339+
)
340+
}
341+
342+
/**
343+
* Retry a failed scheduled Pix Automático payment
344+
* @param paymentRequestId ID of the payment request
345+
* @param automaticPixPaymentId ID of the Pix Automático authorization
346+
* @param payload RetryAutomaticPixPaymentRequest
347+
* @returns {AutomaticPixPayment} AutomaticPixPayment object
348+
*/
349+
async retryAutomaticPixPayment(
350+
paymentRequestId: string,
351+
automaticPixPaymentId: string,
352+
payload: RetryAutomaticPixPaymentRequest
353+
): Promise<AutomaticPixPayment> {
354+
return await this.createPostRequest(
355+
`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}/retry`,
356+
null,
357+
payload
358+
)
359+
}
360+
361+
/**
362+
* List scheduled Pix Automático payments for an authorization
363+
* @param automaticPixPaymentId ID of the Pix Automático authorization
364+
* @param options PaymentPixAutomaticFilters
365+
* @returns {AutomaticPixPaymentListResponse} List of scheduled payments
366+
*/
367+
async fetchAutomaticPixPayments(
368+
automaticPixPaymentId: string,
369+
options: PaymentPixAutomaticFilters
370+
): Promise<AutomaticPixPaymentListResponse> {
371+
return await this.createGetRequest(
372+
`payments/requests/${automaticPixPaymentId}/automatic-pix/schedules`,
373+
options
374+
)
375+
}
376+
377+
/**
378+
* Fetch a single scheduled Pix Automático payment
379+
* @param paymentRequestId ID of the payment request
380+
* @param automaticPixPaymentId ID of the Pix Automático authorization
381+
* @returns {AutomaticPixPayment} AutomaticPixPayment object
382+
*/
383+
async fetchAutomaticPixPayment(
384+
paymentRequestId: string,
385+
automaticPixPaymentId: string
386+
): Promise<AutomaticPixPayment> {
387+
return await this.createGetRequest(
388+
`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}`
389+
)
390+
}
391+
392+
/**
393+
* Cancel a scheduled Pix Automático payment
394+
* @param paymentRequestId ID of the payment request
395+
* @param automaticPixPaymentId ID of the Pix Automático authorization
396+
*/
397+
async cancelAutomaticPixPayment(
398+
paymentRequestId: string,
399+
automaticPixPaymentId: string
400+
): Promise<void> {
401+
await this.createPostRequest(
402+
`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}/cancel`
403+
)
404+
}
405+
406+
/**
407+
* Cancel all scheduled Pix Automático payments for a payment request authorization
408+
* @param paymentRequestId ID of the payment request
409+
*/
410+
async cancelAutomaticPixAuthorization(paymentRequestId: string): Promise<void> {
411+
await this.createPostRequest(`payments/requests/${paymentRequestId}/automatic-pix/cancel`)
412+
}
319413
}

src/types/payments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './smartAccount'
88
export * from './bulkPayment'
99
export * from './paymentReceipt'
1010
export * from './schedulePayment'
11+
export * from './pixAutomatic'

src/types/payments/pixAutomatic.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { PageFilters, PageResponse } from '../common'
2+
3+
export const AUTOMATIC_PIX_PAYMENT_STATUSES = [
4+
'SCHEDULED',
5+
'CREATED',
6+
'COMPLETED',
7+
'CANCELED',
8+
'ERROR',
9+
] as const
10+
export type AutomaticPixPaymentStatus = typeof AUTOMATIC_PIX_PAYMENT_STATUSES[number]
11+
12+
export type AutomaticPixPaymentErrorDetail = {
13+
code: string
14+
description: string
15+
detail?: string
16+
}
17+
18+
export type AutomaticPixPayment = {
19+
id: string
20+
status: AutomaticPixPaymentStatus
21+
amount: number
22+
description?: string
23+
date: string // YYYY-MM-DD
24+
endToEndId?: string
25+
errorDetail?: AutomaticPixPaymentErrorDetail | null
26+
}
27+
28+
export type ScheduleAutomaticPixPaymentRequest = {
29+
amount: number
30+
description?: string
31+
date: string // YYYY-MM-DD
32+
}
33+
34+
export type RetryAutomaticPixPaymentRequest = {
35+
date: string // YYYY-MM-DD
36+
}
37+
38+
export type AutomaticPixPaymentListResponse = PageResponse<AutomaticPixPayment>
39+
40+
export type PaymentPixAutomaticFilters = PageFilters

0 commit comments

Comments
 (0)