Exemplo n.º 1
0
        /// <summary>
        /// Creates some general payza button
        /// </summary>
        /// <param name="itemName">Name describing the item or service. Max Length: 50 characters</param>
        /// <param name="amount">The price or cost of the product or service. The value for
        /// amount must be positive. Null or negative numbers are not allowed.</param>
        /// <param name="command">Describes how handler should handle IPN request.
        /// Stored in field apc_1. Max Length: 100 characters</param>
        /// <param name="args">
        /// Custom values you can pass along with the payment button.
        /// The values are not displayed to the payer on our Pay Process page.
        /// Payza returns these fields back in the IPN.
        /// Used by IIpnHandler ('command')
        /// Stored in fields apc_2 - apc_6. Max Length: 100 characters
        /// </param>
        /// <returns>Http address where member should be redirected after clicking button.</returns>
        protected override string generate(string itemName, Money amount, string command, object[] args)
        {
            string url = String.Empty;

            var shooppingVoucher = new ShoppingVoucherEntity();

            shooppingVoucher.Amount       = amount.ToDecimal();
            shooppingVoucher.ProductName  = itemName;
            shooppingVoucher.CategoryName = HashingManager.Base64Encode(command);
            shooppingVoucher.TotalAmount  = amount.ToDecimal();
            shooppingVoucher.Quantity     = 1;

            int orderId = PaparaOrder.Create(amount, command, String.Join(ButtonGenerationStrategy.ArgsDelimeter.ToString(), args));

            var client = new ApiRequestSoapClient();
            var result = client.TransactionRequest(account.ApiName, account.ApiKey, account.Username, orderId.ToString(), amount.ToDecimal(), Money.Zero.ToDecimal(),
                                                   new ShoppingVoucherEntity[1] {
                shooppingVoucher
            }, AppSettings.Site.Url + "Handlers/Payment/Papara.ashx", 2);

            client.Close();

            if (result.ResultStatus && !String.IsNullOrEmpty(result.ResultObject))
            {
                url = result.ResultObject;
            }

            return(url);
        }
Exemplo n.º 2
0
        protected override string generate(string itemName, Money amount, string command, object[] args)
        {
            NVPStringBuilder nvps = new NVPStringBuilder();

            string orderId = HashingManager.GenerateMD5(AppSettings.Site.Name + DateTime.Now).ToLower();

            orderId = orderId.Substring(0, Math.Min(orderId.Length, 31));

            string description = command + "#" + String.Join(ArgsDelimeter + "", args);

            description = itemName + " **" + description;

            string toHash = account.MerchantID + ":" + orderId + ":" + amount.ToShortClearString() + ":" + AppSettings.Site.CurrencyCode
                            + ":" + HashingManager.Base64Encode(description) + ":" + account.SecretKey;
            string hash = HashingManager.SHA256(toHash).ToUpper();

            nvps.Append("m_shop", account.MerchantID)
            .Append("m_orderid", orderId)
            .Append("m_amount", amount.ToShortClearString())
            .Append("m_curr", AppSettings.Site.CurrencyCode)
            .Append("m_desc", HashingManager.Base64Encode(description))
            .Append("m_sign", hash);

            return(HandlerUrl + '?' + nvps.Build());
        }
Exemplo n.º 3
0
        protected override string generate(string itemName, Money amount, string command, object[] args)
        {
            //FOR BTC MIN AMOUNT IS 0.001
            try
            {
                var ApiKey    = account.APIKey;
                var ApiSecret = account.APISecret;
                var clientAPI = new LocalBitcoinsAPI(ApiKey, ApiSecret);

                var currencyCode = AppSettings.Site.CurrencyCode;
                //command#args
                var     customFields  = string.Join(ArgsDelimeter.ToString(), args);
                var     hashingValues = HashingManager.Base64Encode(command + joinSymbol + customFields);
                decimal finalAmount;
                if (AppSettings.Site.CurrencyCode != "BTC")
                {
                    finalAmount = Convert.ToDecimal(amount.ToShortClearString());
                }
                else
                {
                    finalAmount = Convert.ToDecimal(amount.ToClearString());
                }

                var createdInvoiceDetails = clientAPI.NewInvoice(currencyCode, finalAmount, hashingValues, SUCCESS_URL).ToString();
                var data = JObject.Parse(createdInvoiceDetails);

                return(data.data.invoice.url);
            }
            catch (Exception e)
            {
                throw new MsgException(e.Message);
            }
        }
Exemplo n.º 4
0
    public dynamic CreatePayment(string username, string phoneNumber, decimal amount)
    {
        using (WebClient client = new WebClient())
        {
            try
            {
                var url            = CreateURL("pay");
                var webRequest     = (HttpWebRequest)WebRequest.Create(url);
                var responseString = string.Empty;
                //requestId - max 40 chars
                var requestId      = HashingManager.Base64Encode(AppSettings.ServerTime.TimeOfDay.ToString());
                var counterpartyId = AddCounterparty(username, phoneNumber);
                var description    = "test";
                var handlerUrl     = string.Format("{0}Handlers/Revolut.ashx", AppSettings.Site.Url);

                dynamic receiverInfo = new JObject
                {
                    { "counterparty_id", counterpartyId },
                    { "account_id", GetAccount().Id }
                };

                var dataToSend = new JObject
                {
                    { "request_id", requestId },
                    { "account_id", GetAccount().Id },  // the ID of the account to pay from
                    { "receiver", receiverInfo },
                    { "amount", amount },
                    { "currency", AppSettings.Site.CurrencyCode },
                    { "description", description }
                    //{ "webhook", handlerUrl }
                };

                ErrorLogger.Log(dataToSend.ToString());

                webRequest.Method = "POST";
                webRequest.Headers.Add("Authorization", " Bearer " + APIKey);

                using (var stream = new StreamWriter(webRequest.GetRequestStream()))
                {
                    stream.Write(dataToSend);
                }

                using (var response = (HttpWebResponse)webRequest.GetResponse())
                    using (var stream = response.GetResponseStream())
                        using (var reader = new StreamReader(stream))
                        {
                            responseString = reader.ReadToEnd();
                        }

                return(JsonConvert.DeserializeObject <dynamic>(responseString));
            }
            catch (WebException ex)
            {
                ErrorLogger.Log(ex);
                var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                throw new MsgException(resp);
            }
        }
    }
Exemplo n.º 5
0
        public override void ProcessRequest()
        {
            string pre1 = context.Request["pre1"];
            string pre2 = context.Request["pre2"];

            pre1 = HashingManager.Base64Decode(pre1);
            string orderId    = pre1.Split('+')[0];
            string statusCode = pre1.Split('+')[1];

            string key = orderId + "+" + statusCode;

            key = HashingManager.Base64Encode(key);
            string md5String = HashingManager.GenerateMD5(key + PaparaAccountDetails.GetSecretKey());

            //Papara transaction OK check
            if (md5String == pre2)
            {
                //Set variables
                OrderID = orderId;

                try
                {
                    PaparaOrder Order = PaparaOrder.Get(Convert.ToInt32(OrderID));

                    Args          = Order.Args;
                    TransactionID = OrderID;
                    Amount        = Order.Amount.ToShortClearString();
                    CommandName   = Order.CommandName;

                    //Check duplicated transactions
                    CheckIfNotDoneYet(OrderID);

                    //All OK, let's proceed
                    Assembly    assembly = Assembly.GetAssembly(typeof(IIpnHandler));
                    var         type     = assembly.GetType(CommandName, true, true);
                    IIpnHandler command  = Activator.CreateInstance(type) as IIpnHandler;

                    command.HandlePapara(Args, TransactionID, Amount);

                    Order.IsPaid = true;
                    Order.Save();

                    context.Response.Redirect(ButtonGenerationStrategy.SUCCESS_URL);
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                    context.Response.Redirect(ButtonGenerationStrategy.FAILURE_URL);
                }
            }
            else
            {
                context.Response.Redirect(ButtonGenerationStrategy.FAILURE_URL);
            }
        }
Exemplo n.º 6
0
        public string GetToken()
        {
            string EndUrl = String.Format("{0}/v1/oauth2/token?grant_type=client_credentials", EndPointUrl);
            string valuesToCreateToken = String.Format("{0}:{1}", accountDetails.ClientId, accountDetails.ClientSecret);
            string PreAccessToken      = HashingManager.Base64Encode(valuesToCreateToken);

            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Authorization", "Basic " + PreAccessToken);
                client.Headers.Add("Content-Type", "application/json");
                JObject TokenJson = JObject.Parse(client.UploadString(EndUrl, ""));
                return(TokenJson["accessToken"].ToString());
            }
        }
Exemplo n.º 7
0
        public override string Generate()
        {
            string itemName            = string.Format("Buy {0} x {1} from Marketplace ({2})", quantity, product.Title, Amount);
            string emailWithPromotorId = HashingManager.Base64Encode(email) + "#" + HashingManager.Base64Encode(promotorId.ToString());

            return(Strategy.Generate(
                       itemName: itemName,
                       amount: Amount,
                       handlerCommand: typeof(BuyMarketplaceProductIpnHandler),
                       args: new object[]
            {
                Username,
                productId,
                this.Strategy.ToString(),
                quantity,
                deliveryAddress,
                emailWithPromotorId
            }));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates some general payza button
        /// </summary>
        /// <param name="itemName">Name describing the item or service. Max Length: 50 characters</param>
        /// <param name="amount">The price or cost of the product or service. The value for
        /// amount must be positive. Null or negative numbers are not allowed.</param>
        /// <param name="command">Describes how handler should handle IPN request.
        /// Stored in field apc_1. Max Length: 100 characters</param>
        /// <param name="args">
        /// Custom values you can pass along with the payment button.
        /// The values are not displayed to the payer on our Pay Process page.
        /// Payza returns these fields back in the IPN.
        /// Used by IIpnHandler ('command')
        /// Stored in fields apc_2 - apc_6. Max Length: 100 characters
        /// </param>
        /// <returns>Http address where member should be redirected after clicking button.</returns>
        protected override string generate(string itemName, Money amount, string command, object[] args)
        {
            string orderId = HashingManager.GenerateMD5(AppSettings.Site.Name + DateTime.Now).ToLower();

            NVPStringBuilder nvps = new NVPStringBuilder();

            nvps.Append("ok_receiver", account.Username)
            .Append("ok_item_1_name", itemName)
            .Append("ok_item_1_price", amount.ToShortClearString())
            .Append("ok_currency", AppSettings.Site.CurrencyCode)
            .Append("ok_fees", "1")
            .Append("ok_invoice", orderId)
            .Append("ok_item_1_custom_1_title", "command")
            .Append("ok_item_1_custom_1_value", command)
            .Append("ok_item_1_custom_2_title", "args")
            .Append("ok_item_1_custom_2_value", HashingManager.Base64Encode(String.Join(ArgsDelimeter + "", args)));

            return(Handler + '?' + nvps.Build());
        }