UNPKG

@coinbase/cdp-sdk

Version:

SDK for interacting with the Coinbase Developer Platform Wallet API

258 lines (243 loc) 11 kB
/** * @module PaymentMethods */ // This file was auto-generated by Fern from our API Definition. import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js"; import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient.js"; import { mergeHeaders } from "../../../../core/headers.js"; import * as core from "../../../../core/index.js"; import * as environments from "../../../../environments.js"; import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.js"; import * as errors from "../../../../errors/index.js"; import * as CoinbaseApi from "../../../index.js"; export declare namespace PaymentMethodsClient { export type Options = BaseClientOptions; export interface RequestOptions extends BaseRequestOptions {} } /** * 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. */ export class PaymentMethodsClient { protected readonly _options: NormalizedClientOptionsWithAuth<PaymentMethodsClient.Options>; constructor(options: PaymentMethodsClient.Options) { this._options = 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==" * }) * ``` */ public listPaymentMethods( request: CoinbaseApi.ListPaymentMethodsRequest = {}, requestOptions?: PaymentMethodsClient.RequestOptions, ): core.HttpResponsePromise<CoinbaseApi.ListPaymentMethodsResponse> { return core.HttpResponsePromise.fromPromise(this.__listPaymentMethods(request, requestOptions)); } private async __listPaymentMethods( request: CoinbaseApi.ListPaymentMethodsRequest = {}, requestOptions?: PaymentMethodsClient.RequestOptions, ): Promise<core.WithRawResponse<CoinbaseApi.ListPaymentMethodsResponse>> { const _metadata: core.EndpointMetadata = { security: [{ apiKeyAuth: [] }], method: "GET", path: "v2/payment-methods", operationId: "endpoint_paymentMethods.listPaymentMethods", }; const { pageSize, pageToken } = request; const _queryParams: Record<string, unknown> = { pageSize, pageToken, }; const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest({ endpointMetadata: _metadata, clientOptions: this._options, request: { method: "GET", }, }); const _headers: core.Fetcher.Args["headers"] = 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 as CoinbaseApi.ListPaymentMethodsResponse, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new CoinbaseApi.BadRequestError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); case 401: throw new CoinbaseApi.UnauthorizedError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); case 500: throw new CoinbaseApi.InternalServerError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); default: throw new errors.CoinbaseApiError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return 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" * }) * ``` */ public getPaymentMethod( request: CoinbaseApi.GetPaymentMethodRequest, requestOptions?: PaymentMethodsClient.RequestOptions, ): core.HttpResponsePromise<CoinbaseApi.PaymentMethodsPaymentMethod> { return core.HttpResponsePromise.fromPromise(this.__getPaymentMethod(request, requestOptions)); } private async __getPaymentMethod( request: CoinbaseApi.GetPaymentMethodRequest, requestOptions?: PaymentMethodsClient.RequestOptions, ): Promise<core.WithRawResponse<CoinbaseApi.PaymentMethodsPaymentMethod>> { const _metadata: core.EndpointMetadata = { security: [{ apiKeyAuth: [] }], method: "GET", path: "v2/payment-methods/{paymentMethodId}", operationId: "endpoint_paymentMethods.getPaymentMethod", }; const { paymentMethodId } = request; const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest({ endpointMetadata: _metadata, clientOptions: this._options, request: { method: "GET", }, }); const _headers: core.Fetcher.Args["headers"] = 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 as CoinbaseApi.PaymentMethodsPaymentMethod, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new CoinbaseApi.BadRequestError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); case 401: throw new CoinbaseApi.UnauthorizedError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); case 404: throw new CoinbaseApi.NotFoundError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); case 500: throw new CoinbaseApi.InternalServerError( _response.error.body as CoinbaseApi.Error_, _response.rawResponse, ); default: throw new errors.CoinbaseApiError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError( _response.error, _response.rawResponse, "GET", "/v2/payment-methods/{paymentMethodId}", ); } }