Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Remove the need for the canMakePayment callback in the editor conte…
Browse files Browse the repository at this point in the history
…xt (#4188)

* Force can pay true in editor context

* Update docs
  • Loading branch information
mikejolley authored and grogou committed Aug 20, 2021
1 parent 90499cb commit 8ed63f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -103,11 +103,15 @@ const usePaymentMethodRegistration = (
continue;
}

// In front end, ask payment method if it should be available.
// See if payment method should be available. This always evaluates to true in the editor context.
try {
const canPay = await Promise.resolve(
paymentMethod.canMakePayment( canPayArgument.current )
);
const canPay = isEditor
? true
: await Promise.resolve(
paymentMethod.canMakePayment(
canPayArgument.current
)
);

if ( !! canPay ) {
if (
Expand Down
3 changes: 3 additions & 0 deletions docs/extensibility/payment-method-integration.md
Expand Up @@ -98,6 +98,9 @@ canMakePayment( {

Returns a boolean value - true if payment method is available for use. If your gateway needs to perform async initialization to determine availability, you can return a promise (resolving to boolean). This allows a payment method to be hidden based on the cart, e.g. if the cart has physical/shippable products (example: [`Cash on delivery`](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e089ae17043fa525e8397d605f0f470959f2ae95/assets/js/payment-method-extensions/payment-methods/cod/index.js#L48-L70)); or for payment methods to control whether they are available depending on other conditions.

`canMakePayment` only runs on the frontend of the Store. In editor context, rather than use `canMakePayment`, the editor will
assume the payment method is available (true) so that the defined `edit` component is shown to the merchant.

**Keep in mind this function could be invoked multiple times in the lifecycle of the checkout and thus any expensive logic in the callback provided on this property should be memoized.**

#### `paymentMethodId`
Expand Down

0 comments on commit 8ed63f7

Please sign in to comment.