protected void UpdateRecord(string PayPalStatus, string mailToName, string Address, string Address1, string City, string State, string Zip, string Note, string PP_PaymentId, string PP_Response)
        {
            try
            {
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = new GiftCertificateInfo();

                item.ItemId             = Convert.ToInt32(Request.QueryString["itemId"].ToString());// itemId;
                item.MailTo             = mailToName;
                item.MailToAddress      = Address;
                item.MailToAddress1     = Address1;
                item.MailToCity         = City;
                item.MailToState        = State;
                item.MailToZip          = Zip;
                item.Notes              = Note;
                item.PaypalPaymentState = PayPalStatus;
                item.PP_PaymentId       = PP_PaymentId;
                item.PP_Response        = PP_Response;
                controller.GiftCertUpdateWithPayPalReponse(item);
                //if (cbxEmailPurchaser.Checked)
                //{
                //  EmailPurchaser();
                //}
                //Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "List", "mid=" + ModuleId.ToString()), true);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        public void GetGiftCertRecord(int itemID)
        {
            try
            {
                //check we have an item to lookup
                if (!Null.IsNull(itemId))
                {
                    //load the item
                    GiftCertificateController controller = new GiftCertificateController();
                    item = controller.GetGiftCert(itemId);
                    if (item != null)
                    {
                        if (item.PaypalPaymentState.ToString().Length > 0)
                        {
                            Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                        }

                        TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

                        //NumberToWords(Int32.Parse(item.CertAmount.ToString())).ToString()

                        lblCertAmount.Text = String.Format("{0:f2}", item.CertAmount) + " - " + textInfo.ToTitleCase(NumberToWords(Int32.Parse(item.CertAmount.ToString())).ToString()).ToString() + " Dollars";
                        lblRecipient.Text  = item.ToName;
                        lblPurchaser.Text  = item.FromName + "<br />" + item.FromEmail + "<br />" + item.FromPhone;
                        lblMailingTo.Text  = item.MailTo + "<br />" + item.MailToAddress;
                        if (item.MailToAddress1.ToString().Length > 0)
                        {
                            lblMailingTo.Text += "<br />" + item.MailToAddress1;
                        }

                        lblMailingTo.Text += "<br />" + item.MailToCity + ", " + item.MailToState + " " + item.MailToZip;
                        string MailAddress = "";
                        MailAddress   = item.ToName + Environment.NewLine + item.MailToAddress + " " + item.MailToAddress1 + Environment.NewLine + item.MailToCity + ", " + item.MailToState + " " + item.MailToZip;
                        lblNotes.Text = item.Notes;
                    }
                    else
                    {
                        Response.Redirect(Globals.NavigateURL(), true);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = new GiftCertificateInfo();

                item.IsProcessed     = Convert.ToBoolean(isProcessed.SelectedValue.ToString());
                item.ItemId          = itemId;
                item.ModuleId        = this.ModuleId;
                item.UpdatedByUserID = this.UserId;
                item.ToName          = txtRecipientName.Text.ToString();
                item.CertAmount      = Convert.ToDouble(txtCertAmount.Text.ToString());
                item.MailTo          = txtMailToName.Text.ToString();
                item.MailToAddress   = txtToAddress.Text.ToString();
                item.MailToAddress1  = txtToAddress1.Text.ToString();
                item.MailToCity      = txtToCity.Text.ToString();
                item.MailToState     = ddlStatesRecipient.SelectedValue.ToString();
                item.MailToZip       = txtToZip.Text.ToString();

                item.MailTo   = txtMailToName.Text.ToString();
                item.FromName = txtFromName.Text.ToString();

                item.FromPhone = txtFromPhone.Text.ToString();
                item.FromEmail = txtFromEmail.Text.ToString();


                item.Notes = txtSpecialInstructions.Text.ToString();

                controller.GiftCertUpdateGiftCert(item);
                //.UpdateGiftCert(item);
                // Response.Redirect("MakePayment.aspx", true);

                if (cbxEmailPurchaser.Checked)
                {
                    EmailPurchaser();
                }
                //Response.Redirect(Globals.NavigateURL(), true);
                Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "List", "mid=" + ModuleId.ToString()), true);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Esempio n. 4
0
        public void GetGiftCertRecord(int itemID)
        {
            try
            {
                //check we have an item to lookup
                if (!Null.IsNull(itemId))
                {
                    //load the item
                    GiftCertificateController controller = new GiftCertificateController();
                    GiftCertificateInfo       item       = controller.GetGiftCert(itemId);
                    if (item != null)
                    {
                        txtCertAmount.Text = String.Format("{0:f2}", item.CertAmount);

                        txtToName.Text     = item.ToName;
                        txtFromName.Text   = item.FromName;
                        txtFromEmail.Text  = item.FromEmail;
                        txtFromPhone.Text  = item.FromPhone;
                        txtMailToName.Text = item.MailTo;
                        txtToAddress.Text  = item.MailToAddress;
                        txtToAddress1.Text = item.MailToAddress1;
                        txtToCity.Text     = item.MailToCity;
                        ddlStatesRecipient.SelectedValue = item.MailToState;
                        txtToZip.Text = item.MailToZip;
                        txtNotes.Text = item.Notes;

                        Page.Validate();

                        if (item.PaypalPaymentState.ToString().Length > 0)
                        {
                            Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                        }
                    }
                    else
                    {
                        Response.Redirect(Globals.NavigateURL(), true);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            try
            {
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = new GiftCertificateInfo();

                item.ModuleId       = this.ModuleId;
                item.ItemId         = Convert.ToInt32(Request.QueryString["itemId"].ToString());// itemId;
                item.MailTo         = txtMailToName.Text.ToString();
                item.MailToAddress  = txtToAddress.Text.ToString();
                item.MailToAddress1 = txtToAddress1.Text.ToString();
                item.MailToCity     = txtToCity.Text.ToString();
                item.MailToState    = ddlStatesRecipient.SelectedValue.ToString();
                item.MailToZip      = txtToZip.Text.ToString();

                controller.GiftCertUpdateShipAddress(item);


                lblResults.Text  = "<b>Shipping Address Updated";
                lblResults.Text += "</b><br><br>The gift certificate will be mailed to: <br><br>" + txtMailToName.Text.ToString();
                lblResults.Text += "<br>" + txtToAddress.Text.ToString();
                if (txtToAddress1.Text.ToString().Length > 1)
                {
                    lblResults.Text += "<br>" + txtToAddress1.Text.ToString();
                }
                lblResults.Text += "<br>" + txtToCity.Text.ToString();
                lblResults.Text += ", " + ddlStatesRecipient.SelectedValue.ToString();
                lblResults.Text += " " + txtToZip.Text.ToString();

                SendGiftCertEmailAddressUpdated(Int32.Parse(Request.QueryString["itemId"].ToString()));
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                LoadSettings();
                if (_isAuthorized)
                {
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                }

                if (Request.QueryString["ItemId"] != null)
                {
                    itemId = Int32.Parse(Request.QueryString["ItemId"]);
                }

                if (!IsPostBack)
                {
                    //load the data into the control the first time
                    //we hit this page
                    GetDropDownLists();

                    LoadModuleTitle();



                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");

                    //check we have an item to lookup
                    if (!Null.IsNull(itemId))
                    {
                        //load the item
                        GiftCertificateController controller = new GiftCertificateController();
                        GiftCertificateInfo       item       = controller.GetGiftCert(itemId);

                        if (item != null)
                        {
                            //  Response.Write(item);

                            //lblMailToRec.Text = item.MailTo;
                            txtCertAmount.Text = String.Format("{0:f2}", item.CertAmount);


                            isProcessed.SelectedIndex = Convert.ToInt32(item.IsProcessed);


                            txtFromEmail.Text = item.FromEmail;
                            txtFromName.Text  = item.FromName;
                            txtFromPhone.Text = item.FromPhone;
                            ddlStatesRecipient.SelectedValue = item.MailToState;
                            txtMailToName.Text    = item.MailTo;
                            txtToAddress.Text     = item.MailToAddress;
                            txtToAddress1.Text    = item.MailToAddress1;
                            txtToCity.Text        = item.MailToCity;
                            txtToZip.Text         = item.MailToZip;
                            txtRecipientName.Text = item.ToName;

                            txtSpecialInstructions.Text = item.Notes;

                            txtPaypalPaymentStatee.Text = item.PaypalPaymentState.ToUpper();
                            if (txtPaypalPaymentStatee.Text.ToString() == "APPROVED")
                            {
                                lblOrderStatus.Text = "PAYMENT " + txtPaypalPaymentStatee.Text.ToString();
                            }

                            else
                            {
                                lblOrderStatus.Text = "<span style='color:Red;'>NO RECORD OF PAYMENT</span>";
                            }


                            txtPP_PaymentId.Text = item.PP_PaymentId;
                            txtPP_Response.Text  = item.PP_Response;

                            string MailAddress  = "";
                            string line2Address = "";
                            if (item.MailToAddress1.ToString().Length > 1)
                            {
                                line2Address = Environment.NewLine + item.MailToAddress1.ToString();
                            }
                            MailAddress = item.MailTo + Environment.NewLine + item.MailToAddress
                                          + line2Address.ToString()
                                          + Environment.NewLine + item.MailToCity + ", " + item.MailToState + " " + item.MailToZip;

                            txtMailingAddresses.Text = MailAddress.ToString();
                        }
                        else
                        {
                            Response.Redirect(Globals.NavigateURL(), true);
                        }
                    }
                    else
                    {
                        cmdDelete.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        public void SendGiftCertEmail(int _itemID)
        {
            try
            {
                //load the item
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = controller.GetGiftCert(_itemID);
                if (item != null)
                {
                    GiftCertificateSettings settingsData = new GiftCertificateSettings(this.TabModuleId);

                    string RedirectURL = "http://" + Request.Url.Host + "/Success/TabID/" + settingsData.RedirectPage + "/Default.aspx";

                    // BUILD E-MAIL BODY

                    string EmailContent = "";

                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("lblCertAmount.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + String.Format("{0:c}", item.CertAmount) + "<br />&nbsp;</dd>";

                    //       EmailContent += "<br clear=all>";

                    EmailContent += "<dt><strong>" + Localization.GetString("lblToName.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.ToName.ToString() + "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";

                    //     EmailContent += "<br clear=all>";

                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("lblFromName.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.FromName.ToString();
                    EmailContent += "<br>" + item.FromPhone.ToString();
                    EmailContent += "<br>" + item.FromEmail.ToString();
                    EmailContent += "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";



                    //      EmailContent += "<br clear=all>";


                    EmailContent += "<dl>";

                    EmailContent += "<dt><strong>" + Localization.GetString("lblMailTo.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.MailTo.ToString();

                    EmailContent += "<br>" + item.MailToAddress.ToString();
                    if (item.MailToAddress1.ToString().Length > 1)
                    {
                        EmailContent += "<br>" + item.MailToAddress1.ToString();
                    }
                    EmailContent += "<br>" + item.MailToCity.ToString() + ", " + item.MailToState.ToString() + " " + item.MailToZip.ToString();

                    EmailContent += "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";

                    //       EmailContent += "<br clear=all>";

                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("emailNotes.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.Notes.ToString() + "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";

                    EmailContent += "<p>Page Submitted: " + Globals.NavigateURL() + "</p>";

                    //EMAIL THE PURCHASER
                    string EmailFrom = "";
                    if (settingsData.EmailFrom.Length > 1)
                    {
                        EmailFrom = settingsData.EmailFrom.ToString();
                    }
                    else
                    {
                        EmailFrom = PortalSettings.Email.ToString();
                    }



                    // NEW

                    string SMTPUserName = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("SMTPUsername");


                    string[] emptyStringArray = new string[0];

                    DotNetNuke.Services.Mail.Mail.SendMail(SMTPUserName.ToString(), item.FromEmail.Trim().ToString(), "", "",
                                                           EmailFrom.ToString(), DotNetNuke.Services.Mail.MailPriority.Normal,
                                                           settingsData.EmailSubject.ToString(), DotNetNuke.Services.Mail.MailFormat.Html,
                                                           System.Text.Encoding.ASCII, EmailContent.ToString(), emptyStringArray,
                                                           "", "", "", "", true);


                    // EMAIL THE settingsData.EmailNotify
                    // ADD NOTE for ADMINS . . . .
                    EmailContent += "<p><b>Administrators must log in to process gift certificate.</b></p>";

                    if (settingsData.EmailNotify.Length > 1)
                    {
                        string   FromPurchaserEmail = item.FromEmail.ToString();
                        string   emailAddress       = settingsData.EmailNotify.Replace(" ", "");
                        string[] valuePair          = emailAddress.Split(new char[] { ';' });
                        //      string[] emailAttachemnts = null ;
                        for (int i = 0; i <= valuePair.Length - 1; i++)
                        {
                            DotNetNuke.Services.Mail.Mail.SendMail(SMTPUserName.ToString(), valuePair[i].Trim().ToString(), "", "",
                                                                   FromPurchaserEmail.ToString(), DotNetNuke.Services.Mail.MailPriority.Normal, "New Order - " +
                                                                   settingsData.EmailSubject.ToString(), DotNetNuke.Services.Mail.MailFormat.Html, System.Text.Encoding.ASCII,
                                                                   EmailContent.ToString(), emptyStringArray, "", "", "", "", true);
                            //MailFrom,             MailTo,                     Cc, Bcc,     ReplyTo,                                        Priority,                          Subject,           BodyFormat, BodyEncoding,           Body,                     Attachments, SMTPServer, SMTPAuthentication, SMTPUsername, SMTPPassword, SMTPEnableSSL
                        }
                    }



                    string TempAddUserRole = "";
                    if (settingsData.AddUserRole != null)
                    {
                        TempAddUserRole = settingsData.AddUserRole;
                    }

                    ////CREATE USER ACCOUNT
                    //if (settingsData.AddUserRole.Length > 0)
                    //{
                    //    CreateNewUser(txtFromName.Text, txtFromEmail.Text, TempAddUserRole);
                    //}


                    //if (settingsData.RedirectPage.Length > 0)
                    //{
                    //    Response.Redirect(RedirectURL.ToString(), true);
                    //    Response.Redirect(settingsData.RedirectPage, true);
                    //}
                    //else
                    //{
                    //    Response.Redirect(Globals.NavigateURL(), true);
                    //}
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL(), true);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        public void SendGiftCertEmailAddressUpdated(int _itemID)
        {
            try
            {
                //load the item
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = controller.GetGiftCert(_itemID);
                if (item != null)
                {
                    GiftCertificateSettings settingsData = new GiftCertificateSettings(this.TabModuleId);

                    string RedirectURL = "http://" + Request.Url.Host + "/Success/TabID/" + settingsData.RedirectPage + "/Default.aspx";

                    // BUILD E-MAIL BODY

                    string EmailContent = "";

                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("lblCertAmount.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + String.Format("{0:c}", item.CertAmount) + "<br />&nbsp;</dd>";


                    EmailContent += "<dt><strong>" + Localization.GetString("lblToName.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.ToName.ToString() + "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";

                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("lblFromName.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.FromName.ToString();
                    EmailContent += "<br>" + item.FromPhone.ToString();
                    EmailContent += "<br>" + item.FromEmail.ToString();
                    EmailContent += "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";


                    EmailContent += "<dl>";

                    EmailContent += "<dt><strong>" + Localization.GetString("lblMailTo.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.MailTo.ToString();

                    EmailContent += "<br>" + item.MailToAddress.ToString();
                    if (item.MailToAddress1.ToString().Length > 1)
                    {
                        EmailContent += "<br>" + item.MailToAddress1.ToString();
                    }
                    EmailContent += "<br>" + item.MailToCity.ToString() + ", " + item.MailToState.ToString() + " " + item.MailToZip.ToString();

                    EmailContent += "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";


                    EmailContent += "<dl>";
                    EmailContent += "<dt><strong>" + Localization.GetString("emailNotes.Text", LocalResourceFile) + "</strong></dt>";
                    EmailContent += "<dd>" + item.Notes.ToString() + "<br />&nbsp;</dd>";
                    EmailContent += "</dl>";

                    EmailContent += "<p>Page Submitted: " + Globals.NavigateURL() + "</p>";

                    //EMAIL THE PURCHASER
                    string EmailFrom = "";
                    if (settingsData.EmailFrom.Length > 1)
                    {
                        EmailFrom = settingsData.EmailFrom.ToString();
                    }
                    else
                    {
                        EmailFrom = PortalSettings.Email.ToString();
                    }
                    string SMTPUserName = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("SMTPUsername");

                    // string[] emailAttachemnts1 = null;
                    string[] emailAttachemnts1 = new string[0];
                    DotNetNuke.Services.Mail.Mail.SendMail(SMTPUserName.ToString(), item.FromEmail.ToString().Trim(), "", "",
                                                           EmailFrom.ToString(), DotNetNuke.Services.Mail.MailPriority.Normal,
                                                           "Address Correction - " + settingsData.EmailSubject.ToString(), DotNetNuke.Services.Mail.MailFormat.Html,
                                                           System.Text.ASCIIEncoding.ASCII, EmailContent.ToString(), emailAttachemnts1, string.Empty, string.Empty, string.Empty, string.Empty, true);


                    //     DotNetNuke.Services.Mail.Mail.SendMail(EmailFrom.ToString(), item.FromEmail.ToString(), "", "Address Correction - " + settingsData.EmailSubject, EmailContent.ToString(), "", "HTML", "", "", "", "");


                    // EMAIL THE settingsData.EmailNotify
                    // ADD NOTE for ADMINS . . . .
                    EmailContent += "<p><b>Administrators must log in to process gift certificate.</b></p>";

                    if (settingsData.EmailNotify.ToString().Length > 1)
                    {
                        string   FromPurchaserEmail = item.FromEmail.ToString();
                        string   emailAddress       = settingsData.EmailNotify.Replace(" ", "");
                        string[] valuePair          = emailAddress.Split(new char[] { ';' });

                        //string SMTPUserName = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("SMTPUsername");
                         

                        for (int i = 0; i <= valuePair.Length - 1; i++)
                        {
                            //  DotNetNuke.Services.Mail.Mail.SendMail(FromPurchaserEmail, valuePair[i].ToString().Trim(), "", "Address Correction - " + settingsData.EmailSubject, EmailContent.ToString(), "", "HTML", "", "", "", "");
                            DotNetNuke.Services.Mail.Mail.SendMail(SMTPUserName.ToString(),
                                                                   valuePair[i].ToString().Trim(), "", "",
                                                                   FromPurchaserEmail.ToString(), DotNetNuke.Services.Mail.MailPriority.Normal,
                                                                   "Address Correction - " + settingsData.EmailSubject, DotNetNuke.Services.Mail.MailFormat.Html,
                                                                   System.Text.Encoding.Default, EmailContent.ToString(), emailAttachemnts1, "", "", "", "", true);
                        }
                    }
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL(), true);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Esempio n. 9
0
        public int AddNewGiftCert()
        {
            try
            {
                GiftCertificateController controller = new GiftCertificateController();
                GiftCertificateInfo       item       = new GiftCertificateInfo();



                item.CertAmount = Convert.ToDouble(txtCertAmount.Text.ToString().Replace("$", "").ToString());
                item.ToName     = txtToName.Text.ToString();
                // item.MailToAddress
                item.MailToAddress  = txtToAddress.Text.ToString();
                item.MailToAddress1 = txtToAddress1.Text.ToString();
                item.MailToCity     = txtToCity.Text.ToString();
                item.MailToState    = ddlStatesRecipient.SelectedValue.ToString();
                item.MailToZip      = txtToZip.Text.ToString();

                item.MailTo = txtMailToName.Text.ToString();

                item.FromUserID = this.UserId;
                item.FromName   = txtFromName.Text.ToString();

                item.FromPhone = txtFromPhone.Text.ToString();
                item.FromEmail = txtFromEmail.Text.ToString();

                item.Notes = txtNotes.Text.ToString();

                item.ModuleId        = this.ModuleId;
                item.CreatedByUserID = this.UserId;
                item.UpdatedByUserID = this.UserId;

                // ADD THE RECORD
                int MyNewID = Null.NullInteger;

//                if (!Null.IsNull(itemId))
                if (itemId > 0)
                {
                    MyNewID          = itemId;
                    item.ItemId      = itemId;
                    item.IsProcessed = false;
                    //    item.UpdatedByUserID = this.UserId;

                    controller.GiftCertUpdateGiftCert(item);
                }

                else
                {
                    MyNewID = controller.GiftCertAddGiftCert(item);
                }



                //    string myNewGiftCertID = Convert.ToString(MyNewID);

                return(MyNewID);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
                return(0);
            }
        }
        protected void CreateLink(GiftCertificateInfo item, bool sendShippingAddress)
        {
            //Components.Configuration mySettings = new Components.Configuration();
            //mySettings.SandboxMode = _PayPalSandboxMode;

            var    apiContext = GIBS.Modules.GiftCertificate.Components.Configuration.GetAPIContext();
            string payerId    = Request.Params["PayerID"];

            if (string.IsNullOrEmpty(payerId))
            {
                var itemList = new ItemList();
                if (sendShippingAddress == true)
                {
                    itemList = new ItemList()
                    {
                        items = new List <Item>()
                        {
                            new Item()
                            {
                                name     = this.PortalSettings.PortalName.ToString() + " Gift Certificate",
                                currency = "USD",
                                price    = item.CertAmount.ToString(),
                                quantity = "1",
                                sku      = "GiftCertificate"
                            }
                        }
                        //,
                        //shipping_address = new ShippingAddress()
                        //{
                        //    city = item.MailToCity,
                        //    country_code = "US",
                        //    line1 = item.MailToAddress,
                        //    line2 = item.MailToAddress1,
                        //    postal_code = item.MailToZip,
                        //    state = item.MailToState,
                        //    recipient_name = item.ToName
                        //}
                    };
                }
                else
                {
                    itemList = new ItemList()
                    {
                        items = new List <Item>()
                        {
                            new Item()
                            {
                                name     = "Gift Certificate",
                                currency = "USD",
                                price    = item.CertAmount.ToString(),
                                quantity = "1",
                                sku      = "GiftCertificate"
                            }
                        }
                    };
                }



                var payer = new Payer()
                {
                    payment_method = "paypal"
                };
                //        lblCertAmount.Text = String.Format("{0:f2}", item.CertAmount);
                // ###Redirect URLS
                var baseURI     = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "PayPalParse", "mid=" + ModuleId.ToString()) + "?userId=" + UserId.ToString();
                var guid        = Convert.ToString((new Random()).Next(100000));
                var redirectUrl = baseURI + "&guid=" + guid + "&itemId=" + Convert.ToInt32(itemId);
                var redirUrls   = new RedirectUrls()
                {
                    cancel_url = redirectUrl + "&cancel=true",
                    return_url = redirectUrl
                };
                // ###Details
                // Let's you specify details of a payment amount.
                var details = new Details()
                {
                    tax      = "0",
                    shipping = "0",
                    subtotal = item.CertAmount.ToString()
                };
                // ###Amount
                // Let's you specify a payment amount.
                var amount = new Amount()
                {
                    currency = "USD",
                    total    = item.CertAmount.ToString(), // Total must be equal to sum of shipping, tax and subtotal.
                    details  = details
                };

                var _payee = new Payee();
                _payee.email = _PayPalPayee.ToString();     // "*****@*****.**";

                // ###Transaction
                // A transaction defines the contract of a
                // payment - what is the payment for and who
                // is fulfilling it.
                var transactionList = new List <Transaction>();
                // The Payment creation API requires a list of
                // Transaction; add the created `Transaction`
                // to a List
                transactionList.Add(new Transaction()
                {
                    payee          = _payee,
                    note_to_payee  = lblNotes.Text.ToString(),
                    description    = "Transaction description.",
                    invoice_number = Common.GetRandomInvoiceNumber(),
                    amount         = amount,
                    item_list      = itemList
                });
                // ###Payment
                var payment = new Payment()
                {
                    intent = "sale",
                    payer  = payer,

                    transactions  = transactionList,
                    redirect_urls = redirUrls
                };
                //Create a payment using a valid APIContext
                try
                {
                    var createdPayment = payment.Create(apiContext);
                    //       lblDebug.Text += " Response from Create: " + createdPayment.ConvertToJson();
                    // Using the `links` provided by the `createdPayment` object, we can give the user the option to redirect to PayPal to approve the payment.
                    var links = createdPayment.links.GetEnumerator();
                    while (links.MoveNext())
                    {
                        var link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //   flowGo.Text = "Complete Payment";
                            flowGo.NavigateUrl = link.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                }
                catch (PayPal.HttpException pp)
                {
                    CreateLink(item, false);
                    //lblDebug.Text += "pp message : " + pp.Message.ToString();
                    //lblDebug.Text += "pp message : " + pp.InnerException.ToString();
                    //lblDebug.Text += "pp message : " + pp.Response.ToString();
                }
            }
        }