Skip to content

Commit

Permalink
Merge pull request #2277 from graphcommerce-org/fix/braintree2
Browse files Browse the repository at this point in the history
Solve issue where Braintree wouldn't place the order after successfully validating a Credit Card.
  • Loading branch information
paales authored May 22, 2024
2 parents d58ac9d + f9199f7 commit 5c83493
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/eight-keys-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphcommerce/magento-cart-payment-method": patch
"@graphcommerce/magento-payment-braintree": patch
---

Solve issue where Braintree wouldn't place the order after successfully validating a Credit Card.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
if (!result.data?.placeOrder?.order) return
await onSuccess(result.data.placeOrder.order.order_number)
},
submitWhileLocked: true,
})

const { handleSubmit } = form
Expand Down
8 changes: 6 additions & 2 deletions packages/magento-cart/hooks/useFormGqlMutationCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useFormGqlMutationCart<
V extends { cartId: string; [index: string]: unknown },
>(
document: TypedDocumentNode<Q, V>,
options: UseFormGraphQlOptions<Q, V> = {},
options: UseFormGraphQlOptions<Q, V> & { submitWhileLocked?: boolean } = {},
operationOptions?: MutationHookOptions<Q, V>,
): UseFormGqlMutationReturn<Q, V> {
const cartId = useCartIdCreate()
Expand All @@ -26,7 +26,11 @@ export function useFormGqlMutationCart<
const vars = { ...variables, cartId: await cartId() }

const res = client.cache.readQuery({ query: CurrentCartIdDocument })
if (res?.currentCartId?.locked) return false
if (!options.submitWhileLocked && res?.currentCartId?.locked) {
console.log('Could not submit form, cart is locked', res.currentCartId.locked)
return false
}

return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars
},
},
Expand Down
6 changes: 2 additions & 4 deletions packages/magento-payment-braintree/methods/braintree/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
PaymentMethodPlaceOrderNoop,
PaymentModule,
} from '@graphcommerce/magento-cart-payment-method'
import type { PaymentModule } from '@graphcommerce/magento-cart-payment-method'
import { PaymentMethodPlaceOrderNoop } from '@graphcommerce/magento-cart-payment-method/PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop'
import { PaymentMethodOptions } from './PaymentMethodOptions'

export const braintree: PaymentModule = {
Expand Down

0 comments on commit 5c83493

Please sign in to comment.