UNPKG

yookassa-sdk-node

Version:
1 lines 3.44 kB
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import createClient, { Client } from 'openapi-fetch';\nimport type { paths, components, operations } from './openapi';\n\nexport type Schemas = components['schemas'];\n\nexport type CreatePaymentBody = components['schemas']['CreatePaymentRequest'];\n\nexport type GetPaymentListQuery = operations['get-payment-list']['parameters']['query'];\n\nexport type CreateInvoiceBody = components['schemas']['CreateInvoiceRequest'];\n\nexport type WebhookEvent = components['schemas']['WebhookEvent'];\n\ninterface SDKOptions {\n shopId: string;\n secretKey: string;\n /**\n * RequestInit extension object to pass as 2nd argument to fetch when supported (defaults to\n * undefined)\n */\n requestInitExt?: Record<string, unknown>;\n}\n\nexport class YooKassaSDK {\n constructor({ shopId, secretKey, requestInitExt }: SDKOptions) {\n this.client = createClient<paths>({ baseUrl: 'https://api.yookassa.ru/v3/', requestInitExt });\n\n this.client.use({\n onRequest({ request }) {\n const credentials = btoa(`${shopId}:${secretKey}`);\n request.headers.set('Authorization', 'Basic ' + credentials);\n },\n });\n }\n\n private readonly client: Client<paths>;\n\n createPayment({ body, idempotenceKey }: { body: CreatePaymentBody; idempotenceKey: string }) {\n return this.client.POST('/payments', {\n params: {\n header: {\n ['Idempotence-Key']: idempotenceKey,\n },\n },\n body,\n });\n }\n\n getPaymentList({ query }: { query: GetPaymentListQuery }) {\n return this.client.GET('/payments', {\n params: { query },\n });\n }\n\n getPayment({ payment_id }: { payment_id: string }) {\n return this.client.GET('/payments/{payment_id}', {\n params: {\n path: { payment_id },\n },\n });\n }\n\n createInvoice({ body, idempotenceKey }: { body: CreateInvoiceBody; idempotenceKey: string }) {\n return this.client.POST('/invoices', {\n params: {\n header: {\n ['Idempotence-Key']: idempotenceKey,\n },\n },\n body,\n });\n }\n\n getInvoice({ invoice_id }: { invoice_id: string }) {\n return this.client.GET('/invoices/{invoice_id}', {\n params: {\n path: { invoice_id },\n },\n });\n }\n}\n"],"mappings":";AAAA,OAAO,kBAA8B;AAuB9B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