NopCommerce 4.6 Payment plugin

2 weeks ago
Hello everyone,
I've created a payment plugin in nop 4.6. I need to check permission to access and show payment gateway to customer in order checkout. (When loading active payment plugins). where do you recommend I check it? ( I have to calll a methd from api and it returns a JWT if the order is eligible).
2 weeks ago
Hi
Please put the logic at HidePaymentMethodAsync method. This method is part of the IPaymentMethod interface. If this method returns true, the payment option will be shown in the payment method selection at the checkout, else it will be hidden.

Note that the order ID is not created/available as the order has not been placed yet when preparing the payment options, so you can't use the order ID as the parameter for your API. You can pass the cart items and the customer details as parameters to the API if that works for your use case.
2 weeks ago
I used this method,"HidePaymentMethodAsync "
But I have a problem, It will be called in every step of shopping cart until the end. Because I'm calling an API method and getting a JWT for the order I have to call this method just once in checkout, just befor showwing payment methods and after shopping cart is completed, includes shipping amount.
2 weeks ago
1. You can use the OrderPlaced event and send the information via API when the order is placed.
i.e. you can create a class and implement the interface to consume the order placed event IConsumer<OrderPlacedEvent>

2. In this case you may need to override the PreparePaymentMethodModelAsync from the CheckoutModelFactory and add the check after all the payment methods are loaded and validate the methods over there. I think this method will be called only once while preparing the payment options at the checkout
2 weeks ago
sanju.dahal741 wrote:
1. You can use the OrderPlaced event and send the information via API when the order is placed.
i.e. you can create a class and implement the interface to consume the order placed event IConsumer<OrderPlacedEvent>

2. In this case you may need to override the PreparePaymentMethodModelAsync from the CheckoutModelFactory and add the check after all the payment methods are loaded and validate the methods over there. I think this method will be called only once while preparing the payment options at the checkout



It's helpful and I think you solved my problem but According to this, there is no way to prevent changing code in nop core. It would be better if I could do this just in plugin  and I could use this payment plugin for other projects without  any needs to change anything else.

Thank you Mr sanju, you help me all the time!
2 weeks ago
You're welcome!
Plus, you don't have to change the code at the core, you can simply override the PreparePaymentMethodModelAsync method from the plugin as it is a virtual method and can be overridden
1 week ago
sanju.dahal741 wrote:
You're welcome!
Plus, you don't have to change the code at the core, you can simply override the PreparePaymentMethodModelAsync method from the plugin as it is a virtual method and can be overridden


Thanks. I think, my plugin is completed finally!

Just I notice something, in order manager(admin) when I add a new Item to order items, It ignores quantity of seleted item. So total amount is not correct, there is something that I'v forgotten to set?
2 days ago
Hi Team,

We have created a custom attribute to store custrefno given by payment gateway in their response.
I want to update custom attribute in customer  from the my payment plugin, how do I update it?

Use case is to update the additionalcustrefno given by payment gateway and if the referenceno exists we need to pass this number second time onwards which will help them to display  saved cards and enable fast payments.

Best Regards
2 hours ago
For that, you must make certain adjustments to your payment plugin.