Example #1
0
    /// <summary>
    /// Handles the Click event of the RefundButton control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void RefundButton_Click(object sender, EventArgs e)
    {
        RangeValidator rangeValidator   = (RangeValidator)LoginView.FindControl("RangeValidator");
        Label          orderNumberLbl   = (Label)LoginView.FindControl("GoogleOrderNumberLabel");
        TextBox        refundCommentTB  = (TextBox)LoginView.FindControl("RefundCommentTextBox");
        TextBox        refundAmountTB   = (TextBox)LoginView.FindControl("RefundTextBox");
        Label          chargedAmountLbl = (Label)LoginView.FindControl("ChargedAmountLabel");
        Label          refundStatusLbl  = (Label)LoginView.FindControl("RefundStatusLabel");
        Panel          refundPanel      = (Panel)LoginView.FindControl("RefundPanel");

        decimal total = decimal.Parse(chargedAmountLbl.Text);

        rangeValidator.MaximumValue = total.ToString();
        decimal amount = 0;

        if (decimal.TryParse(refundAmountTB.Text, out amount) && amount != 0 && amount <= total)
        {
            GCheckout.OrderProcessing.RefundOrderRequest refundReq = new GCheckout.OrderProcessing.RefundOrderRequest(orderNumberLbl.Text, refundCommentTB.Text, "USD", amount, refundCommentTB.Text);
            refundReq.Send();
            refundStatusLbl.Text = "";
            refundPanel.Visible  = false;
        }
        else
        {
            refundStatusLbl.Text = "The entered amount is not correct!";
        }
    }
        public void RefundOrderRequest()
        {
            RefundOrderRequest Req;
              AutoGen.RefundOrderRequest D;
              // Test the first constructor.
              Req = new RefundOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(null, D.amount);
              Assert.AreEqual(null, D.comment);
              Assert.AreEqual(REASON, D.reason);
              Assert.AreEqual(Req.GoogleOrderNumber, D.googleordernumber);

              // Test the second constructor.
              Req = new RefundOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON, "GBP", 100.975m);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual("GBP", D.amount.currency);
              Assert.AreEqual(100.98m, D.amount.Value);
              Assert.AreEqual(null, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the third constructor.
              Req = new RefundOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON, COMMENT);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(null, D.amount);
              Assert.AreEqual(COMMENT, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the fourth constructor.
              Req = new RefundOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON, "USD", 100.993m, COMMENT);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual("USD", D.amount.currency);
              Assert.AreEqual(100.99m, D.amount.Value);
              Assert.AreEqual(COMMENT, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the fifth constructor.
              Req = new RefundOrderRequest(ORDER_NUMBER, REASON);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(null, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the sixth constructor.
              Req = new RefundOrderRequest(ORDER_NUMBER,
            REASON, "USD", 100.993m);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(100.99m, D.amount.Value);
              Assert.AreEqual(null, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the seventh constructor.
              Req = new RefundOrderRequest(ORDER_NUMBER,
            REASON, COMMENT);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(null, D.amount);
              Assert.AreEqual(COMMENT, D.comment);
              Assert.AreEqual(REASON, D.reason);

              // Test the eighth constructor.
              Req = new RefundOrderRequest(ORDER_NUMBER,
            REASON, "USD", 100.993m, COMMENT);
              D = (AutoGen.RefundOrderRequest)EncodeHelper.Deserialize(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(100.99m, D.amount.Value);
              Assert.AreEqual(COMMENT, D.comment);
              Assert.AreEqual(REASON, D.reason);
        }