Skip to content

Commit 2285938

Browse files
docs: update example for calculatePrice to reflect the updated return value of type CalculatedShippingOptionPrice
1 parent f977cd6 commit 2285938

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

packages/core/utils/src/fulfillment/provider.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
/**
99
* ### constructor
1010
*
11-
* The constructor allows you to access resources from the [module's container](https://docs.medusajs.com/learn/fundamentals/modules/container)
11+
* The constructor allows you to access resources from the [module's container](https://docs.medusajs.com/learn/fundamentals/modules/container)
1212
* using the first parameter, and the module's options using the second parameter.
1313
*
1414
* :::note
@@ -48,7 +48,7 @@ import {
4848
*
4949
* this.logger_ = logger
5050
* this.options_ = options
51-
*
51+
*
5252
* // TODO initialize your client
5353
* }
5454
* }
@@ -96,7 +96,7 @@ export class AbstractFulfillmentProviderService
9696
* This method retrieves a list of fulfillment options that this provider supports. Admin users will then choose from these options when
9797
* they're creating a shipping option. The chosen fulfillment option's object is then stored within the created shipping option's `data` property.
9898
* The `data` property is useful to store data relevant for the third-party provider to later process the fulfillment.
99-
*
99+
*
100100
* This method is useful if your third-party provider allows you to retrieve support options, carriers, or services from an API. You can then
101101
* retrieve those and return then in the method, allowing the admin user to choose from the services provided by the third-party provider.
102102
*
@@ -112,7 +112,7 @@ export class AbstractFulfillmentProviderService
112112
* async getFulfillmentOptions(): Promise<FulfillmentOption[]> {
113113
* // assuming you have a client
114114
* const services = await this.client.getServices()
115-
*
115+
*
116116
* return services.map((service) => ({
117117
* id: service.service_id,
118118
* name: service.name,
@@ -190,7 +190,7 @@ export class AbstractFulfillmentProviderService
190190
/**
191191
* This method validates whether a shippin option's price can be calculated during checkout. It's executed when the admin user creates a shipping
192192
* option of type `calculated`. If this method returns `false`, an error is thrown as the shipping option's price can't be calculated.
193-
*
193+
*
194194
* You can perform the checking using the third-party provider if applicable. The `data` parameter will hold the shipping option's `data` property, which
195195
* includes the data of a fulfillment option returned by {@link getFulfillmentOptions}.
196196
*
@@ -231,11 +231,19 @@ export class AbstractFulfillmentProviderService
231231
* @example
232232
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
233233
* // ...
234-
* async calculatePrice(optionData: any, data: any, context: any): Promise<number> {
234+
* async calculatePrice(
235+
optionData: Record<string, unknown>,
236+
data: Record<string, unknown>,
237+
context: any
238+
): Promise<CalculatedShippingOptionPrice> {
235239
* // assuming the client can calculate the price using
236240
* // the third-party service
237241
* const price = await this.client.calculate(data)
238-
* return price
242+
* return {
243+
* calculated_amount: price,
244+
* is_calculated_price_tax_inclusive: true,
245+
* // Update this boolean value based on your logic
246+
* }
239247
* }
240248
* }
241249
*/
@@ -346,7 +354,7 @@ export class AbstractFulfillmentProviderService
346354
* `data` property, it's stored in the fulfillment's `data` property.
347355
*
348356
* The `data` property is useful when handling the fulfillment later,
349-
* as you can access information useful for your integration. For example, you
357+
* as you can access information useful for your integration. For example, you
350358
* can store an ID for the fulfillment in the third-party service.
351359
*
352360
* Use this method to perform actions necessary in the third-party fulfillment service, such as

0 commit comments

Comments
 (0)