how do i change payment status and Order status after redirect from external gateway

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
hi
in EnterPaymentInfo of CheckoutController instead of getting user information, i redirect user to external gateway using webservice  
web services have following method for check payment information  
public int PaymentRequest(string MerchantID, int Amount, string Description, string Email, string Mobile, string CallbackURL, out string Authority)  

PaymentRequest method return integer value and i check this value and redirect user to gateway
after redirection and do payment user come back to website using CallbackURL parameter ,i redirect user to Confirm action method
redirect url have QueryString
i check QueryString in Confirm action method using PaymentVerification method
public int PaymentVerification(string MerchantID, string Authority, int Amount, out long RefID)

this method also return  status code  
now i want check if status code is 100 , update order status and payment status

can i o this without payment plugin??
how can i access and update  order ,Payment  and shipping status in action methods of CheckoutController??
6 years ago
Anyone can answer my question?
Nobody??
6 years ago
Hi

The correct way to do this is with a payment plugin (Redirection Payment Method Type, of course) but any ways, you need to use OrderProcessingService for do this.

To use this you can inject the service (IOrderProcessingSerice) in the contructor method of the class and then you just use MarkOrderAsPaid method of that class



public class any
{
    . . .
    private readonly IOrderProcessingService _orderProcessingService;
    . . .

    public any(IOrderProcessingService _orderProcessingService)
    {
        this._orderProcessingService = orderProcessingService;
    }

    //To Use

    public void anymethod()
    {
     [. . .]

     _orderProcessingService.MarkOrderAsPaid(order);

     [. . .]
    }
}



I hope this help you.
6 years ago
But howcan i call PostPaymentProcess of plugin in checkout controller?
6 years ago
[email protected] wrote:
But howcan i call PostPaymentProcess of plugin in checkout controller?


you dont need it, PostProcessPayment is called by IPaymentService after "Place order" process (ConfirmOrder method). this service call the PosPaymentProcess method (that you implements in your plugin).

If you do a Payment Plugin you DONT need change ANY line of  NopBase source code.
6 years ago
so how it find out that payment is successful or not??
6 years ago
here is my PostProcessPayment

public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            try
            {
                ServicePointManager.Expect100Continue = false;
                PaymentGatewayImplementationServicePortTypeClient gateWay = new PaymentGatewayImplementationServicePortTypeClient();
                string Authority;
              
                int _orderTotal = decimal.ToInt32(postProcessPaymentRequest.Order.OrderTotal);
                string billingPhoneNumber = postProcessPaymentRequest.Order.BillingAddress.PhoneNumber;
                var Email = postProcessPaymentRequest.Order.BillingAddress.Email;
                string CallBackURL = GetCallBackURL(); // return  return Url.Action("Completed", "Checkout", new { orderId = System.Web.Mvc.UrlParameter.Optional }, "http");
                int Status = gateWay.PaymentRequest("MerchantID", _orderTotal, "User Order Description", Email, billingPhoneNumber, CallBackURL , out Authority);

                if (Status == 100)
                {
                    _httpContext.Response.Redirect("https://www.mygateway.com/pg/StartPay/" + Authority);
                }
                else
                {
                    _httpContext.Response.Write("error: " + Status);
                }
            }
            catch(Exception exc)
            {
                _httpContext.Response.Write(exc.ToString());
            }


        }

i send my payment info to gateway and it return me status code that indicate gateway info is correct
after that if status code is 100 everthing is ok and user redirect to gateway
after payment (pay or not pay) user return to CallBackURL  parameter of PaymentRequest
gateway add query string to CallBackURL  and i should  parse query string

var _t = _orderTotalCalculationService.GetShoppingCartTotal(cart);
            int Total = (int)_t;
            if (Request.QueryString["Status"] != "" && Request.QueryString["Status"] != null && Request.QueryString["Authority"] != "" && Request.QueryString["Authority"] != null)
            {
                if (Request.QueryString["Status"].ToString().Equals("OK"))
                {

                    long RefID;
                    System.Net.ServicePointManager.Expect100Continue = false;
                    PaymentGatewayImplementationServicePortTypeClient gateway = new PaymentGatewayImplementationServicePortTypeClient();

                    int Status = gateway.PaymentVerification("MerchantID", Request.QueryString["Authority"].ToString(), Total, out RefID);

                    if (Status == 100)
                    {
                      
                        _httpContext.Session["OrderPaymentResult"] = "Success!! RefId: " + RefID;

                        
                    }
                    else
                    {
                        _httpContext.Session["OrderPaymentResult"] = "Error!! Status: " + Status;
                      
                    }

                }
                else
                {
                    _httpContext.Session["OrderPaymentResult"] = "Error! Authority: " + Request.QueryString["Authority"].ToString() + " Status: " + Request.QueryString["Status"].ToString();
                  
                }
            }
            else
            {
                _httpContext.Session["OrderPaymentResult"] = "Invalid Input";
                
            }

so i don't know where should i put above code and how mark order as paid or not paid
6 years ago
Oh! OK... Lets see.

First you need send to Payment service the GUID of your order and when the you recive a response of your payment service to your CallBackURL, you can know for what order is the response is being received


when you recive a request in your callback URL you need process this payment. if the firs request have a payment response you dont need do an other request to check the status. when you have a payment status you only need get an order with IOrderService implementation (use method GetOrderByGuid) and then you only use IOrderProcessingService to mark order as payment)

You can check the Source code of Pyapal Standard Plugin (Nop.Plugin.Payments.PayPalStandard) to see a implementation of this


PS: I would put this


!String.IsNullOrWhiteSpace((Request.QueryString["Status"])


instead of


Request.QueryString["Status"] != "" && Request.QueryString["Status"] != null


it's most fancy to me ;D
6 years ago
Tnx
But what is correct callBacUrl??
Can you provide me more code/detail??
6 years ago
[email protected] wrote:
Tnx
But what is correct callBacUrl??
Can you provide me more code/detail??


Firs you need add a method in your controller, in this method you control your CallBack requests. On Paypal plugin this method call PDTHandler.

then you need implement an IRouteProvider to register a new URL (see source code of PayPalStandard plugin > RouteProvider class).

And that's it all! Now you have a callbak URL and when your payment service will do a request to this URL you can process the answer (in this case you can register or not the payment)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.