From 540a36b58934cb0db049f5b7f68d3a8fc0c69ce7 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 26 Dec 2024 13:36:44 +0200 Subject: [PATCH] chore: improve payment provider tsdocs + generate reference --- .../core/utils/src/fulfillment/provider.ts | 2 + .../src/payment/abstract-payment-provider.ts | 69 ++- www/apps/resources/generated/edit-dates.mjs | 2 +- www/apps/resources/generated/sidebar.mjs | 580 +++++++++++++++++- .../page.mdx | 67 +- .../typedoc-json-output/payment-provider.json | 288 ++++----- .../merger-custom-options/payment-provider.ts | 5 +- 7 files changed, 815 insertions(+), 198 deletions(-) diff --git a/packages/core/utils/src/fulfillment/provider.ts b/packages/core/utils/src/fulfillment/provider.ts index 22582d2ccb98a..1e5e326457f16 100644 --- a/packages/core/utils/src/fulfillment/provider.ts +++ b/packages/core/utils/src/fulfillment/provider.ts @@ -48,6 +48,8 @@ import { * * this.logger_ = logger * this.options_ = options + * + * // TODO initialize your client * } * } * diff --git a/packages/core/utils/src/payment/abstract-payment-provider.ts b/packages/core/utils/src/payment/abstract-payment-provider.ts index 7709e2ea4fa6e..56f995fdda33c 100644 --- a/packages/core/utils/src/payment/abstract-payment-provider.ts +++ b/packages/core/utils/src/payment/abstract-payment-provider.ts @@ -39,60 +39,52 @@ export abstract class AbstractPaymentProvider> static validateOptions(options: Record): void | never {} /** - * You can use the `constructor` of the provider's service to access resources in your module's container. - * - * You can also use the constructor to initialize your integration with the third-party provider. For example, if you use a client to connect to the third-party provider’s APIs, - * you can initialize it in the constructor and use it in other methods in the service. - * - * The provider can also access the module's options as a second parameter. + * The constructor allows you to access resources from the [module's container](https://docs.medusajs.com/learn/fundamentals/modules/container) + * using the first parameter, and the module's options using the second parameter. + * + * :::note + * + * A module's options are passed when you register it in the Medusa application. + * + * ::: * * @param {Record} cradle - The module's container cradle used to resolve resources. * @param {Record} config - The options passed to the Payment Module provider. + * @typeParam TConfig - The type of the provider's options passed as a second parameter. * * @example - * ```ts - * import { - * AbstractPaymentProvider - * } from "@medusajs/framework/utils" + * import { AbstractPaymentProvider } from "@medusajs/framework/utils" * import { Logger } from "@medusajs/framework/types" - * - * type InjectedDependencies = { - * logger: Logger - * } - * + * * type Options = { * apiKey: string * } - * - * class MyPaymentProviderService extends AbstractPaymentProvider< - * Options - * > { - * static identifier = "my-payment" + * + * type InjectedDependencies = { + * logger: Logger + * } + * + * class MyPaymentProviderService extends AbstractPaymentProvider { * protected logger_: Logger * protected options_: Options - * // Assuming you're using a client to integrate - * // with a third-party service + * // assuming you're initializing a client * protected client - * + * * constructor( - * { logger }: InjectedDependencies, + * container: InjectedDependencies, * options: Options * ) { - * // @ts-ignore - * super(...arguments) - * - * this.logger_ = logger + * super(container, options) + * + * this.logger_ = container.logger * this.options_ = options - * - * // Assuming you're initializing a client - * this.client = new Client(options) + * + * // TODO initialize your client * } - * * // ... * } - * + * * export default MyPaymentProviderService - * ``` */ protected constructor( cradle: Record, @@ -175,6 +167,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentData.id * * try { + * // assuming you have a client that captures the payment * const newData = await this.client.capturePayment(externalId) * * return { @@ -237,6 +230,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentSessionData.id * * try { + * // assuming you have a client that authorizes the payment * const paymentData = await this.client.authorizePayment(externalId) * * return { @@ -299,6 +293,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentData.id * * try { + * // assuming you have a client that cancels the payment * const paymentData = await this.client.cancelPayment(externalId) * } catch (e) { * return { @@ -345,6 +340,7 @@ export abstract class AbstractPaymentProvider> * } = context * * try { + * // assuming you have a client that initializes the payment * const response = await this.client.init( * amount, currency_code, customerDetails * ) @@ -399,6 +395,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentSessionData.id * * try { + * // assuming you have a client that cancels the payment * await this.client.cancelPayment(externalId) * } catch (e) { * return { @@ -439,6 +436,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentSessionData.id * * try { + * // assuming you have a client that retrieves the payment status * const status = await this.client.getStatus(externalId) * * switch (status) { @@ -491,6 +489,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentData.id * * try { + * // assuming you have a client that refunds the payment * const newData = await this.client.refund( * externalId, * refundAmount @@ -543,6 +542,7 @@ export abstract class AbstractPaymentProvider> * const externalId = paymentSessionData.id * * try { + * // assuming you have a client that retrieves the payment * return await this.client.retrieve(externalId) * } catch (e) { * return { @@ -591,6 +591,7 @@ export abstract class AbstractPaymentProvider> * const externalId = data.id * * try { + * // assuming you have a client that updates the payment * const response = await this.client.update( * externalId, * { diff --git a/www/apps/resources/generated/edit-dates.mjs b/www/apps/resources/generated/edit-dates.mjs index a1d907577b574..2cc6b39f1eb86 100644 --- a/www/apps/resources/generated/edit-dates.mjs +++ b/www/apps/resources/generated/edit-dates.mjs @@ -1389,7 +1389,7 @@ export const generatedEditDates = { "references/payment/interfaces/payment.JoinerServiceConfig/page.mdx": "2024-12-09T13:22:02.312Z", "references/payment/interfaces/payment.JoinerServiceConfigAlias/page.mdx": "2024-12-09T13:22:02.308Z", "references/payment/types/payment.JoinerRelationship/page.mdx": "2024-12-09T13:22:02.304Z", - "references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx": "2024-12-09T13:22:02.268Z", + "references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx": "2024-12-26T11:35:43.318Z", "references/pricing/IPricingModuleService/methods/pricing.IPricingModuleService.addPriceListPrices/page.mdx": "2024-12-09T13:22:02.928Z", "references/pricing/IPricingModuleService/methods/pricing.IPricingModuleService.addPrices/page.mdx": "2024-12-09T13:22:02.868Z", "references/pricing/IPricingModuleService/methods/pricing.IPricingModuleService.calculatePrices/page.mdx": "2024-12-09T13:22:02.832Z", diff --git a/www/apps/resources/generated/sidebar.mjs b/www/apps/resources/generated/sidebar.mjs index 63d27ae864a44..28f1689bb2e03 100644 --- a/www/apps/resources/generated/sidebar.mjs +++ b/www/apps/resources/generated/sidebar.mjs @@ -238,6 +238,25 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "initialOpen": false, + "autogenerate_tags": "admin+apiKey", + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "apiKey", + "path": "/references/js-sdk/admin/apiKey", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -1106,6 +1125,14 @@ export const generatedSidebar = [ "title": "Checkout Step 3: Choose Shipping Method", "path": "/storefront-development/checkout/shipping", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "cart", + "path": "/references/js-sdk/store/cart", + "children": [] } ] }, @@ -1881,6 +1908,25 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+currency", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "currency", + "path": "/references/js-sdk/admin/currency", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -2106,6 +2152,41 @@ export const generatedSidebar = [ "title": "Third-Party or Social Login in Storefront", "path": "/storefront-development/customers/third-party-login", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "customer", + "path": "/references/js-sdk/store/customer", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+customer", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "customer", + "path": "/references/js-sdk/admin/customer", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "customerGroup", + "path": "/references/js-sdk/admin/customerGroup", + "children": [] } ] }, @@ -2812,6 +2893,65 @@ export const generatedSidebar = [ "title": "Checkout Step 3: Choose Shipping Method", "path": "/storefront-development/checkout/shipping", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "fulfillment", + "path": "/references/js-sdk/store/fulfillment", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+fulfillment", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "fulfillment", + "path": "/references/js-sdk/admin/fulfillment", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "fulfillmentProvider", + "path": "/references/js-sdk/admin/fulfillmentProvider", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "fulfillmentSet", + "path": "/references/js-sdk/admin/fulfillmentSet", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "shippingOption", + "path": "/references/js-sdk/admin/shippingOption", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "shippingProfile", + "path": "/references/js-sdk/admin/shippingProfile", + "children": [] } ] }, @@ -3983,6 +4123,33 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+inventory", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "inventoryItem", + "path": "/references/js-sdk/admin/inventoryItem", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "reservation", + "path": "/references/js-sdk/admin/reservation", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -4867,6 +5034,81 @@ export const generatedSidebar = [ "title": "Checkout Step 5: Complete Cart", "path": "/storefront-development/checkout/complete-cart", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "order", + "path": "/references/js-sdk/store/order", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+order", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "claim", + "path": "/references/js-sdk/admin/claim", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "exchange", + "path": "/references/js-sdk/admin/exchange", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "order", + "path": "/references/js-sdk/admin/order", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "orderEdit", + "path": "/references/js-sdk/admin/orderEdit", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "refundReason", + "path": "/references/js-sdk/admin/refundReason", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "return", + "path": "/references/js-sdk/admin/return", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "returnReason", + "path": "/references/js-sdk/admin/returnReason", + "children": [] } ] }, @@ -7318,6 +7560,14 @@ export const generatedSidebar = [ "title": "Payment with Stripe in React Storefront", "path": "/storefront-development/checkout/payment/stripe", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "payment", + "path": "/references/js-sdk/store/payment", + "children": [] } ] }, @@ -7325,8 +7575,8 @@ export const generatedSidebar = [ "loaded": true, "isPathHref": true, "type": "category", - "title": "Workflows", - "autogenerate_tags": "workflow+payment", + "title": "Admin Guides", + "autogenerate_tags": "admin+payment", "initialOpen": false, "autogenerate_as_ref": true, "children": [ @@ -7334,24 +7584,51 @@ export const generatedSidebar = [ "loaded": true, "isPathHref": true, "type": "ref", - "title": "createCartWorkflow", - "path": "/references/medusa-workflows/createCartWorkflow", - "children": [] - }, - { - "loaded": true, - "isPathHref": true, - "type": "ref", - "title": "createPaymentCollectionForCartWorkflow", - "path": "/references/medusa-workflows/createPaymentCollectionForCartWorkflow", + "title": "payment", + "path": "/references/js-sdk/admin/payment", "children": [] }, { "loaded": true, "isPathHref": true, "type": "ref", - "title": "refreshPaymentCollectionForCartWorkflow", - "path": "/references/medusa-workflows/refreshPaymentCollectionForCartWorkflow", + "title": "paymentCollection", + "path": "/references/js-sdk/admin/paymentCollection", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Workflows", + "autogenerate_tags": "workflow+payment", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "createCartWorkflow", + "path": "/references/medusa-workflows/createCartWorkflow", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "createPaymentCollectionForCartWorkflow", + "path": "/references/medusa-workflows/createPaymentCollectionForCartWorkflow", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "refreshPaymentCollectionForCartWorkflow", + "path": "/references/medusa-workflows/refreshPaymentCollectionForCartWorkflow", "children": [] }, { @@ -8052,6 +8329,33 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+pricing", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "priceList", + "path": "/references/js-sdk/admin/priceList", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "pricePreference", + "path": "/references/js-sdk/admin/pricePreference", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -9036,6 +9340,89 @@ export const generatedSidebar = [ "title": "Select Product Variants in Storefront", "path": "/storefront-development/products/variants", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "category", + "path": "/references/js-sdk/store/category", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "collection", + "path": "/references/js-sdk/store/collection", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "product", + "path": "/references/js-sdk/store/product", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+product", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "product", + "path": "/references/js-sdk/admin/product", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "productCategory", + "path": "/references/js-sdk/admin/productCategory", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "productCollection", + "path": "/references/js-sdk/admin/productCollection", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "productTag", + "path": "/references/js-sdk/admin/productTag", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "productType", + "path": "/references/js-sdk/admin/productType", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "productVariant", + "path": "/references/js-sdk/admin/productVariant", + "children": [] } ] }, @@ -10247,6 +10634,33 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+promotion", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "campaign", + "path": "/references/js-sdk/admin/campaign", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "promotion", + "path": "/references/js-sdk/admin/promotion", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -10901,6 +11315,33 @@ export const generatedSidebar = [ "title": "Store and Retrieve Region", "path": "/storefront-development/regions/store-retrieve-region", "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "region", + "path": "/references/js-sdk/store/region", + "children": [] + } + ] + }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+region", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "region", + "path": "/references/js-sdk/admin/region", + "children": [] } ] }, @@ -11303,6 +11744,25 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+salesChannel", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "salesChannel", + "path": "/references/js-sdk/admin/salesChannel", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -11675,6 +12135,25 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+stockLocation", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "stockLocation", + "path": "/references/js-sdk/admin/stockLocation", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -11927,6 +12406,25 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+store", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "store", + "path": "/references/js-sdk/admin/store", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -12337,6 +12835,33 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+tax", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "taxRate", + "path": "/references/js-sdk/admin/taxRate", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "taxRegion", + "path": "/references/js-sdk/admin/taxRegion", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, @@ -12887,6 +13412,33 @@ export const generatedSidebar = [ } ] }, + { + "loaded": true, + "isPathHref": true, + "type": "category", + "title": "Admin Guides", + "autogenerate_tags": "admin+user", + "initialOpen": false, + "autogenerate_as_ref": true, + "children": [ + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "invite", + "path": "/references/js-sdk/admin/invite", + "children": [] + }, + { + "loaded": true, + "isPathHref": true, + "type": "ref", + "title": "user", + "path": "/references/js-sdk/admin/user", + "children": [] + } + ] + }, { "loaded": true, "isPathHref": true, diff --git a/www/apps/resources/references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx b/www/apps/resources/references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx index a683021907e44..b5a5a81f4ef0f 100644 --- a/www/apps/resources/references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx +++ b/www/apps/resources/references/payment_provider/classes/payment_provider.AbstractPaymentProvider/page.mdx @@ -36,6 +36,62 @@ class MyPaymentProviderService extends AbstractPaymentProvider< export default MyPaymentProviderService ``` +### constructor + +The constructor allows you to access resources from the [module's container](https://docs.medusajs.com/learn/fundamentals/modules/container) +using the first parameter, and the module's options using the second parameter. + +:::note + +A module's options are passed when you register it in the Medusa application. + +::: + +#### Example + +```ts +import { AbstractPaymentProvider } from "@medusajs/framework/utils" +import { Logger } from "@medusajs/framework/types" + +type Options = { + apiKey: string +} + +type InjectedDependencies = { + logger: Logger +} + +class MyPaymentProviderService extends AbstractPaymentProvider { + protected logger_: Logger + protected options_: Options + // assuming you're initializing a client + protected client + + constructor( + container: InjectedDependencies, + options: Options + ) { + super(container, options) + + this.logger_ = container.logger + this.options_ = options + + // TODO initialize your client + } + // ... +} + +export default MyPaymentProviderService +``` + +#### Type Parameters + + + +#### Parameters + +`","description":"The module's container cradle used to resolve resources.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="AbstractPaymentProvider"/> + ### identifier Each payment provider has a unique identifier defined in its class. The provider's ID @@ -111,6 +167,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentData.id try { + // assuming you have a client that captures the payment const newData = await this.client.capturePayment(externalId) return { @@ -173,6 +230,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentSessionData.id try { + // assuming you have a client that authorizes the payment const paymentData = await this.client.authorizePayment(externalId) return { @@ -225,6 +283,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentData.id try { + // assuming you have a client that cancels the payment const paymentData = await this.client.cancelPayment(externalId) } catch (e) { return { @@ -274,6 +333,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< } = context try { + // assuming you have a client that initializes the payment const response = await this.client.init( amount, currency_code, customerDetails ) @@ -331,6 +391,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentSessionData.id try { + // assuming you have a client that cancels the payment await this.client.cancelPayment(externalId) } catch (e) { return { @@ -374,6 +435,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentSessionData.id try { + // assuming you have a client that retrieves the payment status const status = await this.client.getStatus(externalId) switch (status) { @@ -428,6 +490,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentData.id try { + // assuming you have a client that refunds the payment const newData = await this.client.refund( externalId, refundAmount @@ -482,6 +545,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = paymentSessionData.id try { + // assuming you have a client that retrieves the payment return await this.client.retrieve(externalId) } catch (e) { return { @@ -533,6 +597,7 @@ class MyPaymentProviderService extends AbstractPaymentProvider< const externalId = data.id try { + // assuming you have a client that updates the payment const response = await this.client.update( externalId, { @@ -707,4 +772,4 @@ Then, go through checkout to place an order. Your payment provider is used to au ## Useful Guides -- [Storefront Guide: how to implement UI for your payment provider during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment) +- [Storefront Guide: how to implement UI for your payment provider during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/payment) diff --git a/www/utils/generated/typedoc-json-output/payment-provider.json b/www/utils/generated/typedoc-json-output/payment-provider.json index ffbc9f7e7acdc..7e291370bf1d6 100644 --- a/www/utils/generated/typedoc-json-output/payment-provider.json +++ b/www/utils/generated/typedoc-json-output/payment-provider.json @@ -1,12 +1,12 @@ { - "id": 41499, + "id": 0, "name": "payment-provider", "variant": "project", "kind": 1, "flags": {}, "children": [ { - "id": 41503, + "id": 4, "name": "AbstractPaymentProvider", "variant": "declaration", "kind": 128, @@ -15,7 +15,7 @@ }, "children": [ { - "id": 41504, + "id": 5, "name": "validateOptions", "variant": "declaration", "kind": 2048, @@ -24,7 +24,7 @@ }, "signatures": [ { - "id": 41505, + "id": 6, "name": "validateOptions", "variant": "signature", "kind": 4096, @@ -58,7 +58,7 @@ }, "parameters": [ { - "id": 41506, + "id": 7, "name": "options", "variant": "param", "kind": 32768, @@ -100,7 +100,7 @@ ] }, { - "id": 41512, + "id": 13, "name": "constructor", "variant": "declaration", "kind": 512, @@ -109,7 +109,7 @@ }, "signatures": [ { - "id": 41513, + "id": 14, "name": "AbstractPaymentProvider", "variant": "signature", "kind": 16384, @@ -118,15 +118,7 @@ "summary": [ { "kind": "text", - "text": "You can use the " - }, - { - "kind": "code", - "text": "`constructor`" - }, - { - "kind": "text", - "text": " of the provider's service to access resources in your module's container.\n\nYou can also use the constructor to initialize your integration with the third-party provider. For example, if you use a client to connect to the third-party provider’s APIs,\nyou can initialize it in the constructor and use it in other methods in the service.\n\nThe provider can also access the module's options as a second parameter." + "text": "The constructor allows you to access resources from the [module's container](https://docs.medusajs.com/learn/fundamentals/modules/container) \nusing the first parameter, and the module's options using the second parameter.\n\n:::note\n\nA module's options are passed when you register it in the Medusa application.\n\n:::" } ], "blockTags": [ @@ -135,7 +127,7 @@ "content": [ { "kind": "code", - "text": "```ts\nimport {\n AbstractPaymentProvider\n} from \"@medusajs/framework/utils\"\nimport { Logger } from \"@medusajs/framework/types\"\n\ntype InjectedDependencies = {\n logger: Logger\n}\n\ntype Options = {\n apiKey: string\n}\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n static identifier = \"my-payment\"\n protected logger_: Logger\n protected options_: Options\n // Assuming you're using a client to integrate\n // with a third-party service\n protected client\n\n constructor(\n { logger }: InjectedDependencies,\n options: Options\n ) {\n // @ts-ignore\n super(...arguments)\n\n this.logger_ = logger\n this.options_ = options\n\n // Assuming you're initializing a client\n this.client = new Client(options)\n }\n\n // ...\n}\n\nexport default MyPaymentProviderService\n```" + "text": "```ts\nimport { AbstractPaymentProvider } from \"@medusajs/framework/utils\"\nimport { Logger } from \"@medusajs/framework/types\"\n\ntype Options = {\n apiKey: string\n}\n\ntype InjectedDependencies = {\n logger: Logger\n}\n\nclass MyPaymentProviderService extends AbstractPaymentProvider {\n protected logger_: Logger\n protected options_: Options\n // assuming you're initializing a client\n protected client\n\n constructor(\n container: InjectedDependencies,\n options: Options\n ) {\n super(container, options)\n\n this.logger_ = container.logger\n this.options_ = options\n\n // TODO initialize your client\n }\n // ...\n}\n\nexport default MyPaymentProviderService\n```" } ] } @@ -143,11 +135,19 @@ }, "typeParameters": [ { - "id": 41514, + "id": 15, "name": "TConfig", "variant": "typeParam", "kind": 131072, "flags": {}, + "comment": { + "summary": [ + { + "kind": "text", + "text": "The type of the provider's options passed as a second parameter." + } + ] + }, "default": { "type": "reference", "target": { @@ -171,7 +171,7 @@ ], "parameters": [ { - "id": 41515, + "id": 16, "name": "cradle", "variant": "param", "kind": 32768, @@ -207,11 +207,11 @@ ], "type": { "type": "reference", - "target": 41503, + "target": 4, "typeArguments": [ { "type": "reference", - "target": 41514, + "target": 15, "name": "TConfig", "package": "@medusajs/utils", "qualifiedName": "AbstractPaymentProvider.TConfig", @@ -225,7 +225,7 @@ ] }, { - "id": 41511, + "id": 12, "name": "identifier", "variant": "declaration", "kind": 1024, @@ -290,7 +290,7 @@ } }, { - "id": 41521, + "id": 22, "name": "capturePayment", "variant": "declaration", "kind": 2048, @@ -299,7 +299,7 @@ }, "signatures": [ { - "id": 41522, + "id": 23, "name": "capturePayment", "variant": "signature", "kind": 4096, @@ -314,7 +314,7 @@ "kind": "inline-tag", "tag": "@link", "text": "authorizePayment", - "target": 41524 + "target": 25 }, { "kind": "text", @@ -352,7 +352,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async capturePayment(\n paymentData: Record\n ): Promise {\n const externalId = paymentData.id\n\n try {\n const newData = await this.client.capturePayment(externalId)\n\n return {\n ...newData,\n id: externalId\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async capturePayment(\n paymentData: Record\n ): Promise {\n const externalId = paymentData.id\n\n try {\n // assuming you have a client that captures the payment\n const newData = await this.client.capturePayment(externalId)\n\n return {\n ...newData,\n id: externalId\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -360,7 +360,7 @@ }, "parameters": [ { - "id": 41523, + "id": 24, "name": "paymentData", "variant": "param", "kind": 32768, @@ -460,7 +460,7 @@ } }, { - "id": 41524, + "id": 25, "name": "authorizePayment", "variant": "declaration", "kind": 2048, @@ -469,7 +469,7 @@ }, "signatures": [ { - "id": 41525, + "id": 26, "name": "authorizePayment", "variant": "signature", "kind": 4096, @@ -484,7 +484,7 @@ "kind": "inline-tag", "tag": "@link", "text": "capturePayment", - "target": 41521 + "target": 22 }, { "kind": "text", @@ -530,7 +530,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n PaymentSessionStatus\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async authorizePayment(\n paymentSessionData: Record,\n context: Record\n ): Promise<\n PaymentProviderError | {\n status: PaymentSessionStatus\n data: PaymentProviderSessionResponse[\"data\"]\n }\n > {\n const externalId = paymentSessionData.id\n\n try {\n const paymentData = await this.client.authorizePayment(externalId)\n\n return {\n data: {\n ...paymentData,\n id: externalId\n },\n status: \"authorized\"\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n PaymentSessionStatus\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async authorizePayment(\n paymentSessionData: Record,\n context: Record\n ): Promise<\n PaymentProviderError | {\n status: PaymentSessionStatus\n data: PaymentProviderSessionResponse[\"data\"]\n }\n > {\n const externalId = paymentSessionData.id\n\n try {\n // assuming you have a client that authorizes the payment\n const paymentData = await this.client.authorizePayment(externalId)\n\n return {\n data: {\n ...paymentData,\n id: externalId\n },\n status: \"authorized\"\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -538,7 +538,7 @@ }, "parameters": [ { - "id": 41526, + "id": 27, "name": "paymentSessionData", "variant": "param", "kind": 32768, @@ -580,7 +580,7 @@ } }, { - "id": 41527, + "id": 28, "name": "context", "variant": "param", "kind": 32768, @@ -644,14 +644,14 @@ { "type": "reflection", "declaration": { - "id": 41528, + "id": 29, "name": "__type", "variant": "declaration", "kind": 65536, "flags": {}, "children": [ { - "id": 41529, + "id": 30, "name": "status", "variant": "declaration", "kind": 1024, @@ -675,7 +675,7 @@ } }, { - "id": 41530, + "id": 31, "name": "data", "variant": "declaration", "kind": 1024, @@ -721,8 +721,8 @@ { "title": "Properties", "children": [ - 41529, - 41530 + 30, + 31 ] } ] @@ -748,7 +748,7 @@ } }, { - "id": 41531, + "id": 32, "name": "cancelPayment", "variant": "declaration", "kind": 2048, @@ -757,7 +757,7 @@ }, "signatures": [ { - "id": 41532, + "id": 33, "name": "cancelPayment", "variant": "signature", "kind": 4096, @@ -784,7 +784,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async cancelPayment(\n paymentData: Record\n ): Promise {\n const externalId = paymentData.id\n\n try {\n const paymentData = await this.client.cancelPayment(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async cancelPayment(\n paymentData: Record\n ): Promise {\n const externalId = paymentData.id\n\n try {\n // assuming you have a client that cancels the payment\n const paymentData = await this.client.cancelPayment(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -792,7 +792,7 @@ }, "parameters": [ { - "id": 41533, + "id": 34, "name": "paymentData", "variant": "param", "kind": 32768, @@ -892,7 +892,7 @@ } }, { - "id": 41534, + "id": 35, "name": "initiatePayment", "variant": "declaration", "kind": 2048, @@ -901,7 +901,7 @@ }, "signatures": [ { - "id": 41535, + "id": 36, "name": "initiatePayment", "variant": "signature", "kind": 4096, @@ -944,7 +944,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async initiatePayment(\n context: CreatePaymentProviderSession\n ): Promise {\n const {\n amount,\n currency_code,\n context: customerDetails\n } = context\n\n try {\n const response = await this.client.init(\n amount, currency_code, customerDetails\n )\n\n return {\n ...response,\n data: {\n id: response.id\n }\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async initiatePayment(\n context: CreatePaymentProviderSession\n ): Promise {\n const {\n amount,\n currency_code,\n context: customerDetails\n } = context\n\n try {\n // assuming you have a client that initializes the payment\n const response = await this.client.init(\n amount, currency_code, customerDetails\n )\n\n return {\n ...response,\n data: {\n id: response.id\n }\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -952,7 +952,7 @@ }, "parameters": [ { - "id": 41536, + "id": 37, "name": "context", "variant": "param", "kind": 32768, @@ -1024,7 +1024,7 @@ } }, { - "id": 41537, + "id": 38, "name": "deletePayment", "variant": "declaration", "kind": 2048, @@ -1033,7 +1033,7 @@ }, "signatures": [ { - "id": 41538, + "id": 39, "name": "deletePayment", "variant": "signature", "kind": 4096, @@ -1060,7 +1060,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async deletePayment(\n paymentSessionData: Record\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentSessionData.id\n\n try {\n await this.client.cancelPayment(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async deletePayment(\n paymentSessionData: Record\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentSessionData.id\n\n try {\n // assuming you have a client that cancels the payment\n await this.client.cancelPayment(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -1068,7 +1068,7 @@ }, "parameters": [ { - "id": 41539, + "id": 40, "name": "paymentSessionData", "variant": "param", "kind": 32768, @@ -1168,7 +1168,7 @@ } }, { - "id": 41540, + "id": 41, "name": "getPaymentStatus", "variant": "declaration", "kind": 2048, @@ -1177,7 +1177,7 @@ }, "signatures": [ { - "id": 41541, + "id": 42, "name": "getPaymentStatus", "variant": "signature", "kind": 4096, @@ -1204,7 +1204,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentSessionStatus\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async getPaymentStatus(\n paymentSessionData: Record\n ): Promise {\n const externalId = paymentSessionData.id\n\n try {\n const status = await this.client.getStatus(externalId)\n\n switch (status) {\n case \"requires_capture\":\n return \"authorized\"\n case \"success\":\n return \"captured\"\n case \"canceled\":\n return \"canceled\"\n default:\n return \"pending\"\n }\n } catch (e) {\n return \"error\"\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentSessionStatus\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async getPaymentStatus(\n paymentSessionData: Record\n ): Promise {\n const externalId = paymentSessionData.id\n\n try {\n // assuming you have a client that retrieves the payment status\n const status = await this.client.getStatus(externalId)\n\n switch (status) {\n case \"requires_capture\":\n return \"authorized\"\n case \"success\":\n return \"captured\"\n case \"canceled\":\n return \"canceled\"\n default:\n return \"pending\"\n }\n } catch (e) {\n return \"error\"\n }\n }\n\n // ...\n}\n```" } ] } @@ -1212,7 +1212,7 @@ }, "parameters": [ { - "id": 41542, + "id": 43, "name": "paymentSessionData", "variant": "param", "kind": 32768, @@ -1288,7 +1288,7 @@ } }, { - "id": 41543, + "id": 44, "name": "refundPayment", "variant": "declaration", "kind": 2048, @@ -1297,7 +1297,7 @@ }, "signatures": [ { - "id": 41544, + "id": 45, "name": "refundPayment", "variant": "signature", "kind": 4096, @@ -1332,7 +1332,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async refundPayment(\n paymentData: Record,\n refundAmount: number\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentData.id\n\n try {\n const newData = await this.client.refund(\n externalId,\n refundAmount\n )\n\n return {\n ...newData,\n id: externalId\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async refundPayment(\n paymentData: Record,\n refundAmount: number\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentData.id\n\n try {\n // assuming you have a client that refunds the payment\n const newData = await this.client.refund(\n externalId,\n refundAmount\n )\n\n return {\n ...newData,\n id: externalId\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -1340,7 +1340,7 @@ }, "parameters": [ { - "id": 41545, + "id": 46, "name": "paymentData", "variant": "param", "kind": 32768, @@ -1382,7 +1382,7 @@ } }, { - "id": 41546, + "id": 47, "name": "refundAmount", "variant": "param", "kind": 32768, @@ -1459,7 +1459,7 @@ } }, { - "id": 41547, + "id": 48, "name": "retrievePayment", "variant": "declaration", "kind": 2048, @@ -1468,7 +1468,7 @@ }, "signatures": [ { - "id": 41548, + "id": 49, "name": "retrievePayment", "variant": "signature", "kind": 4096, @@ -1503,7 +1503,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async retrievePayment(\n paymentSessionData: Record\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentSessionData.id\n\n try {\n return await this.client.retrieve(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async retrievePayment(\n paymentSessionData: Record\n ): Promise<\n PaymentProviderError | PaymentProviderSessionResponse[\"data\"]\n > {\n const externalId = paymentSessionData.id\n\n try {\n // assuming you have a client that retrieves the payment\n return await this.client.retrieve(externalId)\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -1511,7 +1511,7 @@ }, "parameters": [ { - "id": 41549, + "id": 50, "name": "paymentSessionData", "variant": "param", "kind": 32768, @@ -1611,7 +1611,7 @@ } }, { - "id": 41550, + "id": 51, "name": "updatePayment", "variant": "declaration", "kind": 2048, @@ -1620,7 +1620,7 @@ }, "signatures": [ { - "id": 41551, + "id": 52, "name": "updatePayment", "variant": "signature", "kind": 4096, @@ -1635,7 +1635,7 @@ "kind": "inline-tag", "tag": "@link", "text": "initiatePayment", - "target": 41534 + "target": 35 }, { "kind": "text", @@ -1673,7 +1673,7 @@ "content": [ { "kind": "code", - "text": "```ts\n// other imports...\nimport {\n UpdatePaymentProviderSession,\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async updatePayment(\n context: UpdatePaymentProviderSession\n ): Promise {\n const {\n amount,\n currency_code,\n context: customerDetails,\n data\n } = context\n const externalId = data.id\n\n try {\n const response = await this.client.update(\n externalId,\n {\n amount,\n currency_code,\n customerDetails\n }\n )\n\n return {\n ...response,\n data: {\n id: response.id\n }\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" + "text": "```ts\n// other imports...\nimport {\n UpdatePaymentProviderSession,\n PaymentProviderError,\n PaymentProviderSessionResponse,\n} from \"@medusajs/framework/types\"\n\n\nclass MyPaymentProviderService extends AbstractPaymentProvider<\n Options\n> {\n async updatePayment(\n context: UpdatePaymentProviderSession\n ): Promise {\n const {\n amount,\n currency_code,\n context: customerDetails,\n data\n } = context\n const externalId = data.id\n\n try {\n // assuming you have a client that updates the payment\n const response = await this.client.update(\n externalId,\n {\n amount,\n currency_code,\n customerDetails\n }\n )\n\n return {\n ...response,\n data: {\n id: response.id\n }\n }\n } catch (e) {\n return {\n error: e,\n code: \"unknown\",\n detail: e\n }\n }\n }\n\n // ...\n}\n```" } ] } @@ -1681,7 +1681,7 @@ }, "parameters": [ { - "id": 41552, + "id": 53, "name": "context", "variant": "param", "kind": 32768, @@ -1753,7 +1753,7 @@ } }, { - "id": 41553, + "id": 54, "name": "getWebhookActionAndData", "variant": "declaration", "kind": 2048, @@ -1762,7 +1762,7 @@ }, "signatures": [ { - "id": 41554, + "id": 55, "name": "getWebhookActionAndData", "variant": "signature", "kind": 4096, @@ -1829,7 +1829,7 @@ }, "parameters": [ { - "id": 41555, + "id": 56, "name": "data", "variant": "param", "kind": 32768, @@ -1845,14 +1845,14 @@ "type": { "type": "reflection", "declaration": { - "id": 41556, + "id": 57, "name": "__type", "variant": "declaration", "kind": 65536, "flags": {}, "children": [ { - "id": 41557, + "id": 58, "name": "data", "variant": "declaration", "kind": 1024, @@ -1886,7 +1886,7 @@ } }, { - "id": 41558, + "id": 59, "name": "rawData", "variant": "declaration", "kind": 1024, @@ -1920,7 +1920,7 @@ } }, { - "id": 41559, + "id": 60, "name": "headers", "variant": "declaration", "kind": 1024, @@ -1958,9 +1958,9 @@ { "title": "Properties", "children": [ - 41557, - 41558, - 41559 + 58, + 59, + 60 ] } ] @@ -2006,35 +2006,35 @@ { "title": "Constructors", "children": [ - 41512 + 13 ] }, { "title": "Properties", "children": [ - 41511 + 12 ] }, { "title": "Methods", "children": [ - 41504, - 41521, - 41524, - 41531, - 41534, - 41537, - 41540, - 41543, - 41547, - 41550, - 41553 + 5, + 22, + 25, + 32, + 35, + 38, + 41, + 44, + 48, + 51, + 54 ] } ], "typeParameters": [ { - "id": 41560, + "id": 61, "name": "TConfig", "variant": "typeParam", "kind": 131072, @@ -2077,209 +2077,209 @@ { "title": "Classes", "children": [ - 41503 + 4 ] } ], "packageName": "@medusajs/utils", "symbolIdMap": { - "41499": { + "0": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "" }, - "41503": { + "4": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider" }, - "41504": { + "5": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.validateOptions" }, - "41505": { + "6": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.validateOptions" }, - "41506": { + "7": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "options" }, - "41511": { + "12": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.identifier" }, - "41512": { + "13": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.__constructor" }, - "41513": { + "14": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider" }, - "41514": { + "15": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.TConfig" }, - "41515": { + "16": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "cradle" }, - "41521": { + "22": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.capturePayment" }, - "41522": { + "23": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.capturePayment" }, - "41523": { + "24": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentData" }, - "41524": { + "25": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.authorizePayment" }, - "41525": { + "26": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.authorizePayment" }, - "41526": { + "27": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentSessionData" }, - "41527": { + "28": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "context" }, - "41528": { + "29": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "__type" }, - "41529": { + "30": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "__type.status" }, - "41530": { + "31": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "__type.data" }, - "41531": { + "32": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.cancelPayment" }, - "41532": { + "33": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.cancelPayment" }, - "41533": { + "34": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentData" }, - "41534": { + "35": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.initiatePayment" }, - "41535": { + "36": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.initiatePayment" }, - "41536": { + "37": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "context" }, - "41537": { + "38": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.deletePayment" }, - "41538": { + "39": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.deletePayment" }, - "41539": { + "40": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentSessionData" }, - "41540": { + "41": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.getPaymentStatus" }, - "41541": { + "42": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.getPaymentStatus" }, - "41542": { + "43": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentSessionData" }, - "41543": { + "44": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.refundPayment" }, - "41544": { + "45": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.refundPayment" }, - "41545": { + "46": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentData" }, - "41546": { + "47": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "refundAmount" }, - "41547": { + "48": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.retrievePayment" }, - "41548": { + "49": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.retrievePayment" }, - "41549": { + "50": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "paymentSessionData" }, - "41550": { + "51": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.updatePayment" }, - "41551": { + "52": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.updatePayment" }, - "41552": { + "53": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "context" }, - "41553": { + "54": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.getWebhookActionAndData" }, - "41554": { + "55": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.getWebhookActionAndData" }, - "41555": { + "56": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "data" }, - "41556": { + "57": { "sourceFileName": "../../../../packages/core/types/src/payment/mutations.ts", "qualifiedName": "__type" }, - "41557": { + "58": { "sourceFileName": "../../../../packages/core/types/src/payment/mutations.ts", "qualifiedName": "__type.data" }, - "41558": { + "59": { "sourceFileName": "../../../../packages/core/types/src/payment/mutations.ts", "qualifiedName": "__type.rawData" }, - "41559": { + "60": { "sourceFileName": "../../../../packages/core/types/src/payment/mutations.ts", "qualifiedName": "__type.headers" }, - "41560": { + "61": { "sourceFileName": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts", "qualifiedName": "AbstractPaymentProvider.TConfig" } @@ -2289,7 +2289,7 @@ "1": "../../../../packages/core/utils/src/payment/abstract-payment-provider.ts" }, "reflections": { - "1": 41499 + "1": 0 } } } diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/payment-provider.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/payment-provider.ts index 2d6227c828cbb..fb12b74c67078 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/payment-provider.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/payment-provider.ts @@ -13,9 +13,6 @@ const paymentProviderOptions: FormattingOptionsType = { reflectionTitle: { fullReplacement: "How to Create a Payment Provider", }, - reflectionGroups: { - Constructors: false, - }, shouldIncrementAfterStartSections: true, expandMembers: true, expandProperties: true, @@ -101,7 +98,7 @@ Then, go through checkout to place an order. Your payment provider is used to au `, `## Useful Guides -- [Storefront Guide: how to implement UI for your payment provider during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment) +- [Storefront Guide: how to implement UI for your payment provider during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/payment) `, ], },