UNPKG

@coinbase/cdp-sdk

Version:

SDK for interacting with the Coinbase Developer Platform Wallet API

223 lines 10.4 kB
"use strict"; /** * @module PaymentMethods */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PaymentMethodsClient = void 0; const BaseClient_js_1 = require("../../../../BaseClient.js"); const headers_js_1 = require("../../../../core/headers.js"); const core = __importStar(require("../../../../core/index.js")); const environments = __importStar(require("../../../../environments.js")); const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js"); const errors = __importStar(require("../../../../errors/index.js")); const CoinbaseApi = __importStar(require("../../../index.js")); /** * The Payment Methods APIs enable you to create and manage payment methods for accounts. Payment methods represent ways to send and receive payments, such as ACH transfers and Fedwire transfers. These APIs allow you to create, list, and retrieve payment method details for use in payment transfers and transactions. */ class PaymentMethodsClient { _options; constructor(options) { this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options); } /** * List payment methods linked to your entity. Payment methods represent external financial instruments that can be used as a target for transfers. The list will not include disabled or deleted payment methods. * * **Currently Supported Types:** * - `fedwire`: Domestic USD wire transfers * - `swift`: International wire transfers * - `sepa`: SEPA EUR transfers * * **Note:** Payment methods are created and verified through your linked CDP entity. Currently, fetching payment methods is only supported for Prime investment vehicles linked to CDP. * * @param {CoinbaseApi.ListPaymentMethodsRequest} request * @param {PaymentMethodsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws CoinbaseApi.BadRequestError * @throws CoinbaseApi.UnauthorizedError * @throws CoinbaseApi.InternalServerError * * @example * ```ts * await client.paymentMethods.listPaymentMethods({ * pageToken: "eyJsYXN0X2lkIjogImFiYzEyMyIsICJ0aW1lc3RhbXAiOiAxNzA3ODIzNzAxfQ==" * }) * ``` */ listPaymentMethods(request = {}, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__listPaymentMethods(request, requestOptions)); } async __listPaymentMethods(request = {}, requestOptions) { const _metadata = { security: [{ apiKeyAuth: [] }], method: "GET", path: "v2/payment-methods", operationId: "endpoint_paymentMethods.listPaymentMethods", }; const { pageSize, pageToken } = request; const _queryParams = { pageSize, pageToken, }; const _authRequest = await this._options.authProvider.getAuthRequest({ endpointMetadata: _metadata, clientOptions: this._options, request: { method: "GET", }, }); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, this._options?.headers, requestOptions?.headers); const _response = await core.fetcher({ url: core.url.join((await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.CoinbaseApiEnvironment.Default, "v2/payment-methods"), method: "GET", headers: _headers, queryString: core.url .queryBuilder() .addMany(_queryParams) .mergeAdditional(requestOptions?.queryParams) .build(), timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, abortSignal: requestOptions?.abortSignal, endpointMetadata: _metadata, fetchFn: this._options?.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new CoinbaseApi.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new CoinbaseApi.UnauthorizedError(_response.error.body, _response.rawResponse); case 500: throw new CoinbaseApi.InternalServerError(_response.error.body, _response.rawResponse); default: throw new errors.CoinbaseApiError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v2/payment-methods"); } /** * Get details of a specific payment method by its ID. Returns 404 if the payment method is not found or not owned by the requesting entity. * * @param {CoinbaseApi.GetPaymentMethodRequest} request * @param {PaymentMethodsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws CoinbaseApi.BadRequestError * @throws CoinbaseApi.UnauthorizedError * @throws CoinbaseApi.NotFoundError * @throws CoinbaseApi.InternalServerError * * @example * ```ts * await client.paymentMethods.getPaymentMethod({ * paymentMethodId: "paymentMethod_8e03978e-40d5-43e8-bc93-6894a57f9324" * }) * ``` */ getPaymentMethod(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__getPaymentMethod(request, requestOptions)); } async __getPaymentMethod(request, requestOptions) { const _metadata = { security: [{ apiKeyAuth: [] }], method: "GET", path: "v2/payment-methods/{paymentMethodId}", operationId: "endpoint_paymentMethods.getPaymentMethod", }; const { paymentMethodId } = request; const _authRequest = await this._options.authProvider.getAuthRequest({ endpointMetadata: _metadata, clientOptions: this._options, request: { method: "GET", }, }); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, this._options?.headers, requestOptions?.headers); const _response = await core.fetcher({ url: core.url.join((await core.Supplier.get(this._options.baseUrl)) ?? (await core.Supplier.get(this._options.environment)) ?? environments.CoinbaseApiEnvironment.Default, `v2/payment-methods/${core.url.encodePathParam(paymentMethodId)}`), method: "GET", headers: _headers, queryString: core.url.queryBuilder().mergeAdditional(requestOptions?.queryParams).build(), timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, abortSignal: requestOptions?.abortSignal, endpointMetadata: _metadata, fetchFn: this._options?.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new CoinbaseApi.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new CoinbaseApi.UnauthorizedError(_response.error.body, _response.rawResponse); case 404: throw new CoinbaseApi.NotFoundError(_response.error.body, _response.rawResponse); case 500: throw new CoinbaseApi.InternalServerError(_response.error.body, _response.rawResponse); default: throw new errors.CoinbaseApiError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v2/payment-methods/{paymentMethodId}"); } } exports.PaymentMethodsClient = PaymentMethodsClient; //# sourceMappingURL=Client.js.map