Hi to all,
I have one class. That i have to convert to Custom control. Just I took one webcontrol library .For that i have to create form tag at runtime.How to write javascript for that. The following is my class. Check the PayNow() and answer me.
public string PayNow()
{
string modify = string.Empty;
if (CanUserModifySubscription)
modify = "1";
else
modify = "0";
StringBuilder paypalJavascript = new StringBuilder();
if (SubmitPaypal)
{
paypalJavascript.Append("<form id="\"stockhaltPaypal\"" method="\"post\"" action=");<br mode=" hold=" /"> if (EnableSandboxMode)
paypalJavascript.Append(SandboxUrl);
else
paypalJavascript.Append(PaypalUrl);
paypalJavascript.AppendLine(">");
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "cmd", Command, Environment.NewLine);
if (EnableSandboxMode)
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "business", SandboxBusinessEmail, Environment.NewLine);
else
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "business", BusinessEmail, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "item_name", SubscriptionItemName, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "item_number", SubscriptionItemNumber, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "no_shipping", "1", Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "return", SuccessUrl, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "cancel_return", CancelUrl, Environment.NewLine);
if (TrialSubscriptionPeriod != 0)
{
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "a1", TrialSubscriptionAmount.ToString("0.00"), Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "p1", TrialSubscriptionPeriod.ToString(), Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "t1", TrialSubscriptionPeriodUnits.ToString(), Environment.NewLine);
}
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "a3", RegularSubscriptionAmount.ToString("0.00"), Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "p3", RegularSubscriptionPeriod.ToString(), Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "t3", RegularSubscriptionPeriodUnits.ToString(), Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "src", RecurAutomatically, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "sra", ReattemptPaymentOnFailure, Environment.NewLine);
if(!string.IsNullOrEmpty(CustomField))
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "custom", CustomField, Environment.NewLine);
if (!string.IsNullOrEmpty(OptionFieldName1) && !string.IsNullOrEmpty(OptionFieldValue1))
{
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "on0", OptionFieldName1, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "os0", OptionFieldValue1, Environment.NewLine);
}
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "no_note", "1", Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "currency_code", CurrencyCode, Environment.NewLine);
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "rm","2", Environment.NewLine);
if (!string.IsNullOrEmpty(NotifyUrl))
paypalJavascript.AppendFormat("<input type="\"hidden\"" name="\"{0}\"" value="\"{1}\"">{2}", "notify_url", NotifyUrl, Environment.NewLine);
paypalJavascript.AppendLine("</input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></input></form>");
paypalJavascript.AppendLine("<script type="\"text/javascript\"" language="\"javascript\"">document.forms[\"stockhaltPaypal\"].submit();</script>");
return paypalJavascript.ToString();
}
else
{
paypalJavascript.AppendLine("<span id="\"stockhaltnolink\""></span>");
return paypalJavascript.ToString();
}
}
}
Thanks & Regards
satish
|