Пример #1
0
        public ActionResult CreateOrder(Models.PaymentInitiateModel _requestData)
        {
            // Generate random receipt number for order
            Random randomObj     = new Random();
            string transactionId = randomObj.Next(10000000, 100000000).ToString();

            Razorpay.Api.RazorpayClient client  = new Razorpay.Api.RazorpayClient("rzp_test_umbrFAbVJ3slyJ", "su9eXFaihGucMmKECVRcRk0Q");
            Dictionary <string, object> options = new Dictionary <string, object>();

            options.Add("amount", _requestData.amount * 100);  // Amount will in paise
            options.Add("receipt", transactionId);
            options.Add("currency", "INR");
            options.Add("payment_capture", "0"); // 1 - automatic  , 0 - manual
                                                 //options.Add("notes", "-- You can put any notes here --");
            Razorpay.Api.Order orderResponse = client.Order.Create(options);
            string             orderId       = orderResponse["id"].ToString();

            // Create order model for return on view
            OrderModel orderModel = new OrderModel
            {
                orderId       = orderResponse.Attributes["id"],
                razorpayKey   = "rzp_test_umbrFAbVJ3slyJ",
                amount        = _requestData.amount * 100,
                currency      = "INR",
                name          = _requestData.name,
                email         = _requestData.email,
                contactNumber = _requestData.contactNumber,
                address       = _requestData.address,
                description   = "Testing description"
            };

            // Return on PaymentPage with Order data
            return(View("PaymentPage", orderModel));
        }
Пример #2
0
        public ActionResult Now(Models.PaymentInitiateModel requestData)
        {
            string transactionId = Randoms.Pattern("trans-{HEX:15}");

            Razorpay.Api.RazorpayClient client = new Razorpay.Api.RazorpayClient("rzp_test_DmK2S2Y4ATkGZz", "glz95rTDL8OE4kV3RsUo4UAj");

            Dictionary <string, object> options = new Dictionary <string, object>();

            options.Add("amount", int.Parse(requestData.amount) * 100);
            options.Add("receipt", transactionId);
            options.Add("currency", "INR");
            options.Add("payment_capture", "0");
            //options.Add("notes", "Good to go");

            Razorpay.Api.Order orderResponse = client.Order.Create(options);
            string             orderId       = orderResponse["id"].ToString();

            // Create order model for return on view
            OrderModel orderModel = new OrderModel
            {
                orderId       = orderResponse.Attributes["id"],
                razorpayKey   = "rzp_test_DmK2S2Y4ATkGZz",
                amount        = int.Parse(requestData.amount) * 100,
                currency      = "INR",
                name          = requestData.name,
                email         = requestData.email,
                contactNumber = requestData.contact,
                address       = requestData.address,
                description   = "Testing description"
            };

            // Return on PaymentPage with Order data
            return(View("Payment", orderModel));
        }
        public ActionResult CreateOrder(Models.PaymentInitiateModel paymentData)
        {
            // We can validate the payment data using dataAnnotation on model

            // Using random we crate the transaction id of payment
            Random randomObj     = new Random();
            string transactionId = randomObj.Next(10000000, 100000000).ToString();

            // Create instamojo Clint Id and Secret
            Instamojo objClass = InstamojoImplementation.getApi(instamojoClientId, instamojoSecretId, endpoint, auth_endpoint);


            PaymentOrder objPaymentRequest = new PaymentOrder();

            //Required POST parameters
            objPaymentRequest.name           = paymentData.name;
            objPaymentRequest.email          = paymentData.email;
            objPaymentRequest.phone          = paymentData.contactNumber;
            objPaymentRequest.amount         = paymentData.amount;
            objPaymentRequest.transaction_id = transactionId;   // Unique Id to be provided . This unique id we have to create

            // Redirect url is for when transaction completed than payment gateway redirected to this url
            // Let's set the redirecturl
            // Create Complete Controller function
            objPaymentRequest.redirect_url = "http://localhost:64200/payment/complete";

            //webhook is optional. this is used for when payment completed instamojo hit this api for giving the reponse of payment
            // objPaymentRequest.webhook_url = "https://your.server.com/webhook";


            // Validate the order data
            if (objPaymentRequest.validate())
            {
                // Email is not valid
                if (objPaymentRequest.emailInvalid)
                {
                }
                //Name is not valid
                if (objPaymentRequest.nameInvalid)
                {
                }
                //Phone is not valid
                if (objPaymentRequest.phoneInvalid)
                {
                }
                //Amount is not valid
                if (objPaymentRequest.amountInvalid)
                {
                }
                //Currency is not valid
                if (objPaymentRequest.currencyInvalid)
                {
                }
                //Transaction Id is not valid
                if (objPaymentRequest.transactionIdInvalid)
                {
                }
                //Redirect Url Id is not valid
                if (objPaymentRequest.redirectUrlInvalid)
                {
                }
                //              Webhook URL is not valid
                if (objPaymentRequest.webhookUrlInvalid)
                {
                }
            }
            else
            {
                try
                {
                    // Create the order and it will reurn payment url and instmojo order id
                    CreatePaymentOrderResponse objPaymentResponse = objClass.createNewPaymentRequest(objPaymentRequest);

                    // Instmojo order id you can save this wihth user data in db for verification on payment verification time
                    string orderId    = objPaymentResponse.order.id;
                    string paymentUrl = objPaymentResponse.payment_options.payment_url;

                    // Return on payment url
                    return(Redirect(paymentUrl));
                }
                catch (ArgumentNullException ex)
                {
                }
                catch (WebException ex)
                {
                }
                catch (IOException ex)
                {
                }
                catch (InvalidPaymentOrderException ex)
                {
                    if (!ex.IsWebhookValid())
                    {
                    }

                    if (!ex.IsCurrencyValid())
                    {
                    }

                    if (!ex.IsTransactionIDValid())
                    {
                    }
                }
                catch (ConnectionException ex)
                {
                }
                catch (BaseException ex)
                {
                }
                catch (Exception ex)
                {
                }
            }

            return(View(""));
        }
 public ActionResult GetPayment(Models.PaymentInitiateModel _requestData)
 {
     return(View("Index", _requestData));
 }