Exemplo n.º 1
0
        public async Task <IActionResult> PayTransactionMobilePay(PayTransaction model)
        {
            var user = await _identityService.GetUserById(model.ToUserId);

            if (string.IsNullOrWhiteSpace(user.PhoneNumber))
            {
                return(Json(new
                {
                    respone = "Error",
                    result = user.FirstName + " " + user.LastName + " have not registered a phone number"
                }));
            }

            var command = new CreateTransactionCommand
            {
                TransactionType    = TransactionType.FinancialReceiptsMobilePay,
                ToUserId           = model.ToUserId,
                Amount             = model.Amount,
                FinancialProjectId = model.FinancialProjectId
            };

            await Mediator.Send(command);


            var mobilePayDeepLink = MobilePayDeepLink.GenerateUrl(user, model.Amount);

            return(Json(new { response = "Succeed", result = mobilePayDeepLink }));
        }
Exemplo n.º 2
0
        public long SavePayTransaction(PaymentData pay_data, bool fromPay)
        {
            long pay_transaction_id = 0;

            if (fromPay)
            {
                if (!_db.PayTransactions.Any(t => t.TransactionId == pay_data.TransactionId))
                {
                    PayTransaction pay_tran = new PayTransaction
                    {
                        Amount              = pay_data.Amount,
                        Tdate               = DateTime.Now,
                        TransactionId       = pay_data.TransactionId,
                        PayTransactionCards = pay_data.Cards.Select(c => new PayTransactionCard {
                            CardId = c
                        }).ToList()
                    };
                    _db.PayTransactions.Add(pay_tran);
                    _db.SaveChanges();
                    pay_transaction_id = pay_tran.Id;
                }
                else
                {
                    return(0);
                }
            }

            return(pay_transaction_id);
        }
Exemplo n.º 3
0
        private bool ONLine()
        {
            Thread t = new Thread(() =>
            {
                try
                {
                    //--------------
                    // create/read configuration from a configuration file
                    PayConfiguration config = createConfigFromFile(mPfad);

                    // start a new session
                    PaySession session = new PaySession();

                    // we define a message listener for events (optional)
                    MyMessageListener msgList = new MyMessageListener(lbl_Status, btn_OK);

                    session.setListener(msgList);

                    if (!session.isLoggedIn())
                    {
                        // login (this is always the first communication to the EFT)
                        mTerminal = session.login(config);
                    }


                    try
                    {
                        // Now we start a payment of 1 cent

                        // First we create the result object PayMedia
                        PayMedia media = new PayMedia();

                        // Then we start the authorisation of the card

                        short payType = PayTerminal.__Fields.PAY_TYPE_AUTOMATIC;
                        PayTransaction transaction = mTerminal.payment(mBetrag, payType, media);

                        // When we are here, the given card was accepted. We commit the transaction.
                        // If transaction is null, the device doesn't support commit and we are finished.
                        if (transaction != null)
                        {
                            transaction.commit(media);
                        }
                    }
                    finally
                    {
                    }
                }
                catch (PayException x)
                {
                    // catch all PayExceptions and write to console
                    Console.WriteLine(x.toString());
                }
            });

            t.Start();
            return(true);
        }
Exemplo n.º 4
0
        public BufferRegister GetBufferRegisterByPayToken(string token, AppDbContext ctx)
        {
            BufferRegister model = new BufferRegister();

            using (SqlConnection connection = ctx.Database.Connection as SqlConnection)
            {
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                }
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "select b.*, m.Title MembershipTitle, m.[Description] MembershipDescription, m.RoleName, m.Price, g.GatewayID, g.GatewayName from BufferRegister b left join Membership m on m.MembershipID = b.MembershipId left join Gateways g on g.IsDefault = 1 where b.TransactionToken = @TransactionToken";
                    command.Parameters.AddWithValue("@TransactionToken", token);
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        model.TokenID = (Guid)reader["TokenID"];
                        //contact
                        Contact modelContact = new Contact();
                        modelContact.Email     = reader["Email"].ToString();
                        modelContact.FirstName = reader["FirstName"].ToString();
                        modelContact.LastName  = reader["LastName"].ToString();
                        modelContact.City      = reader["City"].ToString();
                        model.BufferContact    = modelContact;

                        Membership modelMmb = new Membership();
                        modelMmb.MembershipID = int.Parse(reader["MembershipId"].ToString());
                        modelMmb.Title        = reader["MembershipTitle"].ToString();
                        modelMmb.Description  = reader["MembershipDescription"].ToString();
                        modelMmb.RoleName     = reader["RoleName"].ToString();
                        var     dblPrice  = reader["Price"].ToString();
                        decimal dblMPrice = 0;
                        decimal.TryParse(dblPrice, out dblMPrice);
                        modelMmb.Price         = dblMPrice;
                        model.BufferMembership = modelMmb;

                        PayTransaction modelTrans = new PayTransaction();
                        modelTrans.Amount            = dblMPrice;
                        modelTrans.PayerID           = Tools.SafeGetString(reader, "RoleName");
                        modelTrans.TransactionNumber = Tools.SafeGetString(reader, "TransactionNumber");
                        modelTrans.TransactionToken  = Tools.SafeGetString(reader, "TransactionToken");
                        model.BufferTransaction      = modelTrans;

                        Gateway modelGateway = new Gateway();
                        modelGateway.GatewayId   = reader["GatewayID"] as int? ?? default(int);
                        modelGateway.GatewayName = Tools.SafeGetString(reader, "GatewayName");
                        model.BufferGateway      = modelGateway;
                    }

                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }
            return(model);
        }
Exemplo n.º 5
0
        public async Task PayTransaction(PayTransaction model)
        {
            var command = new CreateTransactionCommand
            {
                TransactionType    = TransactionType.FinancialReceipts,
                ToUserId           = model.ToUserId,
                Amount             = model.Amount,
                FinancialProjectId = model.FinancialProjectId
            };

            await Mediator.Send(command);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            try
            {
                // create/read configuration from a configuration file
                PayConfiguration config = createConfigFromFile("../../etc/zvt.cfg");

                // start a new session
                PaySession session = new PaySession();

                // we define a message listener for events (optional)
                session.setListener(new MyMessageListener());

                // get the software version of LUIS ePayment
                Console.WriteLine("Version=" + session.getVersion());

                // login (this is always the first communication to the EFT)
                PayTerminal terminal = session.login(config);

                try
                {
                    // let's have a look at the settings within the EFT
                    PayResult result = terminal.settings();
                    Console.WriteLine(result.toString());

                    // do some selftest
                    result = terminal.selftest();
                    Console.WriteLine(result.toString());


                    // try to connect the network provider and get the limits for a payment
                    result = terminal.diagnose(PayTerminal.__Fields.DIAGNOSE_EXTENDED);
                    Console.WriteLine(result.toString());


                    // Now we start a payment of 1 cent

                    // First we create the result object PayMedia
                    PayMedia media = new PayMedia();

                    // Then we start the authorisation of the card
                    int            cents       = 1;
                    short          payType     = PayTerminal.__Fields.PAY_TYPE_AUTOMATIC;
                    PayTransaction transaction = terminal.payment(cents, payType, media);
                    Console.WriteLine(media.toString());

                    // When we are here, the given card was accepted. We commit the transaction.
                    // If transaction is null, the device doesn't support commit and we are finished.
                    if (transaction != null)
                    {
                        transaction.commit(media);
                        Console.WriteLine(media.toString());
                    }
                }
                finally
                {
                    // logout at last
                    session.logout();
                }
            }
            catch (PayException x)
            {
                // catch all PayExceptions and write to console
                Console.WriteLine(x.toString());
            }
        }
Exemplo n.º 7
0
        public ActionResult PaymentItemReceive(string token, string payerID)
        {
            try {
                string query;

                // First thing's first. We'll need to get the token and payer ID returned from the previous call:
                if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(payerID))
                {
                    ViewBag.ErrorMessage = "Something went wrong, payment didn't go through the gateway.";
                    return(View());
                }


                //BufferRegister model = new BufferRegister();

                BufferRegister dbModel; //= DBHelper.DBMembership.GetModelByTransactionToken(token);
                Helpers.DB     xObj = new Helpers.DB();
                dbModel = xObj.GetBufferRegisterByPayToken(token, new AppDbContext());

                // using (AppDbContext context = new AppDbContext())
                // {
                //     query = "SELECT BufferRegister.*, Membership.Title, Membership.[Description], Membership.Price from BufferRegister " +
                //             " LEFT JOIN Membership on Membership.MembershipID = BufferRegister.MembershipID " +
                //             " WHERE BufferRegister.TransactionToken = @TransactionToken ";
                //     dbModel = context.Database.SqlQuery<BufferRegister>(query,
                //         new SqlParameter("@TransactionToken", token)
                //         ).First();
                //}

                string  nameProduct = HttpUtility.UrlEncode(dbModel.BufferMembership.Title);
                string  descProduct = HttpUtility.UrlEncode(dbModel.BufferMembership.Description);
                decimal tax         = 13 / 100;
                string  sTax        = Helpers.Tools.PriceFormat(tax);
                string  Amount      = Helpers.Tools.PriceFormat(dbModel.BufferMembership.Price);
                string  totalAmount = Helpers.Tools.PriceFormat(dbModel.BufferMembership.Price * (1 + tax));


                // Than we add the tokens to string type variables as we'll need to rebuild the NVP string

                // Rebuilding the NVP string for the request; I've hardcoded the payment values again as this sample app does not have a database behind it.
                string NVP = string.Empty;

                NVP += "METHOD=DoExpressCheckoutPayment";
                NVP += "&VERSION=123";

                NVP += "&USER="******"&PWD=" + Your_Test_Account_Password;
                NVP += "&SIGNATURE=" + Your_Test_Account_Signature;

                NVP += "&TOKEN=" + token;
                NVP += "&PAYERID=" + payerID;

                NVP += "&PAYMENTREQUEST_0_PAYMENTACTION=Sale";
                NVP += "&PAYMENTREQUEST_0_AMT=" + totalAmount;
                NVP += "&PAYMENTREQUEST_0_ITEMAMT=" + Amount;
                NVP += "&PAYMENTREQUEST_0_SHIPPINGAMT=0";
                NVP += "&PAYMENTREQUEST_0_HANDLINGAMT=0";
                NVP += "&PAYMENTREQUEST_0_TAXAMT=" + sTax;

                // Making the API call
                string response = APICall(NVP);

                // Interpreting the response from PayPal; As a simple UI for checking the transaction, I'm displaying the transaction ID in the page on success so to make things easier when I'm checking the transaction log in PayPal's web UI.
                if (response.Contains("Success"))
                {
                    string transactionId  = response.Substring(response.IndexOf("PAYMENTINFO_0_TRANSACTIONID"), response.IndexOf("&", response.IndexOf("PAYMENTINFO_0_TRANSACTIONID")) - response.IndexOf("PAYMENTINFO_0_TRANSACTIONID"));
                    string TransactNumber = transactionId.Split('=')[1];
                    ViewBag.PaymentStatus += transactionId;

                    //model = DBHelper.DBMembership.CheckTransactionTokenReturn(token);
                    if (dbModel.isBufferValid())
                    {
                        PayTransaction modelTrans = new PayTransaction();
                        modelTrans.PayerID           = payerID;
                        modelTrans.TransactionNumber = TransactNumber;
                        dbModel.BufferTransaction    = modelTrans;

                        using (AppDbContext context = new AppDbContext())
                        {
                            //validate transaction, update database
                            query = "update BufferRegister set PayerID=@PayerID, TransactionNumber=@TransactionNumber where Email=@Email";
                            context.Database.ExecuteSqlCommand(query,
                                                               new SqlParameter("@Email", dbModel.BufferContact.Email),
                                                               new SqlParameter("@TransactionNumber", dbModel.BufferTransaction.TransactionNumber),
                                                               new SqlParameter("@PayerID", dbModel.BufferTransaction.PayerID));

                            //buffer transfer, update database
                            query = "BufferTransfer @Email";
                            context.Database.ExecuteSqlCommand(query,
                                                               new SqlParameter("@Email", dbModel.BufferContact.Email));
                        }
                        //create application username
                        Helpers.MembUsers.CreateMember(dbModel, new AuthDbContext());
                    }
                }
                else
                {
                    //model = (MembershipContactInfoModel)Session["Payer"];
                    throw new Exception("Something went wrong, payment didn't go through the gateway.");
                }

                return(View(dbModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("CustomError", ex.Message);
                return(View("Error"));
            }
        }
Exemplo n.º 8
0
        public ActionResult PaymentReceive(string token, string payerID)
        {
            try
            {
                string currency = "CAD";

                string query;
                //string payerID = payerID;
                // First thing's first. We'll need to get the token and payer ID returned from the previous call:
                //|| string.IsNullOrEmpty(payerID)
                if (string.IsNullOrEmpty(token))
                {
                    ViewBag.ErrorMessage = "Something went wrong, payment didn't go through the gateway.";
                    return(View());
                }


                //BufferRegister model = new BufferRegister();

                BufferRegister dbModel; //= DBHelper.DBMembership.GetModelByTransactionToken(token);
                Helpers.DB     xObj = new Helpers.DB();
                dbModel = xObj.GetBufferRegisterByPayToken(token, new AppDbContext());

                string  nameProduct = HttpUtility.UrlEncode(dbModel.BufferMembership.Title);
                string  descProduct = HttpUtility.UrlEncode(dbModel.BufferMembership.Description);
                decimal tax         = 13 / 100;
                string  sTax        = Helpers.Tools.PriceFormat(tax);
                string  Amount      = Helpers.Tools.PriceFormat(dbModel.BufferMembership.Price);
                string  totalAmount = Helpers.Tools.PriceFormat(dbModel.BufferMembership.Price * (1 + tax));
                string  sTaxAmt     = Helpers.Tools.PriceFormat(tax * dbModel.BufferMembership.Price);

                // Than we add the tokens to string type variables as we'll need to rebuild the NVP string

                // Rebuilding the NVP string for the request;
                string NVP = string.Empty;
                NVP += "USER="******"&PWD=" + Your_Test_Account_Password;
                NVP += "&SIGNATURE=" + Your_Test_Account_Signature;

                NVP += "&METHOD=CreateRecurringPaymentsProfile";
                NVP += "&VERSION=86";

                //product
                NVP += "&DESC=" + nameProduct;  //#Profile description - same value as a billing agreement description
                //NVP += "&NAME=" + nameProduct;  //#Profile description - same value as a billing agreement description

                //payment
                NVP += "&TOKEN=" + token;
                NVP += "&TAXAMT=" + sTaxAmt;
                //NVP += "&INITAMT=" + Amount;
                NVP += "&BILLINGPERIOD=Year";  //    #Period of time between billings
                NVP += "&BILLINGFREQUENCY=1";  //    #Frequency of charges
                NVP += "&AMT=" + Amount;       //    #The amount the buyer will pay in a payment period
                NVP += "&MAXFAILEDPAYMENTS=3"; //    #Maximum failed payments before suspension of the profile
                NVP += "&NOSHIPPING=2";        //    #Maximum failed payments before suspension of the profile
                NVP += "&CURRENCYCODE=" + currency;

                // Products involved in the transaction
                NVP += "&PAYMENTREQUEST_0_AMT=" + totalAmount;      // Total payment for the transaction
                NVP += "&PAYMENTREQUEST_0_ITEMAMT=" + Amount;       // Purchased product price
                NVP += "&PAYMENTREQUEST_0_TAXAMT=" + sTaxAmt;       // Tax amount
                NVP += "&PAYMENTREQUEST_0_QTY=1";
                //NVP += "&L_PAYMENTREQUEST_0_NAME0=" + nameProduct;                                                  // Product name
                //NVP += "&L_PAYMENTREQUEST_0_DESC0=" + descProduct;                                                  // Product description
                //NVP += "&L_PAYMENTREQUEST_0_AMT0=" + totalAmount;       // Product price
                //NVP += "&L_PAYMENTREQUEST_0_QTY0=1";                            // Product quantity

                //Payer Information Fields
                NVP += "&EMAIL=" + dbModel.BufferContact.Email;

                NVP += "&SHIPTONAME=" + dbModel.BufferContact.FirstName + " " + dbModel.BufferContact.LastName;

                NVP += "&SUBSCRIBERNAME=" + dbModel.BufferContact.FirstName + " " + dbModel.BufferContact.LastName;
                NVP += "&PROFILEREFERENCE=INVOICENUMBERORSTUFF";
                NVP += "&PROFILESTARTDATE=" + DateTime.UtcNow.ToString(); //  #Billing date start, in UTC/GMT format
                NVP += "&FIRSTNAME=" + dbModel.BufferContact.FirstName;
                NVP += "&LASTNAME=" + dbModel.BufferContact.LastName;
                NVP += "&STREET=1 Anything Street";
                NVP += "&ADDRESS1=1 Anything Street";
                NVP += "&CITY=" + dbModel.BufferContact.City;
                //NVP += "&STATE=ON";
                //NVP += "&ZIP=L4Z3U2";
                NVP += "&COUNTRYCODE=CA";
                NVP += "&BUSINESS=City of Hamilton";
                NVP += "&AUTOBILLAMT=AddToNextBilling";


                // Making the API call
                string response = APICall(NVP);

                // Interpreting the response from PayPal; As a simple UI for checking the transaction, I'm displaying the transaction ID in the page on success so to make things easier when I'm checking the transaction log in PayPal's web UI.
                if (response.Contains("Success"))
                {
                    string Profile        = response.Substring(response.IndexOf("PROFILEID"), response.IndexOf("&", response.IndexOf("PROFILEID")) - response.IndexOf("PROFILEID"));
                    string TransactNumber = Profile.Split('=')[1];
                    ViewBag.PaymentStatus += TransactNumber;

                    //model = DBHelper.DBMembership.CheckTransactionTokenReturn(token);
                    if (dbModel.isBufferValid())
                    {
                        PayTransaction modelTrans = new PayTransaction();
                        modelTrans.PayerID           = payerID;
                        modelTrans.TransactionNumber = TransactNumber;
                        dbModel.BufferTransaction    = modelTrans;

                        using (AppDbContext context = new AppDbContext())
                        {
                            //validate transaction, update database
                            query = "update BufferRegister set PayerID=@PayerID, TransactionNumber=@TransactionNumber where Email=@Email";
                            context.Database.ExecuteSqlCommand(query,
                                                               new SqlParameter("@Email", dbModel.BufferContact.Email),
                                                               new SqlParameter("@TransactionNumber", dbModel.BufferTransaction.TransactionNumber),
                                                               new SqlParameter("@PayerID", dbModel.BufferTransaction.PayerID));

                            //buffer transfer, update database
                            query = "BufferTransfer @Email";
                            context.Database.ExecuteSqlCommand(query,
                                                               new SqlParameter("@Email", dbModel.BufferContact.Email));
                        }
                        //create application username
                        Helpers.MembUsers.CreateMember(dbModel, new AuthDbContext());
                    }
                }
                else
                {
                    //model = (MembershipContactInfoModel)Session["Payer"];
                    throw new Exception("Something went wrong, payment didn't go through the gateway.");
                }

                return(View(dbModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("CustomError", ex.Message);
                return(View("Error"));
            }
        }