Management of notifications in the nopcommerce plugin - plugins

I develop a plugin on nopcommerce 3.8 and I'm almost at the end. This plugin is the payment plugin and allows to redirect users to a page of a bank to pay the order.
My problem now is to manage the various messages (notifications) that the user will see on our site once an operation has been completed. The transaction may be, payment successful, payment failure, insufficient money in the account, cancellation of payment, etc.
For this, for each operation we must notify the user on our site. For example, after the cancellation of the payment the user is redirected again on our site (Page Index) and we want to show him a message (notification) to tell him that: "You have just canceled your order". In the code of our plugin we have provided the Notify method of our controller which will process the result of each operation. So it is in this method that we want to manage the display of notifications. Here is the beginning of our method.
public ActionResult Notify(WariWebResponse response)
{
//My implementation here
return RedirectToAction("Index","Home",new { area="" });
}

Related

Upgrading PayPal payment to Orders API, the testing account didn't receive any money after finish the payment

I'm trying to implement the new PayPal Orders API, here is what I did:
Create a developer account, add an app name and then I have Client Id and Secret.
Use OrderCreateRequest to create an Order
Get approvel_url from the resposne->result->links
Redirect to this approvel_url and finish the payment
Paypal will redirect back to my website.
But I never got any thing from the PayPal testing account,Please, what did I miss?
Edit:
On No.4, when redirects to the PayPal page, somehow it only shows 'Continue' button on the page, not the 'make payment' button.
You are missing:
Display an order review page to the payer.
Capture the order with an API call, which (if successful) will return the transaction ID in the purchase_units[0].payments.captures[0] object.
On success, display a thank you/confirmation page.
Without the final capture API call, there is no PayPal transaction.
You are also still using an old integration method based on redirects, which is for old websites. Current PayPal Checkout integrations use no redirects. At all.
Instead of redirecting, make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). When a capture response is successful, store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) right before sending your return JSON.
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Process PayPal payments lead to Payer has not approved payment error

I have implemented PayPal payment described here
https://developer.paypal.com/docs/api/quickstart/payments/ with provided Java SDK which use API /v1/payments
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>rest-api-sdk</artifactId>
<version>1.14.0</version>
</dependency>
Step1 : Create payment as describe in above link and it will create payment at PayPal and we got approval_url which is shared to customer to complete payment.
Step2 : There is a webhook listener for only one event there
Step3 : when my application receives that event from PayPal then it executes payment as described in above link
This is working for most of the payment case, but few payments, during payment execution following error get occurred.
{"name":"PAYMENT_NOT_APPROVED_FOR_EXECUTION","message":"Payer has not approved payment","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"8c19669326adc"}
Now, this is not clean what is different between payment which lead to successful execution and other which lead to failure with "Payer has not approved payment" message. And what should be done to solve issue here?
When an old deprecated API v1/payment (or with the current API, a v2/checkout/order) is created, it is in an unapproved state. For it to be executable (or with v2, capturable) a payer must log into a checkout and approve it.
If no one logs in and approves a payment, it remains in an unapproved state.
When you attempt to 'execute' a payment (or with the current v2/checkout/orders API, 'capture' an order) that has not been approved by a payer, you will receive an error message stating that the payment has not been approved.
You can only execute payments (or capture orders) that have been approved.
For best results, use the current v2/checkout API with an in-context approval flow. Make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). When a capture response is successful, store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) before sending your return JSON.
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

cancel paypal subscription from my cart

as stated here: Detecting Paypal Subscription Cancellation api can be used to detect a paypal subscription cancellation. what about the opposite? using magento, i have code that creates the paypal subscription but when i cancel the subscription (in the cart), the cancellation is not passed to paypal and i must then go to paypal to cancel.
it would be great to avoid the extra step of double canceling and just only have to cancel from my cart (as admin and as customer via api sent to paypal)
You can use the ManageRecurringPaymentsProfileStatus API to cancel "I-" profiles. As far as if Magento supports this, or if there is a plugin that you can use I don't know of one off hand. However, it is possible. All that needs to happen is that your cart just needs to make API call.

What if the user doesn't get redirected after PayPal payment?

After adding stuff in shopping cart, clicking some Pay Now with PayPal button, and successful PayPal payment (PP or CC), it is logically possible that a user stays on PayPal website, if for example the Auto Return option isn't activated (or it is but it doesn't work because the user is a guest user without PP account)
The user can return to the site by clicking a link, but doesn't have to. My question is: if he doesn't, how will the site owner be aware that the user paid so that he can now send the items by post? That the site owner gets informed of being paid seems elemental to me, so I find incomprehensible that such elemental thing be left to some obscure Auto-Return option.
Please can somebody explain this to me?
This is a common challenge with any redirected payment gateway, and it's the reason most (if not all) of them implement some sort of asynchronous notification that a payment has been completed. In PayPal, this is the Instant Payment Notification (IPN). You must setup on your site either a generic IPN listener that you link to from your PayPal account profile settings or you can create a more targeted IPN listener specifically for your transactions and use the NOTIFYURL (or related) parameter in the form or API request you use to redirect to PayPal to send IPNs to that listener.
In my integrations, I never perform any order update or transaction logging when the customer returns from the site, preferring instead to wait for the IPN that I can validate and ensure came from PayPal as opposed to a spoofed return from someone trying to hack my checkout process.
For more information, see the IPN documentation: https://www.x.com/developers/paypal/documentation-tools/ipn/integration-guide/IPNIntro
Paypal provide IPN for this purpose through which we paypal send request asynchronous to your site and you can perform whichever action you want
I think the point may have been missed here. Or a problem does exist. If the purchaser uses CC, even if you have IPN set up and it works, but if the purchaser uses CC and does not click a button on the last page, which is not presented when using PP account, it is possible for the funds to go through, but no IPN, and so your website is unaware of the purchase. This last page, is an extra page that CC user gets after the page with the Pay button on it.
In this state, you can even go into IPN history, and the IPN is there, says it is sent, but it hasn't been. It does not get sent until after the purchaser clicks the button on the extra page and then they are taken to the auto return page.

Paypal Payment Standard: Callback URL

On Paypal Sandbox:
After logging in using a test account and then clicking the "Pay Now" button, the user is redirected to "Thanks for your order" page inside Paypal. The page has three(3) links below the message that says:
Return to Test Store
Go to PayPal account overview
Add funds from your bank
Clicking the "Return to Test Store" will redirect me to the return URL I specified on my query string. This marks the order as "Completed" or whatever the value of the payment_status returned by Paypal is.
The Problem:
Clicking the other links bypasses the return URL and goes to user account profile which leaves the order incomplete even if the transaction was successfully paid because the return URL has the script to mark the outcome of the transaction.
The Question:
Is there a way to bypass the Thank you page and just redirect to my return URL so the transaction can be concluded accordingly?
BTW, I have my Test Business Account set to autoredirect to the return URL after the order.
You want to read about PayPal's Instant Payment Notification and about Identifying Your IPN Listener to PayPal.
You have the option to be notified whenever a transaction takes place, regardless of what users clicks on. Paypal's servers will make requests to a Notification URL you provide and give you informations about that transaction.