Skip to content

Commit e83757d

Browse files
committed
chore(js-sdk): add methods to manage promotion codes
1 parent c7e799d commit e83757d

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.changeset/brave-suits-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/js-sdk": patch
3+
---
4+
5+
chore(js-sdk): add methods to manage promotion codes

packages/core/js-sdk/src/store/index.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,66 @@ export class Store {
750750
}
751751
)
752752
},
753+
754+
755+
/**
756+
* This method adds a promotion code to the current cart
757+
* The method sends a request to the [Add Promotion Code](https://docs.medusajs.com/api/store#carts_postcartsidpromotions) API route.
758+
*
759+
* @example
760+
* sdk.store.cart.addPromotionCodes("cart_123", {
761+
* promo_codes: ["20OFF"]
762+
* })
763+
* .then(({ cart }) => {
764+
* console.log(cart)
765+
* })
766+
*/
767+
addPromotionCodes: async (
768+
cartId: string,
769+
body: HttpTypes.StoreCartAddPromotion,
770+
query?: SelectParams,
771+
headers?: ClientHeaders
772+
) => {
773+
return this.client.fetch<HttpTypes.StoreCartResponse>(
774+
`/store/carts/${cartId}/promotions`,
775+
{
776+
method: "POST",
777+
headers,
778+
body,
779+
query,
780+
}
781+
)
782+
},
783+
784+
/**
785+
* This method removes promotion codes from the current cart
786+
* The method sends a request to the [Remove Promotion Code](https://docs.medusajs.com/api/store#carts_deletecartsidpromotions) API route.
787+
*
788+
* @example
789+
* sdk.store.cart.removePromotionCodes("cart_123", {
790+
* promo_codes: ["20OFF"]
791+
* })
792+
* .then(({ cart }) => {
793+
* console.log(cart)
794+
* })
795+
*/
796+
removePromotionCodes: async (
797+
cartId: string,
798+
body: HttpTypes.StoreCartRemovePromotion,
799+
query?: SelectParams,
800+
headers?: ClientHeaders
801+
) => {
802+
return this.client.fetch<HttpTypes.StoreCartResponse>(
803+
`/store/carts/${cartId}/promotions`,
804+
{
805+
method: "DELETE",
806+
headers,
807+
body,
808+
query,
809+
}
810+
)
811+
},
812+
753813
/**
754814
* This method completes a cart and places the order. It's the last step of the checkout flow.
755815
* The method sends a request to the [Complete Cart](https://docs.medusajs.com/api/store#carts_postcartsidcomplete)

0 commit comments

Comments
 (0)