Example #1
0
        public async Task <ActionResult> PayStackResponse(String trxref, String reference)
        {
            if (Session["PaystackDetails"] != null)
            {
                ViewBag.Status = false;

                try
                {
                    Logical.WriteToLog(((ProcessPayStackPayment)Session["PaystackDetails"]).PayStackReference);
                    ProcessPayStackPayment returnedBookingResponse = (ProcessPayStackPayment)Session["PaystackDetails"];

                    //starts here..
                    var bookingResult = await Logical.PostPayStackPayment(returnedBookingResponse);

                    var bookingResult_ = ((PostSearchResponseModel)Session["booking"]).Object;

                    if (bookingResult_.Response.ToLower() == "approved")
                    {
                        var payrefres = bookingResult.Item1.Object.BookingReferenceCode as string;
                        var success   = (bool)Session["success"];
                        //Session["queryRef"] = returnedBookingResponse.RefCode;
                        Session["queryRef"] = reference;
                        if (success == false)
                        {
                            Session["transactionDetails"] = bookingResult_;
                            Session["Errormsg"]           = "Transaction Failed";
                            // Response.Redirect("Payment-Error.aspx?Ref=" + returnedBookingResponse.RefCode + "&Errormsg=" + bookingResult.Item2.Message + "", false);
                            return(RedirectToAction("PaymentError"));
                        }
                        if (payrefres == null)
                        {
                            payrefres = "-";
                        }

                        Session["transactionDetails"] = bookingResult_;

                        return(RedirectToAction("PaymentConfirmation"));
                    }
                    else
                    {
                        var transactionDetails = confirmPayStackTransaction(reference);

                        Session["PayStackDetails"] = transactionDetails;

                        String bank = transactionDetails.Data.Authorization.Bank;

                        return(RedirectToAction("PaymentError"));
                    }
                }
                catch (Exception ex)
                {
                    Logical.WriteToLog(ex.Message + "::" + ex.StackTrace);

                    if ((bool)Session["Success"].Equals(true))
                    {
                        Session["queryRef"] = reference;

                        if (((PostSearchResponseModel)Session["booking"]).Object.Response.ToLower() == "approved")
                        {
                            ViewData["tranDetails"] = Session["transactionDetails"] as PostSearchResponseModel;
                            return(RedirectToAction("PaymentConfirmation"));
                        }
                        else
                        {
                            Session["Errormsg"] = ((PostSearchResponseModel)Session["booking"]).Object.Response;

                            return(RedirectToAction("PaymentError"));
                        }
                    }

                    return(RedirectToAction("PaymentError"));
                }
            }
            else
            {
                ViewBag.HireService = true;
                return(RedirectToAction("PaymentConfirmation"));
            }
        }
Example #2
0
        public static async Task <Tuple <PostHireResponseModel, ErrorModel> > PostHirePayStackPayment(ProcessPayStackPayment paystackpaymentopt)
        {
            using (HttpClientHelper client = new HttpClientHelper())
            {
                PostHireResponseModel bookobj    = new PostHireResponseModel();
                ErrorModel            errorModel = null;
                await client.ProcessClientRequestAsync <PostHireResponseModel>(GigUrl.ProcessHirePaystack + paystackpaymentopt.RefCode, HttpMethod.Get, paystackpaymentopt,
                                                                               success =>
                {
                    bookobj = success;
                },
                                                                               error =>
                {
                    errorModel = error;
                }
                                                                               );

                return(new Tuple <PostHireResponseModel, ErrorModel>(bookobj, errorModel));
            }
        }
        public async Task <JsonResult> PostHireBooking(GetHireRefcodeRequest hireRequest)
        {
            var response = await Logical.GetHireRefcode(hireRequest);

            IPayStackApi api = new PayStackApi("");
            TransactionInitializeRequest request = new TransactionInitializeRequest();

            Session["HireResponse_"] = response.Item1.Object;
            Session["HireRequest"]   = hireRequest;

            //HireRefCodeReturn call is successful  and payment method is paystack
            if (response.Item1.Code == "200" && hireRequest.PaymentMethod == "5")
            {
                try
                {
                    request.Email        = hireRequest.Email;
                    request.AmountInKobo = Convert.ToInt32(hireRequest.Amount) * 100;
                    // request.AmountInKobo = (int)Session["roundTripHire"] == 0 ? request.AmountInKobo : request.AmountInKobo * 2;
                    request.CallbackUrl = ConfigurationManager.AppSettings["PaystackResponse"];
                    request.MetadataObject["cancel_action"] = ConfigurationManager.AppSettings["PaystackResponse"];
                    request.Reference  = response.Item1.Object.RefCode;
                    request.SubAccount = ConfigurationManager.AppSettings["PaystackSubAccount"] ?? "";

                    var testOrLiveSecret = ConfigurationManager.AppSettings["PayStackSecret"];
                    api = new PayStackApi(testOrLiveSecret);


                    try
                    {
                        var payStackResponse = api.Transactions.Initialize(request);

                        if (payStackResponse.Status)
                        {
                            var PaystackDetails = new ProcessPayStackPayment
                            {
                                amount            = (int)request.AmountInKobo,
                                RefCode           = request.Reference,
                                PayStackReference = payStackResponse.Data.Reference,
                                email             = request.Email
                            };
                            Session["PaystackHireDetails"] = PaystackDetails;

                            Tuple <String, String, getHireRefcodeResponse> returnObject
                                = new Tuple <string, string, getHireRefcodeResponse>(payStackResponse.Data.AuthorizationUrl, "", response.Item1);

                            return(new JsonResult {
                                Data = returnObject
                            });
                        }
                        else
                        {
                            Tuple <String, String> returnObject = new Tuple <string, string>(String.Empty, "failed");
                            return(new JsonResult {
                                Data = returnObject
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        Logical.WriteToLog(ex.Message);


                        return(new JsonResult {
                            Data = new Tuple <String, String>("failed", ex.Message)
                        });
                    }
                }
                catch (Exception ex)
                {
                    return(new JsonResult {
                        Data = new Tuple <String, String>("failed", ex.Message)
                    });
                }


                //Tuple<String, String> returnObject = new Tuple<string, string>("", "");
            }
            else if (hireRequest.PaymentMethod == "12")
            {
                var buttonId = "BankTransfer";
                Session["PaymentGatewayType"] = 12;

                var returnUrl = "/Pages/BookOnHold?refCode=" + response.Item1.Object.RefCode + "&buttonId=" + buttonId;

                return(new JsonResult {
                    Data = returnUrl
                });
            }
            else if (!String.IsNullOrEmpty(response.Item1.Code) && response.Item1.Code != "200")
            {
                return(new JsonResult {
                    Data = new Tuple <String, String>("failed", response.Item1.ShortDescription)
                });
            }


            return(new JsonResult {
                Data = new Tuple <String, String>("failed", "Server error")
            });
        }
Example #4
0
        public static async Task <Tuple <PostSearchResponseModel, ErrorModel> > PostPayStackPayment(ProcessPayStackPayment paystackpaymentopt)
        {
            using (HttpClientHelper client = new HttpClientHelper())
            {
                PostSearchResponseModel bookobj = new PostSearchResponseModel();
                ErrorModel errorModel           = null;
                await client.ProcessClientRequestAsync <PostSearchResponseModel>(GigUrl.ProcessGigmsPayStack, HttpMethod.Post, paystackpaymentopt,
                                                                                 success =>
                {
                    bookobj = success;

                    if (success.Code.Equals("200"))
                    {
                        HttpContext.Current.Session["Success"] = true;

                        HttpContext.Current.Session["booking"] = success;
                    }
                    else
                    {
                        HttpContext.Current.Session["Success"] = false;
                    }
                },
                                                                                 error =>
                {
                    errorModel = error;
                    HttpContext.Current.Session["Success"] = false;
                }
                                                                                 );

                return(new Tuple <PostSearchResponseModel, ErrorModel>(bookobj, errorModel));
            }
        }
        public async Task <JsonResult> PostBooking(PostSearchModel booking)
        {
            Session["BookingRequest"] = booking;
            booking.Discount          = 0;
            var payStackUrl = String.Empty;

            try
            {
                if (booking.Beneficiaries == null)
                {
                    booking.Beneficiaries = new List <GigmsBookingBeneficiary>();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                booking.Beneficiaries = new List <GigmsBookingBeneficiary>();
            }

            var response = await Logical.PostSearchObjects(booking);

            if (!response.Item1.Code.Equals("200"))
            {
                return(new JsonResult {
                    Data = null
                });
            }


            Session["transactionDetails"] = response.Item1;
            var amount = Convert.ToInt64(booking.Amount) * 100;


            // var response = api.Transactions.Initialize(email, (int)amount);


            //Flutterwave
            if (booking.PaymentMethod.Equals(8))
            {
                Tuple <String, String, String> response_ = new Tuple <string, string, String>("", "", "");
                if (!String.IsNullOrEmpty(response.Item1.Object.BookingReferenceCode))
                {
                    var pubKey      = ConfigurationManager.AppSettings["FlutterWavePublicKey"];
                    var secKey      = ConfigurationManager.AppSettings["FlutterWaveSecretKey"];
                    var txref       = response.Item1.Object.BookingReferenceCode;
                    var redirectUrl = ConfigurationManager.AppSettings["FlutterWaveRedirect"] + txref;
                    //PBFPubKey.Text + amount.Text + "NG" + "NGN" + customer_email.Text + "card" + 1 + redirect_url.Text + txref.Text + secKey
                    var hash = _GetSha256Hash(pubKey + booking.Amount.Split(new String[] { "." }, StringSplitOptions.None)[0] + "NG" + "NGN" + booking.Email + "card" + 1 + redirectUrl + txref + secKey);

                    response_ = new Tuple <String, String, String>(response.Item1.Object.BookingReferenceCode, hash, redirectUrl);
                }

                return(new JsonResult {
                    Data = response_
                });
            }

            //Paystack
            else if (booking.PaymentMethod.Equals(5))
            {
                var request = new TransactionInitializeRequest();
                request.Email        = booking.Email;
                request.AmountInKobo = (int)amount;
                request.CallbackUrl  = ConfigurationManager.AppSettings["PaystackResponse"];
                request.MetadataObject["cancel_action"] = ConfigurationManager.AppSettings["PaystackResponse"];
                request.Reference  = response.Item1.Object.BookingReferenceCode;
                request.SubAccount = ConfigurationManager.AppSettings["PaystackSubAccount"] ?? "";

                var testOrLiveSecret = ConfigurationManager.AppSettings["PayStackSecret"];
                var api = new PayStackApi(testOrLiveSecret);

                try
                {
                    var payStackResponse = api.Transactions.Initialize(request);

                    if (payStackResponse.Status)
                    {
                        var PaystackDetails = new ProcessPayStackPayment
                        {
                            amount            = (int)amount,
                            RefCode           = request.Reference,
                            PayStackReference = payStackResponse.Data.Reference,
                            email             = request.Email
                        };
                        Session["PaystackDetails"] = PaystackDetails;
                        payStackUrl = payStackResponse.Data.AuthorizationUrl;

                        return(new JsonResult {
                            Data = payStackUrl
                        });
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = null
                        });
                    }
                }
                catch (Exception ex)
                {
                    Logical.WriteToLog(ex.Message);


                    return(new JsonResult {
                        Data = null
                    });
                }
            }

            else if (booking.PaymentMethod.Equals(12))
            {
                var buttonId = "lnkbtnGtbUssd";
                Session["PaymentGatewayType"] = 12;

                var returnUrl = "/Pages/BookOnHold?refCode=" + response.Item1.Object.BookingReferenceCode + "&buttonId=" + buttonId;

                return(new JsonResult {
                    Data = returnUrl
                });
            }
            else if (booking.PaymentMethod.Equals(7) || booking.PaymentMethod.Equals(10) || booking.PaymentMethod.Equals(12) ||
                     booking.PaymentMethod.Equals(14) || booking.PaymentMethod.Equals(16))
            {
                var buttonId = "ussd";
                Session["PaymentGatewayType"] = 0;

                var returnUrl = "/Pages/BookOnHold?refCode=" + response.Item1.Object.BookingReferenceCode + "&buttonId=" + buttonId;

                return(new JsonResult {
                    Data = returnUrl
                });
            }
            else
            {
                return(null);
            }
        }