コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //testing query functionality
            Query query = new Query();

            query.InitializeValues((string)Session["Stamp"], (string)Session["Reference"],
                                   this.merchantId, (string)Session["Amount"], this.merchantSecretKey);

            //send Query to Checkout Finland
            string queryResponse = "";

            try
            {
                queryResponse = CheckoutClient.postQueryData(query.FormData());
            }
            catch (WebException ex)
            {
                //exception handling for testing
                string errorMessage = ex.ToString();
                errorMessage = (errorMessage.Length > 1000) ? errorMessage.Substring(0, 1000) : errorMessage;
                Response.Redirect("~/PaymentErrorWebForm.aspx?error=" + HttpUtility.UrlEncode(errorMessage));
            }

            XDocument xmlDoc      = XDocument.Parse(queryResponse);
            XElement  statusNode  = (XElement)xmlDoc.FirstNode;
            string    statusValue = statusNode.Value;

            this.queryResponseMessage.Text =
                PaymentUtils.GetPaymentResponseStatusMessage(statusValue);
            XElement tradeElem  = (XElement)xmlDoc.FirstNode;
            XElement statusElem = (XElement)tradeElem.FirstNode;

            this.tradeBegin.Text  = tradeElem.Name.ToString();
            this.tradeEnd.Text    = tradeElem.Name.ToString();
            this.statusBegin.Text = statusElem.Name.ToString();
            this.statusEnd.Text   = statusElem.Name.ToString();
            this.statusValue.Text = statusElem.Value;
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                //the below creates for example
                //URL: http://localhost:53416/PaymentResponseWebForm.aspx";
                string urlBeginning = this.TestUrl();
                string returnURL    = urlBeginning + "/PaymentResponseWebForm.aspx";
                string cancelURL    = urlBeginning + "/PaymentResponseWebForm.aspx";
                string rejectURL    = urlBeginning + "/PaymentResponseWebForm.aspx";
                string delayedURL   = urlBeginning + "/PaymentResponseWebForm.aspx";

                //Create Payment
                Payment payment = new Payment();

                //set merchant data (required)
                payment.InitializeValues(merchantId, merchantSecretKey);

                //other required parameters
                payment.Stamp = DateTime.Now.ToString("MMddyyyyhhmmssfff");
                string modifiedAmount = PaymentUtils.ModifyAmount(this.AmountTextBox.Text); // remove comma or dot
                payment.Amount       = modifiedAmount;                                      // 1 Euro minimum purchase (100 cents)
                Session["Amount"]    = modifiedAmount;                                      //store Amount in Session for Query (just for testing)
                payment.Reference    = "123456";
                payment.ReturnUrl    = returnURL;
                payment.CancelUrl    = cancelURL;
                payment.DeliveryDate = DateTime.Now.ToString("yyyyMMdd");

                payment.Language = this.LanguageDropDownList.SelectedValue; // (required param)
                payment.Country  = "FIN";                                   // (required)

                payment.Device = this.DeviceDropDownList.SelectedValue;     //HTML or XML

                //Optional
                payment.RejectUrl  = rejectURL;
                payment.DelayedUrl = delayedURL;
                payment.FirstName  = this.FirstNameTextBox.Text;
                payment.FamilyName = this.FamilyNameTextBox.Text;
                payment.Address    = this.AddressTextBox.Text;
                payment.Postcode   = this.PostcodeTextBox.Text;
                payment.PostOffice = this.PostcodeTextBox.Text;
                payment.Message    = this.MessageTextBox.Text;

                payment.Validate(); //optional validation (Checkout Finland validates data too)

                //Send payment data to Checkout Finland,
                //then make received payment options available
                //to the Web Form
                try
                {
                    this.BankPaymentOptions = CheckoutClient.postPaymentData(payment.FormData());
                }
                catch (WebException ex)
                {
                    //exception handling for testing
                    string errorMessage = ex.ToString();
                    errorMessage = (errorMessage.Length > 1000) ? errorMessage.Substring(0, 1000) : errorMessage;
                    Response.Redirect("~/PaymentErrorWebForm.aspx?error=" + HttpUtility.UrlEncode(errorMessage));
                }

                //if device HTML (1), then use WebForm for HTML page
                if (payment.Device.Equals(Checkout.Payment.Device_HTML))
                {
                    Server.Transfer("PaymentOptionsHTML.aspx");
                }
                else //WebForm for XML format
                {
                    this.Payment = payment;

                    Server.Transfer("PaymentOptionsXML.aspx");
                }
            }
        }