This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwallet.compat-node-qiwi.ts
161 lines (150 loc) · 4.38 KB
/
wallet.compat-node-qiwi.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* istanbul ignore file */
import { Wallet } from "./wallet";
import type * as types from "./wallet.types";
/**
*
* @deprecated Это класс для тех, кто мигрирует с `node-qiwi`.
* Остальным рекомендуется использовать класс {@link Wallet}
*
* @export
* @class _WalletCompatNodeQiwi
* @extends {Wallet}
*/
export class _WalletCompatNodeQiwi extends Wallet {
/**
* Creates an instance of _WalletCompatNodeQiwi.
* @param {string} key
* @param {string} [contractId=""]
* @memberof _WalletCompatNodeQiwi
*/
constructor(public readonly key: string, public readonly contractId: string = "") {
super({
http: _WalletCompatNodeQiwi.httpClientFactory(key),
token: key,
walletId: contractId
});
}
/**
*
*
* @protected
* @template T
* @param {(string | number)} contractId
* @param {*} executor
* @return {Promise<T>} Promise<T>
* @memberof _WalletCompatNodeQiwi
*/
protected async _executeWithContractId<T>(
contractId: string | number,
executor: (api: _WalletCompatNodeQiwi) => Promise<T>
): Promise<T> {
const instance = new _WalletCompatNodeQiwi(this.key, contractId.toString());
instance.agent = this.agent;
try {
return await executor(instance);
} finally {
instance.agent = undefined;
}
}
/**
*
*
* @param {(string | number)} contractId
* @param {types.IdentificationBase} [body]
* @return {Promise<types.IdentificationResponse>} Promise<types.IdentificationResponse>
* @memberof _WalletCompatNodeQiwi
*/
async getIdentification(
contractId: string | number,
body?: types.IdentificationBase
): Promise<types.IdentificationResponse> {
return await this._executeWithContractId(contractId, async (wallet) => {
if (body) return await wallet.identification.set(body);
return await wallet.identification.get();
});
}
/**
*
*
* @param {(string | number)} contractId
* @param {types.GetPaymentHistoryParameters} settings
* @return {Promise<types.GetTransactionsHistoryResponse>} Promise<types.GetTransactionsHistoryResponse>
* @memberof _WalletCompatNodeQiwi
*/
async getHistory(
contractId: string | number,
settings: Partial<types.GetPaymentHistoryParameters> = {}
): Promise<types.GetTransactionsHistoryResponse> {
return await this._executeWithContractId(contractId, async (wallet) => {
return await wallet.paymentHistory.getHistory({ rows: 50, ...settings });
});
}
/**
*
*
* @param {(string | number)} contractId
* @param {types.GetPaymentHistoryTotalParameters} settings
* @return {Promise<types.GetPaymentHistoryTotalResponse>} Promise<types.GetPaymentHistoryTotalResponse>
* @memberof _WalletCompatNodeQiwi
*/
async getTransactionsStats(
contractId: string | number,
settings: types.GetPaymentHistoryTotalParameters
): Promise<types.GetPaymentHistoryTotalResponse> {
return await this._executeWithContractId(contractId, async (wallet) => {
return await wallet.paymentHistory.getTotal(settings);
});
}
/**
*
*
* @param {(string | number)} transactionId
* @param {{ type: types.TransactionTypeAny? }} [settings]
* @return {*} Promise<types.Transaction>
* @memberof _WalletCompatNodeQiwi
*/
async getTransaction(
transactionId: string | number,
settings: { type?: types.TransactionTypeAny } = {}
): Promise<types.Transaction> {
return await this.paymentHistory.getTransaction(transactionId, settings.type);
}
/**
*
*
* @return {*} Promise<types.PersonProfile>
* @memberof _WalletCompatNodeQiwi
*/
async getProfile(): Promise<types.PersonProfile> {
return await this.personProfile.getCurrent();
}
/**
*
*
* @return {Promise<types.Account[]>} Promise<types.Account[]>
* @memberof _WalletCompatNodeQiwi
*/
async getBalance(): Promise<types.Account[]> {
return await this.fundingSources.getAccounts();
}
/**
*
*
* @param {number} amount
* @param {string} account
* @param {string} [comment]
* @return {Promise<types.PaymentResponse>} Promise<types.PaymentResponse>
* @memberof _WalletCompatNodeQiwi
*/
async sendPayment(
amount: number,
account: string,
comment?: string
): Promise<types.PaymentResponse> {
return await this.payments.pay({
account,
amount,
comment
});
}
}