Skip to content

Commit

Permalink
Merge pull request #133 from emigal/checkout_changes
Browse files Browse the repository at this point in the history
allow_promotion_codes flag
  • Loading branch information
chrisvdm authored Jan 12, 2024
2 parents 68efa3b + 650ea60 commit bf1469a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/src/services/checkouts/checkouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const createStripeCheckoutSession = async ({
mode,
cart,
successUrl = "http://localhost:8910/stripe-demo?success=true&sessionId={CHECKOUT_SESSION_ID}",
cancelUrl = "http://localhost:8910/stripe-demo?success=false"
cancelUrl = "http://localhost:8910/stripe-demo?success=false",
allowPromotionCodes = true
}) => {
const line_items = cart.map(product => ({
price: product.id,
Expand All @@ -35,6 +36,7 @@ export const createStripeCheckoutSession = async ({
line_items: line_items,
mode: mode,
payment_method_types: ['card'],
allow_promotion_codes: allowPromotionCodes,
... (Object.hasOwn(customer, "id") && { customer: customer.id })
}

Expand Down
6 changes: 4 additions & 2 deletions web/src/hooks/useStripeCheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export const useStripeCheckout = () => {
$cancelUrl: String
$customer: StripeCustomerInput
$mode: StripeCheckoutModeEnum
$allowPromotionCodes: Boolean
) {
checkout(cart: $cart, successUrl: $successUrl, cancelUrl: $cancelUrl, customer: $customer, mode: $mode) {
checkout(cart: $cart, successUrl: $successUrl, cancelUrl: $cancelUrl, customer: $customer, mode: $mode, allowPromotionCodes: $allowPromotionCodes) {
id
url
}
Expand All @@ -39,7 +40,7 @@ export const useStripeCheckout = () => {
`

return {
checkout: async ({ cart, customer, successUrl, cancelUrl, mode }) => {
checkout: async ({ cart, customer, successUrl, cancelUrl, mode, allowPromotionCodes }) => {
// customer = !!customer ? customer : (await context.waitForCustomer())
customer = customer || context.customer
cart = cart || context.cart
Expand All @@ -61,6 +62,7 @@ export const useStripeCheckout = () => {
successUrl: successUrl,
cancelUrl: cancelUrl,
mode: determinedMode,
allowPromotionCodes: allowPromotionCodes,
... (customer != null ? {
customer: {
id: customer.id,
Expand Down

0 comments on commit bf1469a

Please sign in to comment.