Esempio n. 1
0
        public void AdjustExternalBanks(Payment paymenttemp)
        {
            Users user_sender = get_user_info(paymenttemp.Requestor_user_key);
            Users user_treasury = get_treasury_account(1);
            External_APIs.BancBox bb = new External_APIs.BancBox();

            //Adjust Sender's ext banks
            if ((paymenttemp.Buy_currency == 3) && (user_sender.Bancbox_payment_object_key > 0) && (paymenttemp.Payment_object_receiver_type != 1)){ //USD & sender has BB
                bb.SendFunds_Internal(user_sender.User_key, user_treasury.User_key, paymenttemp.Buy_amount, "Adjust External Banks", false, 1, paymenttemp.Payments_Key);
            }

            //Adjust Receiver's ext banks
            if (paymenttemp.Payment_object_receiver_type == 3) //going to user's Balance
            {
                Users user_receiver = get_user_from_paymentobject(paymenttemp.Payment_object_receiver);
                if ((paymenttemp.Buy_currency == 3) && (user_receiver.Bancbox_payment_object_key > 0))
                {
                    bb.SendFunds_Internal(user_treasury.User_key, user_receiver.User_key, paymenttemp.Buy_amount, "Adjust External Banks", false, 1, paymenttemp.Payments_Key);
                }
            }
        }
Esempio n. 2
0
        public Payment getPayment(int paymentkey)
        {
            Payment paymenttemp = new Payment();
            paymenttemp.Payments_Key = paymentkey;

            DataSet dstemp = Peerfx_DB.SPs.ViewPaymentSpecific(paymentkey).GetDataSet();

            if (dstemp.Tables[0].Rows[0]["quote_key"] != DBNull.Value)
            {
                paymenttemp.Quote_Key = Convert.ToInt32(dstemp.Tables[0].Rows[0]["quote_key"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["quote_key_actual"] != DBNull.Value)
            {
                paymenttemp.Quote_Key_Actual = Convert.ToInt32(dstemp.Tables[0].Rows[0]["quote_key_actual"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["payment_status"] != DBNull.Value)
            {
                paymenttemp.Payment_status = Convert.ToInt32(dstemp.Tables[0].Rows[0]["payment_status"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["date_created"] != DBNull.Value)
            {
                paymenttemp.Date_created = Convert.ToDateTime(dstemp.Tables[0].Rows[0]["date_created"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["payment_object_sender"] != DBNull.Value)
            {
                paymenttemp.Payment_object_sender = Convert.ToInt64(dstemp.Tables[0].Rows[0]["payment_object_sender"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["payment_object_receiver"] != DBNull.Value)
            {
                paymenttemp.Payment_object_receiver = Convert.ToInt64(dstemp.Tables[0].Rows[0]["payment_object_receiver"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["payment_object_receiver_type"] != DBNull.Value)
            {
                paymenttemp.Payment_object_receiver_type = Convert.ToInt32(dstemp.Tables[0].Rows[0]["payment_object_receiver_type"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["payment_description"] != DBNull.Value)
            {
                paymenttemp.Payment_description = dstemp.Tables[0].Rows[0]["payment_description"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["sell_amount"] != DBNull.Value)
            {
                paymenttemp.Sell_amount = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["sell_amount"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["sell_currency"] != DBNull.Value)
            {
                paymenttemp.Sell_currency = Convert.ToInt32(dstemp.Tables[0].Rows[0]["sell_currency"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["buy_amount"] != DBNull.Value)
            {
                paymenttemp.Buy_amount = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["buy_amount"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["buy_currency"] != DBNull.Value)
            {
                paymenttemp.Buy_currency = Convert.ToInt32(dstemp.Tables[0].Rows[0]["buy_currency"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["rate"] != DBNull.Value)
            {
                paymenttemp.Rate = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["rate"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["service_fee"] != DBNull.Value)
            {
                paymenttemp.Service_fee = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["service_fee"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["promised_delivery_date"] != DBNull.Value)
            {
                paymenttemp.Promised_delivery_date = Convert.ToDateTime(dstemp.Tables[0].Rows[0]["promised_delivery_date"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["actual_delivery_date"] != DBNull.Value)
            {
                paymenttemp.Actual_delivery_date = Convert.ToDateTime(dstemp.Tables[0].Rows[0]["actual_delivery_date"].ToString());
            }
            if (dstemp.Tables[0].Rows[0]["receiver_name"] != DBNull.Value)
            {
                paymenttemp.Receiver_name = dstemp.Tables[0].Rows[0]["receiver_name"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["sender_name"] != DBNull.Value)
            {
                paymenttemp.Sender_name = dstemp.Tables[0].Rows[0]["sender_name"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["sell_currency_text"] != DBNull.Value)
            {
                paymenttemp.Sell_currency_text = dstemp.Tables[0].Rows[0]["sell_currency_text"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["buy_currency_text"] != DBNull.Value)
            {
                paymenttemp.Buy_currency_text = dstemp.Tables[0].Rows[0]["buy_currency_text"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["payment_status_text"] != DBNull.Value)
            {
                paymenttemp.Payment_status_text = dstemp.Tables[0].Rows[0]["payment_status_text"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["internal_only"] != DBNull.Value)
            {
                paymenttemp.Internal_only = Convert.ToBoolean(dstemp.Tables[0].Rows[0]["internal_only"]);
            }
            if (dstemp.Tables[0].Rows[0]["requiresmanualexport"] != DBNull.Value)
            {
                paymenttemp.Requiresmanualexport = Convert.ToBoolean(dstemp.Tables[0].Rows[0]["requiresmanualexport"]);
            }
            if (dstemp.Tables[0].Rows[0]["requestor_user_key"] != DBNull.Value)
            {
                paymenttemp.Requestor_user_key = Convert.ToInt32(dstemp.Tables[0].Rows[0]["requestor_user_key"]);
            }
            if (dstemp.Tables[0].Rows[0]["txt_Sell_full"] != DBNull.Value)
            {
                paymenttemp.Txt_Sell_full = dstemp.Tables[0].Rows[0]["txt_Sell_full"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["txt_Buy_full"] != DBNull.Value)
            {
                paymenttemp.Txt_Buy_full = dstemp.Tables[0].Rows[0]["txt_Buy_full"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["actual_rate"] != DBNull.Value)
            {
                paymenttemp.Actual_rate = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["actual_rate"]);
            }
            if (dstemp.Tables[0].Rows[0]["actual_txt_Sell_full"] != DBNull.Value)
            {
                paymenttemp.Actual_txt_Sell_full = dstemp.Tables[0].Rows[0]["actual_txt_Sell_full"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["actual_txt_Buy_full"] != DBNull.Value)
            {
                paymenttemp.Actual_txt_Buy_full = dstemp.Tables[0].Rows[0]["actual_txt_Buy_full"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["actual_service_fee"] != DBNull.Value)
            {
                paymenttemp.Actual_service_fee = Convert.ToDecimal(dstemp.Tables[0].Rows[0]["actual_service_fee"]);
            }
            if (dstemp.Tables[0].Rows[0]["treasury_type"] != DBNull.Value)
            {
                paymenttemp.Treasury_type = Convert.ToInt32(dstemp.Tables[0].Rows[0]["treasury_type"]);
            }
            if (dstemp.Tables[0].Rows[0]["directlyfromcurrencycloud"] != DBNull.Value)
            {
                paymenttemp.Directlyfromcurrencycloud = Convert.ToInt32(dstemp.Tables[0].Rows[0]["directlyfromcurrencycloud"]);
            }
            if (dstemp.Tables[0].Rows[0]["cc_tradeid"] != DBNull.Value)
            {
                paymenttemp.Currencycloudtradeid = dstemp.Tables[0].Rows[0]["cc_tradeid"].ToString();
            }
            if (dstemp.Tables[0].Rows[0]["cc_paymentid"] != DBNull.Value)
            {
                paymenttemp.Currencycloudpaymentid = dstemp.Tables[0].Rows[0]["cc_paymentid"].ToString();
            }
            return paymenttemp;
        }
Esempio n. 3
0
 public void CompleteTopUp(Payment paymenttemp)
 {
 }
Esempio n. 4
0
        public void payment_refill_treasury(Payment paymenttemp)
        {
            Users treasury = get_treasury_account(1);
            Int64 senderpaymentobject = getpaymentobject_UserBalance(treasury.User_key, paymenttemp.Sell_currency);
            Int64 receiverpaymentobject = getpaymentobject_UserBalance(treasury.User_key, paymenttemp.Buy_currency);

            //Save & get Quote
            Quote quotetemp = getQuote(paymenttemp.Buy_amount, paymenttemp.Buy_currency, paymenttemp.Sell_currency, false);
            StoredProcedure sp_UpdateQuotes = Peerfx_DB.SPs.UpdateQuotes(0, quotetemp.Sellamount, quotetemp.Sellcurrency, quotetemp.Buyamount, quotetemp.Buycurrency, quotetemp.Peerfx_Rate, quotetemp.Peerfx_Rate, null, null, 0);
            sp_UpdateQuotes.Execute();
            int quote_key = Convert.ToInt32(sp_UpdateQuotes.Command.Parameters[9].ParameterValue.ToString());

            //Insert Payment
            StoredProcedure sp_UpdatePayments = Peerfx_DB.SPs.UpdatePayments(0, quote_key, 0, 0, treasury.User_key, "Replenish Treasury, Payment# - " + paymenttemp.Payments_Key.ToString(), senderpaymentobject, receiverpaymentobject);
            sp_UpdatePayments.Execute();
            int newpayment_key = Convert.ToInt32(sp_UpdatePayments.Command.Parameters[3].ParameterValue.ToString());

            //update payment status to confirmed
            Peerfx_DB.SPs.UpdatePaymentStatus(newpayment_key, 2).Execute();

            //make sure newpayment goes through CC treasury
            Peerfx_DB.SPs.UpdatePaymentTreasury(newpayment_key, 2).Execute();

            int newsellcurrency = paymenttemp.Buy_currency;
            decimal newsellamount = paymenttemp.Buy_amount;

            //send money from user balance to payment object
            Int64 payment_payment_object_key = getpaymentobject(6, newpayment_key);
            Peerfx_DB.SPs.UpdateTransactionsInternal(0, 2, newsellcurrency, newsellamount, senderpaymentobject, payment_payment_object_key, get_ipaddress(), paymenttemp.Requestor_user_key, "treasury balance to payment", 0, 1, newpayment_key).Execute();

            //instantly convert the payment, because source funding is balance
            //initiate conversion
            payment_initiate(newpayment_key);
        }
Esempio n. 5
0
        public void payment_insert_actual_quote(Payment paymenttemp)
        {
            int paymentkey = paymenttemp.Payments_Key;
            Quote quotetemp = new Quote();
            //Get & Store actual quote
            if (paymenttemp.Treasury_type == 1)
            {
                quotetemp = getQuote(paymenttemp.Sell_amount, paymenttemp.Sell_currency, paymenttemp.Buy_currency, true);
            }
            else
            {
                quotetemp = getQuote(paymenttemp.Sell_amount, paymenttemp.Sell_currency, paymenttemp.Buy_currency, false);
            }

            StoredProcedure sp_UpdateQuotes = Peerfx_DB.SPs.UpdateQuotes(0, quotetemp.Sellamount, paymenttemp.Sell_currency, quotetemp.Buyamount, paymenttemp.Buy_currency, quotetemp.Peerfx_Rate, quotetemp.Peerfx_Servicefee, null, null, 0);
            sp_UpdateQuotes.Execute();
            int quote_key = Convert.ToInt32(sp_UpdateQuotes.Command.Parameters[9].ParameterValue.ToString());
            Peerfx_DB.SPs.UpdatePaymentsActualQuote(paymenttemp.Payments_Key, quote_key).Execute();
        }
Esempio n. 6
0
        public void payment_convert_currency_internal(Payment paymenttemp)
        {
            Int64 payment_payment_object_key = getpaymentobject(6, paymenttemp.Payments_Key);

            paymenttemp = getPayment(paymenttemp.Payments_Key);
            //**************This is also where we charge service fees*********************
            Peerfx_DB.SPs.UpdateConvertCurrency(payment_payment_object_key, paymenttemp.Quote_Key_Actual, get_ipaddress(), paymenttemp.Requestor_user_key, paymenttemp.Payments_Key).Execute();

            //update status to currency converted
            Peerfx_DB.SPs.UpdatePaymentStatus(paymenttemp.Payments_Key, 4).Execute();

            //refill the treasury, by sending a request to currencycloud
            paymenttemp = getPayment(paymenttemp.Payments_Key);
            payment_refill_treasury(paymenttemp);
        }
Esempio n. 7
0
 public void payment_convert_currency_CC(Payment paymenttemp)
 {
     //Execute trade with CC
     External_APIs.CurrencyCloud cc = new External_APIs.CurrencyCloud();
     cc.Trade_Execute(paymenttemp.Payments_Key);
 }
Esempio n. 8
0
        public void payment_complete(Payment paymenttemp)
        {
            int paymentkey = paymenttemp.Payments_Key;
            Int64 payment_payment_object_key = getpaymentobject(6, paymentkey);
            Users user_requestor = get_user_info(paymenttemp.Requestor_user_key);

            //Check if does not require manual export
            if (!paymenttemp.Requiresmanualexport)
            {
                Peerfx.External_APIs.SendGrid sg = new Peerfx.External_APIs.SendGrid();
                //Automatically complete payment

                //If Applicable - Ownership of funds is changing, so need to change ownership of funds in ext bank accounts , eg. bancbox
                AdjustExternalBanks(paymenttemp);

                if (paymenttemp.Payment_object_receiver_type == 3) //going to user balance
                {
                    Peerfx_DB.SPs.UpdateTransactionsInternal(0, 2, paymenttemp.Buy_currency, paymenttemp.Buy_amount, payment_payment_object_key, paymenttemp.Payment_object_receiver, get_ipaddress(), paymenttemp.Requestor_user_key, "From Payment to User Balance", 0, 1, paymentkey).Execute();
                    Peerfx_DB.SPs.UpdatePaymentStatus(paymentkey, 5).Execute(); //payment delivered

                    //payment completed, send email
                    sg.Send_Email_Payment_Completed(paymenttemp.Payments_Key, user_requestor);
                }
                else if (paymenttemp.Payment_object_receiver_type == 7) //Embee top up
                {
                    //Send Top Up
                    EmbeeObject embeetemp = getEmbeeObject(paymenttemp.Payments_Key);
                    External_APIs.Embee embeecalls = new External_APIs.Embee();
                    int newtransid = embeecalls.RequestPurchase(embeetemp.Productid.ToString(), embeetemp.Phone, user_requestor.Email, get_ipaddress(), user_requestor.User_key, paymentkey);
                    Peerfx_DB.SPs.UpdateEmbeeNewtransid(newtransid, embeetemp.Embee_object_key).Execute();
                    Peerfx_DB.SPs.UpdatePaymentStatus(paymentkey, 6).Execute();

                    Int64 embee_paymentobjectkey = getpaymentobject(7, embeetemp.Embee_object_key);
                    Peerfx_DB.SPs.UpdateTransactionsExternal(0, 1, paymenttemp.Buy_currency, paymenttemp.Buy_amount, payment_payment_object_key, embee_paymentobjectkey, get_ipaddress(), paymenttemp.Requestor_user_key, "From Payment to Embee Object", "", 0, 1, paymentkey).Execute();

                    //send receiver note
                    try
                    {
                        string thebody = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("/SMS/payment_confirmed_Embee.txt"));
                        thebody = thebody.Replace("FIRST_NAME", user_requestor.First_name);
                        thebody = thebody.Replace("LAST_NAME", user_requestor.Last_name);
                        thebody = thebody.Replace("TOPUP_NAME", embeetemp.Productname);

                        External_APIs.Twilio twillio = new External_APIs.Twilio();
                        twillio.SendSMS(embeetemp.Phone, thebody, embeetemp.Country);
                    }
                    catch
                    {
                    }
                }
                else if ((paymenttemp.Buy_currency == 3) && (user_requestor.Bancbox_payment_object_key > 0) && (IsBankAccount(paymenttemp.Payment_object_receiver)))
                {
                    //Send out money via Bancbox account
                    External_APIs.BancBox bb = new External_APIs.BancBox();
                    bb.SendFunds_External(user_requestor.User_key, paymenttemp.Payment_object_receiver, paymenttemp.Buy_amount, "External Transfer", false, 1, paymenttemp.Payments_Key);
                    Peerfx_DB.SPs.UpdateTransactionsExternal(0, 1, paymenttemp.Buy_currency, paymenttemp.Buy_amount, payment_payment_object_key, paymenttemp.Payment_object_receiver, get_ipaddress(), paymenttemp.Requestor_user_key, "From Payment to Ext US Bank", "", 0, 1, paymentkey).Execute();

                    //change status to Transaction Complete
                    Peerfx_DB.SPs.UpdatePaymentStatus(paymentkey, 5).Execute();

                    //payment in Payment Sent, send email
                    sg.Send_Email_Payment_Completed(paymenttemp.Payments_Key, user_requestor);
                }
            }
            else
            {
                //notify admin manual export is required

                //change status to processing transaction / awaiting withdrawl
                Peerfx_DB.SPs.UpdatePaymentStatus(paymenttemp.Payments_Key, 10).Execute();
            }
        }