Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 8x 8x 8x 2x 1x 2x 2x 2x 2x 2x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x | import type { WalletApiOptions } from "./wallet.options";
import { WalletBillsApi } from "./bills.api";
import { WalletCardsApi } from "./cards.api";
import { WalletFundingSourcesApi } from "./funding-sources.api";
import { WalletIdentificationApi } from "./identification.api";
import { WalletLimitsApi } from "./limits.api";
import { WalletPaymentHistoryApi } from "./payment-history.api";
import { WalletPaymentsApi } from "./payments.api";
import { WalletPersonProfileApi } from "./person-profile.api";
import { WalletRestrictionsApi } from "./restrictions.api";
import { WalletWebhooksApi } from "./webhooks.api";
import {
PersonIdentificationLevel,
TransactionType,
TransactionStatus,
Currency,
ChequeFormat,
Recipients,
PaymentHistorySource,
LimitType,
CardStatus,
CardActionStatus,
PrettyTokenResponse
} from "./wallet.types";
import { mapHttpErrors } from "./wallet.errors";
import { ApiClass } from "../api";
import { WalletProvidersApi } from "./providers.api";
import { environment } from "../shared/environment";
import { SimpleJsonHttp } from "../shared/http";
import { url } from "../shared/url";
import { USER_AGENT } from "../shared/identity";
import { WalletNicknameApi } from "./nickname.api";
import { WalletOauthApi } from "./oauth.api";
/**
* @callback SetupHttp
* @param {SimpleJsonHttp} http
* @return {void} nothing
*/
type SetupHttp = (http: SimpleJsonHttp) => void;
type CreateAndFetchWalletIdParameters = {
setupHttp?: SetupHttp;
};
/**
* # API Кошелька
* [Документация QIWI](https://developer.qiwi.com/ru/qiwi-wallet-personal/)
*
* @export
* @class Wallet
*/
export class Wallet extends ApiClass<WalletApiOptions> {
static readonly PersonIdentificationLevel = PersonIdentificationLevel;
static readonly TransactionType = TransactionType;
static readonly TransactionStatus = TransactionStatus;
static readonly Currency = Currency;
static readonly ChequeFormat = ChequeFormat;
static readonly Recipients = Recipients;
static readonly PaymentHistorySource = PaymentHistorySource;
static readonly LimitType = LimitType;
static readonly CardStatus = CardStatus;
static readonly CardActionStatus = CardActionStatus;
static readonly IdentificationLevel = PersonIdentificationLevel;
static readonly ReceiptFormat = ChequeFormat;
static readonly PersonProfileApi = WalletPersonProfileApi;
static readonly IdentificationApi = WalletIdentificationApi;
static readonly LimitsApi = WalletLimitsApi;
static readonly RestrictionsApi = WalletRestrictionsApi;
static readonly PaymentHistoryApi = WalletPaymentHistoryApi;
static readonly FundingSourcesApi = WalletFundingSourcesApi;
static readonly CardsApi = WalletCardsApi;
static readonly PaymentsApi = WalletPaymentsApi;
static readonly BillsApi = WalletBillsApi;
static readonly WebhooksApi = WalletWebhooksApi;
static readonly ProvidersApi = WalletProvidersApi;
static readonly NicknameApi = WalletNicknameApi;
static readonly OauthApi = WalletOauthApi;
/**
*
*
* @static
* @param {string} token
* @return {SimpleJsonHttp} SimpleJsonHttp
* @memberof Wallet
*/
static httpClientFactory = (token: string): SimpleJsonHttp => {
const http = new SimpleJsonHttp();
http.client.options = {
...http.client.options,
baseURL: url`https://edge.qiwi.com/`(),
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"User-Agent": USER_AGENT,
Authorization: `Bearer ${token}`
},
okStatusCodes: [200, 201, 202, 203, 204],
timeout: 10_000,
mapHttpErrors
};
return http;
};
/**
* Создаёт экземпляр класса.
*
* Если используете с переменными окружения, то:
* - Переименуйте переменную с токеном в `QIWI_TOKEN`
* - Переименуйте переменную с номером кошелька (если есть) в `QIWI_WALLET`
* - Используйте статический метод {@link Wallet.env} вместо этого
*
*
* @static
* @param {string} token
* @param {string} [walletId=""]
* @return {Wallet} Wallet
* @memberof Wallet
*/
static create(token: string, walletId = ""): Wallet {
return new this({
http: this.httpClientFactory(token),
token,
walletId
});
}
/**
* Подхватывает токен из переменной окружения `QIWI_TOKEN` и
* номер телефона из переменной `QIWI_WALLET` и использует их
* для создания экземпляра
*
* @static
* @param {string} [token=process.env.QIWI_TOKEN]
* @param {string} [walletId=process.env.QIWI_WALLET]
* @return {Wallet} Wallet
* @memberof Wallet
*/
static env(
token = environment.QIWI_TOKEN,
walletId = environment.QIWI_WALLET
): Wallet {
return this.create(token, walletId);
}
/**
* Автоматически подтягивает номер телефона из API QIWI.
* Номер телефона требуется для вызова большинства методов из
* классов API:
*
* - {@link Wallet.IdentificationApi}
* - {@link Wallet.LimitsApi}
* - {@link Wallet.RestrictionsApi}
* - {@link Wallet.PaymentHistoryApi}
* - {@link Wallet.FundingSourcesApi}
* - {@link Wallet.CardsApi}
*
* @static
* @param {string} token
* @return {Promise<Wallet>} Promise<Wallet>
* @memberof Wallet
*/
static async createAndFetchWalletId(
token: string,
{ setupHttp }: CreateAndFetchWalletIdParameters = {}
): Promise<Wallet> {
const options: WalletApiOptions = {
token,
walletId: "",
http: this.httpClientFactory(token)
};
setupHttp?.(options.http);
const personProfileApi = new this.PersonProfileApi(options);
const profile = await personProfileApi.getCurrent();
const walletId = profile.contractInfo.contractId.toString();
return new this({ ...options, walletId });
}
/**
* Creates an instance of Wallet.
* @param {WalletApiOptions} [options]
* @memberof Wallet
*/
constructor({
token = "",
walletId = "",
http = Wallet.httpClientFactory(token)
}: Partial<WalletApiOptions> = {}) {
super({ token, walletId, http });
}
readonly personProfile = new Wallet.PersonProfileApi(this._options);
readonly identification = new Wallet.IdentificationApi(this._options);
readonly limits = new Wallet.LimitsApi(this._options);
readonly restrictions = new Wallet.RestrictionsApi(this._options);
readonly paymentHistory = new Wallet.PaymentHistoryApi(this._options);
readonly fundingSources = new Wallet.FundingSourcesApi(this._options);
readonly cards = new Wallet.CardsApi(this._options);
readonly payments = new Wallet.PaymentsApi(this._options);
readonly bills = new Wallet.BillsApi(this._options);
readonly webhooks = new Wallet.WebhooksApi(this._options);
readonly providers = new Wallet.ProvidersApi(this._options);
readonly nickname = new Wallet.NicknameApi(this._options);
readonly oauth = new Wallet.OauthApi(this._options);
/**
* Создаёт токен с увеличенным сроком действия (10 лет)
*
* [Документация](https://developer.qiwi.com/ru/qiwi-wallet-personal-advanced/)
*/
async createOauthToken(): Promise<PrettyTokenResponse<Wallet>> {
/* istanbul ignore next */
const { expiry, token } = await this.oauth.createToken();
/* istanbul ignore next */
return { expiry, token, client: new Wallet({ ...this._options, token }) };
}
}
|