-
Notifications
You must be signed in to change notification settings - Fork 18
/
payment.ts
64 lines (53 loc) · 1.78 KB
/
payment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Boleto, MoneyRequest, PixKey, PixPaymentRequest } from "./models";
import { AuthType, Context } from "./context";
import * as GqlOperations from "./utils/graphql-operations";
import { RequiresAuth } from "./utils/decorators";
export class Payment {
public get context(): Context {
return this._context;
}
public constructor(private _context: Context) {}
@RequiresAuth(AuthType.CERT)
public async createBoleto(amount: number): Promise<Boleto> {
const customerId: string = await this._context.account.getCustomerId();
const input = {
amount: String(amount),
customerId,
};
const { data: boletoData } = await this._context.http.graphql(
GqlOperations.MUTATION_CREATE_BOLETO,
{ input }
);
return boletoData?.createTransferInBoleto?.boleto;
}
@RequiresAuth(AuthType.CERT)
public async createMoneyRequest(amount: number): Promise<MoneyRequest> {
const savingsAccountId: string = await this._context.account.getId();
const input = {
amount,
savingsAccountId,
};
const { data: moneyRequestData } = await this._context.http.graphql(
GqlOperations.MUTATION_CREATE_MONEY_REQUEST,
{ input }
);
return moneyRequestData?.createMoneyRequest;
}
@RequiresAuth(AuthType.CERT)
public async createPixPaymentRequest(
pixKey: PixKey,
amount: number
): Promise<PixPaymentRequest> {
const savingsAccountId: string = await this._context.account.getId();
const createPaymentRequestInput = {
amount,
pixAlias: pixKey.value,
savingsAccountId,
};
const { data: moneyRequestData } = await this._context.http.graphql(
GqlOperations.MUTATION_CREATE_MONEY_REQUEST,
{ createPaymentRequestInput }
);
return moneyRequestData?.createMoneyRequest;
}
}