Skip to content

Commit d4b3192

Browse files
authored
Merge pull request #133 from m7ez1n/master
feat: implement smart transfers preauthorization and payment endpoints
2 parents 56069c2 + d1adf5c commit d4b3192

File tree

10 files changed

+179
-26
lines changed

10 files changed

+179
-26
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ dist
44
# Dependencies
55
node_modules
66

7-
.vscode
7+
.vscode
8+
9+
.env.local

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,9 @@ export class PluggyClient extends BaseApi {
200200
* @param accountId The account id
201201
* @returns {PageResponse<AccountStatement[]>} object which contains the Account statements list and related paging data
202202
*/
203-
async fetchAccountStatements(
204-
accountId: string
205-
): Promise<PageResponse<AccountStatement>> {
206-
return await this.createGetRequest(`accounts/${accountId}/statements`)
207-
}
203+
async fetchAccountStatements(accountId: string): Promise<PageResponse<AccountStatement>> {
204+
return await this.createGetRequest(`accounts/${accountId}/statements`)
205+
}
208206

209207
/**
210208
* Post transaction user category for transactin

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/deserialized.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ export type DeserializedItem = Omit<
7979
export type DeserializedTransaction = Omit<Transaction, 'date'> & {
8080
date: string
8181
}
82-

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/paymentCustomer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Connector } from "../connector"
1+
import { Connector } from '../connector'
22

33
export const PAYMENT_CUSTOMER_TYPE = ['INDIVIDUAL', 'BUSINESS'] as const
44

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

src/types/payments/paymentRequest.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PaymentCustomer } from './paymentCustomer'
1+
import { PaymentCustomer } from './paymentCustomer'
22
import { PaymentRecipient } from './paymentRecipient'
33

44
export declare const DAYS_OF_WEEK: readonly [
@@ -89,35 +89,41 @@ export type CustomSchedule = {
8989
additionalInformation?: string
9090
}
9191

92-
export const AUTOMATIC_PIX_INTERVALS = ["WEEKLY", "MONTHLY", "QUARTERLY", "SEMESTER", "YEARLY"] as const;
93-
export type AutomaticPixInterval = typeof AUTOMATIC_PIX_INTERVALS[number];
92+
export const AUTOMATIC_PIX_INTERVALS = [
93+
'WEEKLY',
94+
'MONTHLY',
95+
'QUARTERLY',
96+
'SEMESTER',
97+
'YEARLY',
98+
] as const
99+
export type AutomaticPixInterval = typeof AUTOMATIC_PIX_INTERVALS[number]
94100

95101
export type AutomaticPixFirstPayment = {
96102
/**! date of the first payment, default to instant */
97-
date?: string;
103+
date?: string
98104
/**! amount of the first payment */
99-
amount: number;
105+
amount: number
100106
/**! description of the first payment */
101-
description?: string;
102-
};
107+
description?: string
108+
}
103109

104110
export type PaymentRequestAutomaticPixDetails = {
105111
/**! interval of the authorization */
106-
interval: AutomaticPixInterval;
112+
interval: AutomaticPixInterval
107113
/**! start date of the authorization */
108-
startDate: string;
114+
startDate: string
109115
/**! fixed amount of the payment, if provided can't be used with minimumVariableAmount or maximumVariableAmount */
110-
fixedAmount?: number;
116+
fixedAmount?: number
111117
/**! minimum variable amount of the payment, if provided can't be used with fixedAmount */
112-
minimumVariableAmount?: number;
118+
minimumVariableAmount?: number
113119
/**! maximum variable amount of the payment, if provided can't be used with fixedAmount */
114-
maximumVariableAmount?: number;
120+
maximumVariableAmount?: number
115121
/**! expiration date of the authorization */
116-
expiresAt?: string;
122+
expiresAt?: string
117123
/**! if the payments done for this authorization can be retried */
118-
isRetryAccepted?: boolean;
124+
isRetryAccepted?: boolean
119125
/**! if provided, will execute a first payment */
120-
firstPayment?: AutomaticPixFirstPayment;
126+
firstPayment?: AutomaticPixFirstPayment
121127
}
122128

123129
export type PaymentRequest = {
@@ -162,4 +168,8 @@ export type CallbackUrls = {
162168
error?: string
163169
}
164170

165-
export type CreatePaymentRequestAutomaticPix = Pick<CreatePaymentRequest, 'description' | 'recipientId' | 'customerId' | 'callbackUrls' | 'clientPaymentId'> & PaymentRequestAutomaticPixDetails & { isSandbox: boolean }
171+
export type CreatePaymentRequestAutomaticPix = Pick<
172+
CreatePaymentRequest,
173+
'description' | 'recipientId' | 'customerId' | 'callbackUrls' | 'clientPaymentId'
174+
> &
175+
PaymentRequestAutomaticPixDetails & { isSandbox: boolean }
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)