Skip to content

Commit d1adf5c

Browse files
committed
feat: add smart transfer preauthorization and payment functionalities
1 parent f8eaba4 commit d1adf5c

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

src/paymentsClient.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import {
2929
RetryAutomaticPixPaymentRequest,
3030
AutomaticPixPaymentListResponse,
3131
PaymentPixAutomaticFilters,
32+
SmartTransferPreauthorization,
33+
CreateSmartTransferPreauthorization,
34+
SmartTransferPayment,
35+
CreateSmartTransferPayment,
36+
SmartTransferPreauthorizationsFilters,
3237
} from './types'
3338

3439
/**
@@ -410,4 +415,55 @@ export class PluggyPaymentsClient extends BaseApi {
410415
async cancelAutomaticPixAuthorization(paymentRequestId: string): Promise<void> {
411416
await this.createPostRequest(`payments/requests/${paymentRequestId}/automatic-pix/cancel`)
412417
}
418+
419+
/**
420+
* Fetch all smart transfer preauthorizations
421+
* @param options SmartTransferPreauthorizationsFilters with page and pageSize
422+
* @returns {PageResponse<SmartTransferPreauthorization>} paged response of smart transfer preauthorizations
423+
*/
424+
async fetchSmartTransferPreauthorizations(
425+
options: SmartTransferPreauthorizationsFilters = {}
426+
): Promise<PageResponse<SmartTransferPreauthorization>> {
427+
return await this.createGetRequest('smart-transfers/preauthorizations', { ...options })
428+
}
429+
430+
/**
431+
* Creates a smart transfer preauthorization
432+
* @param payload CreateSmartTransferPreauthorization
433+
* @returns {SmartTransferPreauthorization} SmartTransferPreauthorization object
434+
*/
435+
async createSmartTransferPreauthorization(
436+
payload: CreateSmartTransferPreauthorization
437+
): Promise<SmartTransferPreauthorization> {
438+
return await this.createPostRequest('smart-transfers/preauthorizations', null, payload)
439+
}
440+
441+
/**
442+
* Fetch a single smart transfer preauthorization
443+
* @param id ID of the smart transfer preauthorization
444+
* @returns {SmartTransferPreauthorization} SmartTransferPreauthorization object
445+
*/
446+
async fetchSmartTransferPreauthorization(id: string): Promise<SmartTransferPreauthorization> {
447+
return await this.createGetRequest(`smart-transfers/preauthorizations/${id}`)
448+
}
449+
450+
/**
451+
* Creates a smart transfer payment
452+
* @param payload CreateSmartTransferPayment
453+
* @returns {SmartTransferPayment} SmartTransferPayment object
454+
*/
455+
async createSmartTransferPayment(
456+
payload: CreateSmartTransferPayment
457+
): Promise<SmartTransferPayment> {
458+
return await this.createPostRequest('smart-transfers/payments', null, payload)
459+
}
460+
461+
/**
462+
* Fetch a single smart transfer payment
463+
* @param id ID of the smart transfer payment
464+
* @returns {SmartTransferPayment} SmartTransferPayment object
465+
*/
466+
async fetchSmartTransferPayment(id: string): Promise<SmartTransferPayment> {
467+
return await this.createGetRequest(`smart-transfers/payments/${id}`)
468+
}
413469
}

src/types/payments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './bulkPayment'
99
export * from './paymentReceipt'
1010
export * from './schedulePayment'
1111
export * from './pixAutomatic'
12+
export * from './smartTransfers'

src/types/payments/paymentFilters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export type PaymentRecipientsFilters = PageFilters
99
export type PaymentCustomersFilters = PageFilters
1010

1111
export type PaymentInstitutionsFilters = PageFilters & { name?: string }
12+
13+
export type SmartTransferPreauthorizationsFilters = PageFilters
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { Connector } from '../connector'
2+
import { PaymentInstitution } from './paymentInstitution'
3+
import {
4+
PaymentRecipient,
5+
PaymentRecipientAccount,
6+
PaymentRecipientBankAccountType,
7+
} from './paymentRecipient'
8+
import { Parameters } from '../item'
9+
10+
export const SMART_TRANSFER_PREAUTHORIZATION_STATUS = [
11+
'CREATED',
12+
'COMPLETED',
13+
'REVOKED',
14+
'REJECTED',
15+
'ERROR',
16+
] as const
17+
18+
export type SmartTransferPreauthorizationStatus = typeof SMART_TRANSFER_PREAUTHORIZATION_STATUS[number]
19+
20+
export const SMART_TRANSFER_PAYMENT_STATUS = [
21+
'PAYMENT_REJECTED',
22+
'ERROR',
23+
'CANCELED',
24+
'CONSENT_REJECTED',
25+
'CONSENT_AUTHORIZED',
26+
'PAYMENT_PENDING',
27+
'PAYMENT_PARTIALLY_ACCEPTED',
28+
'PAYMENT_SETTLEMENT_PROCESSING',
29+
'PAYMENT_SETTLEMENT_DEBTOR_ACCOUNT',
30+
'PAYMENT_COMPLETED',
31+
] as const
32+
33+
export type SmartTransferPaymentStatus = typeof SMART_TRANSFER_PAYMENT_STATUS[number]
34+
35+
export type SmartTransferRecipient = Pick<
36+
PaymentRecipient,
37+
'id' | 'name' | 'taxNumber' | 'isDefault' | 'paymentInstitution' | 'account'
38+
> & {
39+
pixKey: string | null
40+
}
41+
42+
export type SmartTransferPreauthorization = {
43+
id: string
44+
status: SmartTransferPreauthorizationStatus
45+
consentUrl: string | null
46+
clientPreauthorizationId: string | null
47+
callbackUrls: {
48+
success?: string
49+
error?: string
50+
} | null
51+
recipients: SmartTransferRecipient[]
52+
connector: Connector
53+
createdAt: Date
54+
updatedAt: Date
55+
}
56+
57+
export type CreateSmartTransferPreauthorization = {
58+
connectorId: number
59+
parameters: Parameters
60+
recipientIds: string[]
61+
callbackUrls?: {
62+
success?: string
63+
error?: string
64+
}
65+
}
66+
67+
export type CreateSmartTransferPayment = {
68+
preauthorizationId: string
69+
recipientId: string
70+
amount: number
71+
description?: string
72+
clientPaymentId?: string
73+
}
74+
75+
export type SmartTransferPayment = {
76+
id: string
77+
preauthorizationId: string
78+
status: SmartTransferPaymentStatus
79+
amount: number
80+
description: string | null
81+
recipient: SmartTransferRecipient
82+
createdAt: Date
83+
updatedAt: Date
84+
clientPaymentId: string | null
85+
}

0 commit comments

Comments
 (0)