Beispiel #1
0
 /*
  * Get default signature version for this API Type
  *
  * @return int
  */
 public int GetDefaultSignatureVersion()
 {
     if (PWWidget.GetApiType() != PWWidget.API_CART)
     {
         return(PWWidget.DEFAULT_SIGNATURE_VERSION);
     }
     else
     {
         return(PWWidget.SIGNATURE_VERSION_2);
     }
 }
Beispiel #2
0
        /**
         * Build signature for the widget specified
         *
         * @param Dictionary<string, string> parameters
         * @param string secret Paymentwall Secret Key
         * @param int version Paymentwall Signature Version
         * @return string
         */
        public static string CalculateSignature(Dictionary <string, string> parameters, string secret, int version)
        {
            string baseString = "";

            if (version == PWWidget.SIGNATURE_VERSION_1)     //TODO: throw exception if no uid parameter is present
            {
                if (parameters["uid"] != null)
                {
                    baseString += parameters["uid"];
                }
                else
                {
                    baseString += secret;
                }
                return(PWWidget.getHash(baseString, "md5"));
            }
            else
            {
                parameters = parameters.OrderBy(d => d.Key, StringComparer.Ordinal).ToDictionary(d => d.Key, d => d.Value);

                foreach (KeyValuePair <string, string> param in parameters)
                {
                    baseString += param.Key + "=" + param.Value;
                }
                baseString += secret;

                if (version == PWWidget.SIGNATURE_VERSION_2)
                {
                    return(PWWidget.getHash(baseString, "md5"));
                }
                else
                {
                    return(PWWidget.getHash(baseString, "sha256"));
                }
            }
        }
Beispiel #3
0
        /**
         * Return HTML code for the widget
         *
         * @param Dictionary<string, string> attributes associative array of additional HTML attributes, e.g. Dictionary.Add("width", "100%")
         * @return string
         */
//        public string getHtmlCode(Dictionary<string, string> attributes = null)
//        {
//            Dictionary<string, string> defaultAttributes = new Dictionary<string, string>();
//            defaultAttributes.Add("frameborder", "0");
//            defaultAttributes.Add("width", "750");
//            defaultAttributes.Add("height", "800");
//            if (attributes != null)
//            {
//                attributes = mergeDictionaries(defaultAttributes, attributes);
//            }
//            else
//            {
//                attributes = defaultAttributes;
//            }
//            var attributesQuery = this.buildQueryString(attributes, " ");
//            return "<iframe src='" + this.getUrl() + "' " + attributesQuery + "></iframe>";
//        }


        /**
         * Build controller URL depending on API type
         *
         * @param string widget code of the widget
         * @param bool flexibleCall
         * @return string
         */
        protected string BuildController(string widget, bool flexibleCall = false)
        {
            if (PWWidget.GetApiType() == PWWidget.API_VC)
            {
                if (!Regex.IsMatch(widget, @"^w|s|mw"))
                {
                    return(PWWidget.CONTROLLER_PAYMENT_VIRTUAL_CURRENCY);
                }
                else
                {
                    return("");
                }
            }
            else if (PWWidget.GetApiType() == PWWidget.API_GOODS)
            {
                if (!flexibleCall)
                {
                    if (!Regex.IsMatch(widget, @"^w|s|mw"))
                    {
                        return(PWWidget.CONTROLELR_PAYMENT_DIGITAL_GOODS);
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    return(PWWidget.CONTROLELR_PAYMENT_DIGITAL_GOODS);
                }
            }
            else
            {
                return(PWWidget.CONTROLLER_PAYMENT_CART);
            }
        }
Beispiel #4
0
 public PWUnityWidget(PWWidget widget)
 {
     this._widget = widget;
 }
Beispiel #5
0
        /*
         * Return URL for the widget
         *
         * @return string
         */
        public string GetUrl()
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["key"]    = PWWidget.GetAppKey();
            parameters["uid"]    = this.userId;
            parameters["widget"] = this.widgetCode;

            int productsNumber = this.products.Count;

            if (PWWidget.GetApiType() == PWWidget.API_GOODS)
            {
                if (productsNumber > 0)
                {
                    if (productsNumber == 1)
                    {
                        PWProduct product          = this.products[0];
                        PWProduct postTrialProduct = null;
                        if (product.GetTrialProduct() is PWProduct)
                        {
                            postTrialProduct = product;
                            product          = product.GetTrialProduct();
                        }
                        parameters.Add("amount", product.GetAmount().ToString());
                        parameters.Add("currencyCode", product.GetCurrencyCode());
                        parameters.Add("ag_name", product.GetName());
                        parameters.Add("ag_external_id", product.GetId());
                        parameters.Add("ag_type", product.GetProductType());

                        if (product.GetProductType() == PWProduct.TYPE_SUBSCRIPTION)
                        {
                            parameters.Add("ag_period_length", product.GetPeriodLength().ToString());
                            parameters.Add("ag_period_type", product.GetPeriodType());

                            if (product.IsRecurring())
                            {
                                parameters.Add("ag_recurring", (Convert.ToInt32(product.IsRecurring())).ToString());

                                if (postTrialProduct != null)
                                {
                                    parameters.Add("ag_trial", "1");
                                    parameters.Add("ag_post_trial_external_id", postTrialProduct.GetId());
                                    parameters.Add("ag_post_trial_period_length", postTrialProduct.GetPeriodLength().ToString());
                                    parameters.Add("ag_post_trial_period_type", postTrialProduct.GetPeriodType());
                                    parameters.Add("ag_post_trial_name", postTrialProduct.GetName());
                                    parameters.Add("post_trial_amount", postTrialProduct.GetAmount().ToString());
                                    parameters.Add("post_trial_currencyCode", postTrialProduct.GetCurrencyCode().ToString());
                                }
                            }
                        }
                    } //end if (productNumber == 1)
                    else
                    {
                        //TODO: Paymentwall_Widget.appendToErrors('Only 1 product is allowed in flexible widget call');
                    }
                } //end if (productNumber > 0)
            }
            else if (PWWidget.GetApiType() == PWWidget.API_CART)
            {
                int index = 0;

                foreach (PWProduct product in this.products)
                {
                    parameters.Add("external_ids[" + index.ToString() + "]", product.GetId());

                    if (product.GetAmount() != -1f)
                    {
                        parameters.Add("prices[" + index.ToString() + "]", product.GetAmount().ToString());
                    }

                    if (product.GetCurrencyCode() != null)
                    {
                        parameters.Add("currencies[" + index.ToString() + "]", product.GetCurrencyCode());
                    }

                    index++;
                }

                index = 0;
            }

            int signatureVersion = this.GetDefaultSignatureVersion();

            parameters.Add("sign_version", Convert.ToString(signatureVersion));

            if (this.extraParams.ContainsKey("sign_version"))
            {
                parameters["sign_version"] = this.extraParams["sign_version"];
                signatureVersion           = Convert.ToInt32(this.extraParams["sign_version"]);
            }
            parameters = MergeDictionaries(parameters, extraParams);

            parameters["sign"] = PWWidget.CalculateSignature(parameters, PWWidget.GetSecretKey(), signatureVersion);

            return(PWWidget.BASE_URL + "/" + this.BuildController(this.widgetCode) + "?" + this.BuildQueryString(parameters, "&"));
        }