public Hashtable BitcoinInitializePaymentPage(Hashtable request)
{
Dictionary<string, object> postvals = ServerUtils.ParseQueryString ((string)request["body"]);
UUID txnID = new UUID ((string)postvals["txn"]);
if (!m_transactionsInProgress.ContainsKey (txnID)) {
Hashtable ereply = new Hashtable ();
ereply["int_response_code"] = 404;
// 200 OK
ereply["str_response_string"] = "Invalid Transaction";
ereply["content_type"] = "text/html";
return ereply;
}
FreeMoneyTransaction txn = m_transactionsInProgress[txnID];
string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;
bool has_errors = false;
BitcoinTransaction btc_trans = InitializeBitcoinTransaction(txn, baseUrl);
has_errors = btc_trans.HasErrors();
if (has_errors) {
string error_message = "<p><strong>Sorry, I couldn't set up this payment.</strong></p>";
return ShowUserPage(request, baseUrl, txn, error_message);
}
string user_identifier = txn.From.ToString();
BitcoinAddress count_btc_addr = new BitcoinAddress(m_connectionString, m_btcconfig);
int count_all_addresses = count_btc_addr.CountAddressesForAvatar(user_identifier, true);
int count_usable_addresses = count_btc_addr.CountAddressesForAvatar(user_identifier, false);
Dictionary<string, string> replacements = new Dictionary<string, string> ();
//replacements.Add ("{BTC_SESSION_ID}", HttpUtility.HtmlEncode(btc_session_id));
//TODO put HttpUtility back
replacements.Add ("{BTC_SESSION_ID}", GetSessionKey( txn.From ).ToString());
bool is_submit = true; // TODO
if (is_submit) {
replacements.Add ("{BTC_ERRORS}", "");
replacements.Add ("{BTC_DISABLE_COMPLETE_START}", "<!--");
replacements.Add ("{BTC_DISABLE_COMPLETE_END}", "-->");
replacements.Add ("{BTC_DISABLE_INCOMPLETE_START}", "");
replacements.Add ("{BTC_DISABLE_INCOMPLETE_END}", "");
} else {
replacements.Add ("{BTC_ERRORS}", "");
replacements.Add ("{BTC_DISABLE_INCOMPLETE_START}", "<!--");
replacements.Add ("{BTC_DISABLE_INCOMPLETE_END}", "-->");
replacements.Add ("{BTC_DISABLE_COMPLETE_START}", "");
replacements.Add ("{BTC_DISABLE_COMPLETE_END}", "");
}
replacements.Add ("{BTC_AMOUNT}", btc_trans.GetBTCAmount().ToString());
replacements.Add ("{BTC_ADDRESS}", btc_trans.GetBTCAddress().ToString());
replacements.Add ("{BTC_COUNT_ALL_ADDRESSES}", count_all_addresses.ToString());
replacements.Add ("{BTC_COUNT_USABLE_ADDRESSES}", count_usable_addresses.ToString());
string template;
string template_name = "bitcoin-pay-template.htm";
try {
template = File.ReadAllText (template_name);
} catch (IOException) {
template = "Error: bitcoin-pay-template.htm does not exist.";
//m_log.Error ("[FreeMoney] Unable to load template file.");
m_log.Error("[FreeMoney] Could not load template file bitcoin-pay-template.htm");
has_errors = true;
}
int response_code = has_errors ? 400 : 200;
foreach (KeyValuePair<string, string> pair in replacements) {
template = template.Replace (pair.Key, pair.Value);
}
Hashtable reply = new Hashtable ();
reply["int_response_code"] = 200;
// 200 OK
reply["str_response_string"] = template;
reply["content_type"] = "text/html";
return reply;
}