-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom payment method registration (different state object) #3089
Comments
Also this bug can be ignored, if disable payment-backend-methods. Then, there are will no conflict with handling checkout-before-placeOrder event, and payment method code still will be taken from magento api. (Did not test this yet) |
Hi @Cheeerd thanks for the feedback! I belive it might be related to how “payment-backend-methods” module do insert the server methods it gets from Magento backend. It calls “replaceMethods” so it automatically de-registers all the methods that has been registered from code. It maybe should replace just the methods set by “is_server_method” set to true? I’m writhing this from my iPhone and can’t check how it exactly works :/ Anyway - that’s fact of the server and code based methods share the same code there will be the conflict and potentially a race condition. |
Another idea is that “replaceState” is being used after the “afterRegistration” hook from module was called. In that case the state would be replaced with the one that comes with INITIAL_STATE This can be checked in the client-entry.ts |
Yes, it is called after "afterRegistration" and replaces state with window.INITIAL_STATE. And i found that if i move payment/addMethod out of !isServer condition, custom methods (and cashondelivery) appear in INITIAL_STATE and start replacing payment-backend-methods. But there are also another issue with cashondelivery (but not with my custom method): if card is empty (user first time opens the site), the "servercartAfterCreated" action still loads methods from backend, and cashondelivery from backend overrides cashondelivery from module because of "!isVirtualCart || method.code !== 'cashondelivery'" condition. So cashondelivery's info block won't be shown. And also i wonder, is there are some way without changing core code or disabling payment-backend-methods to keep method's info (title) from magento, but use custom handler when placing order? And do not show custom method if it not available in magento and didn't come with backend methods. |
Yeah, the This is related to #2760 and #3024 - please feel free to share some proposal on payment api changes in the #3024 as well I think that we might have an config option like Please feel free to test these options and select one of them implementing a PR that will cover the problem you're facing. I belive it will be beneficial for all current and future users as well :) |
@Cheeerd have you maybe tried the solution with the |
@pkarw Sorry for late response. I tested it with cashondelivery method. It is used only in |
Current behavior
As described in docs/guide/integrations/payment-gateway.md and implemented in cash on delivery module, to register custom payment method we should dispatch payment/addMethod in afterRegistration hook.
Hovewer it appears that state object used on this step is different from one used after in checkout. So added by this way payment methods will be missed.
I think, it was the case why cash on delivery was static defined in node_modules/@vue-storefront/core/modules/checkout/store/payment/index.ts (#3054 )
Also that's why it was enough to me just remove static definition but keep module enabled when i wrote this: #2983
Can you handle fixing this bug by yourself?
I have to follow cashondelivery's static definition example to make custom method appear. But i'm not pretty familiar with architecture to fix the initial issue myself.
The text was updated successfully, but these errors were encountered: