Exemplo n.º 1
0
    /// <summary>
    /// Handles the Click event of the CancelButton 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 CancelButton_Click(object sender, EventArgs e)
    {
        Label  orderNumberLbl = (Label)LoginView.FindControl("GoogleOrderNumberLabel");
        string reason         = "Cannceled by merchant!";
        string comment        = "Item(s) not available in this moment";

        GCheckout.OrderProcessing.CancelOrderRequest cancelReq = new GCheckout.OrderProcessing.CancelOrderRequest(orderNumberLbl.Text, reason, comment);
        cancelReq.Send();
    }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the notification.
        /// </summary>
        /// <param name="xmlFile">The XML file.</param>
        /// <returns>Serial number of the notification</returns>
        public static string ProcessNotification(string xmlFile)
        {
            string conn = GetConnectionString();
            StoreDataClassesDataContext db = new StoreDataClassesDataContext(conn);
            string SerialNumber            = "";
            //Read XML file
            StreamReader strReader    = new StreamReader(xmlFile);
            string       requestedXml = strReader.ReadToEnd();

            //Act on XML file
            switch (EncodeHelper.GetTopElement(requestedXml))
            {
            case "new-order-notification":
                NewOrderNotification N1 = (NewOrderNotification)EncodeHelper.Deserialize(requestedXml, typeof(NewOrderNotification));
                ///This notification tells us that Google has accepted the order
                SerialNumber = N1.serialnumber;
                Int64  OrderNumber1    = Int64.Parse(N1.googleordernumber);
                int    pos             = N1.buyershippingaddress.contactname.IndexOf(" ");
                string ShipToFirstName = N1.buyershippingaddress.contactname.Substring(0, pos);
                string ShipToLatsName  = N1.buyershippingaddress.contactname.Substring(pos + 1);
                string UserName        = N1.shoppingcart.merchantprivatedata.Any[1].InnerText;
                int    internalOrderId = int.Parse(EncodeHelper.GetElementValue(requestedXml, "MERCHANT_DATA_HIDDEN"));

                order newOrder = db.orders.Where(o => o.order_id == internalOrderId).Single <order>();

                newOrder.google_order_number = OrderNumber1;
                newOrder.order_date          = N1.timestamp;
                newOrder.order_by            = UserName;
                newOrder.sub_total           = N1.ordertotal.Value;
                newOrder.total          = N1.ordertotal.Value;
                newOrder.charged_amount = 0;
                newOrder.status         = "NEW";
                newOrder.root_id        = 1;
                //newOrder.shipping_first_name = ShipToFirstName;
                //newOrder.shipping_last_name = ShipToLatsName;
                //newOrder.shipping_address = N1.buyershippingaddress.address1;
                //newOrder.shipping_city = N1.buyershippingaddress.city;
                //newOrder.shipping_state = N1.buyershippingaddress.region;
                //newOrder.shipping_zip = N1.buyershippingaddress.postalcode;
                //newOrder.shipping_country = N1.buyerbillingaddress.countrycode;

                db.SubmitChanges();
                db.orders.DeleteAllOnSubmit(db.orders.Where(o => (o.status == "TEMP" && o.order_by == UserName)));
                db.SubmitChanges();

                foreach (Item ThisItem in N1.shoppingcart.items)
                {
                    int     itemId   = int.Parse(ThisItem.merchantprivateitemdata.Any[0].InnerText);
                    string  desc     = ThisItem.itemdescription;
                    int     quantity = ThisItem.quantity;
                    decimal price    = ThisItem.unitprice.Value;
                    bool    tangible = false;
                    if (ThisItem.digitalcontent != null)
                    {
                        tangible = true;
                    }

                    order_item newItem = new order_item();
                    newItem.item_id   = itemId;
                    newItem.order_id  = internalOrderId;
                    newItem.price     = price;
                    newItem.qty       = quantity;
                    newItem.tangible  = tangible;
                    newItem.item_desc = desc;
                    newItem.item_name = ThisItem.itemname;

                    db.order_items.InsertOnSubmit(newItem);
                    db.SubmitChanges();
                }

                break;

            case "risk-information-notification":
                RiskInformationNotification N2 = (RiskInformationNotification)EncodeHelper.Deserialize(requestedXml, typeof(RiskInformationNotification));
                // This notification tells us that Google has authorized the order and it has passed the fraud check
                SerialNumber = N2.serialnumber;
                long   googleOrderNumber = Int64.Parse(N2.googleordernumber);
                string contactName       = EncodeHelper.GetElementValue(requestedXml, "contact-name");
                string email             = EncodeHelper.GetElementValue(requestedXml, "email");
                string city     = EncodeHelper.GetElementValue(requestedXml, "city");
                int    zip      = int.Parse(EncodeHelper.GetElementValue(requestedXml, "postal-code"));
                string country  = EncodeHelper.GetElementValue(requestedXml, "country-code");
                bool   elibible = N2.riskinformation.eligibleforprotection;
                char   cvn      = char.Parse(N2.riskinformation.cvnresponse);

                if (elibible && N2.riskinformation.cvnresponse == "M")
                {
                    customer newCustomer = new customer();
                    newCustomer.google_order_number = googleOrderNumber;
                    newCustomer.eligibility         = elibible;
                    newCustomer.contact_name        = contactName;
                    newCustomer.email     = email;
                    newCustomer.address   = N2.riskinformation.billingaddress.address1;
                    newCustomer.city      = city;
                    newCustomer.zip       = zip;
                    newCustomer.country   = country;
                    newCustomer.avs       = char.Parse(N2.riskinformation.avsresponse);
                    newCustomer.cvn       = cvn;
                    newCustomer.cc_number = int.Parse(N2.riskinformation.partialccnumber);
                    newCustomer.ip        = N2.riskinformation.ipaddress;

                    db.customers.InsertOnSubmit(newCustomer);
                    db.SubmitChanges();
                }
                else
                {
                    string reason  = "You did not pass Google security check!";
                    string comment = "Please visis http://checkout.google.com/support/sell/bin/topic.py?topic=15055 for more information";
                    GCheckout.OrderProcessing.CancelOrderRequest cancelReq = new GCheckout.OrderProcessing.CancelOrderRequest(N2.googleordernumber, reason, comment);
                    cancelReq.Send();
                }

                break;

            case "order-state-change-notification":
                OrderStateChangeNotification N3 = (OrderStateChangeNotification)EncodeHelper.Deserialize(requestedXml, typeof(OrderStateChangeNotification));
                // The order has changed either financial or fulfillment state in Google's system.
                SerialNumber = N3.serialnumber;
                long   googleOrderNumber1   = Int64.Parse(N3.googleordernumber);
                string newFinanceState      = N3.newfinancialorderstate.ToString();
                string newFulfillmentState  = N3.newfulfillmentorderstate.ToString();
                string prevFinanceState     = N3.previousfinancialorderstate.ToString();
                string prevFulfillmentState = N3.previousfulfillmentorderstate.ToString();

                order thisOrder1 = (from or in db.orders where or.google_order_number == googleOrderNumber1 select or).Single <order>();
                //if (newFinanceState == "CHARGEABLE")
                //{
                //    GCheckout.OrderProcessing.ChargeOrderRequest chargeReq = new GCheckout.OrderProcessing.ChargeOrderRequest(N3.googleordernumber);
                //    chargeReq.Send();
                //}
                thisOrder1.status = newFinanceState;
                if (newFulfillmentState == "WILL_NOT_DELIVER")
                {
                    thisOrder1.shipping_status = "CANCELLED";
                }
                else
                {
                    thisOrder1.shipping_status = newFulfillmentState;
                }
                db.SubmitChanges();
                break;

            case "charge-amount-notification":
                ChargeAmountNotification N4 = (ChargeAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(ChargeAmountNotification));
                // Google has successfully charged the customer's credit card.
                SerialNumber = N4.serialnumber;
                long    googleOrderNumber2 = Int64.Parse(N4.googleordernumber);
                decimal chargedAmount      = N4.latestchargeamount.Value;

                order thisOrder2 = (from or in db.orders where or.google_order_number == googleOrderNumber2 select or).Single <order>();
                thisOrder2.charged_amount += chargedAmount;
                thisOrder2.sub_total      -= chargedAmount;
                db.SubmitChanges();

                break;

            case "refund-amount-notification":
                RefundAmountNotification N5 = (RefundAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(RefundAmountNotification));
                // Google has successfully refunded the customer's credit card.
                SerialNumber = N5.serialnumber;
                long    googleOrderNumber3 = Int64.Parse(N5.googleordernumber);
                decimal refundedAmount     = N5.latestrefundamount.Value;

                order thisOrder3 = (from or in db.orders where or.google_order_number == googleOrderNumber3 select or).Single <order>();
                thisOrder3.status          = "REFUNDED";
                thisOrder3.charged_amount -= refundedAmount;
                db.SubmitChanges();

                break;

            case "chargeback-amount-notification":
                ChargebackAmountNotification N6 = (ChargebackAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(ChargebackAmountNotification));
                // A customer initiated a chargeback with his credit card company to get her money back.
                SerialNumber = N6.serialnumber;
                long    googleOrderNumber4 = Int64.Parse(N6.googleordernumber);
                decimal chargebackAmount   = N6.latestchargebackamount.Value;

                order thisOrder4 = (from or in db.orders where or.google_order_number == googleOrderNumber4 select or).Single <order>();
                thisOrder4.status = "CHARGEBACK";
                db.SubmitChanges();

                break;

            default:
                break;
            }

            strReader.Close();
            strReader.Dispose();
            return(SerialNumber);
        }
        public void CancelOrderRequest()
        {
            CancelOrderRequest Req;
              AutoGen.CancelOrderRequest D;
              // Test the first constructor.
              Req = new CancelOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON);
              D = ParseCancelOrderRequest(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(null, D.comment);
              Assert.AreEqual(REASON, D.reason);
              Assert.AreEqual(Req.GoogleOrderNumber, D.googleordernumber);

              // Test the second constructor.
              Req = new CancelOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox", ORDER_NUMBER,
            REASON, COMMENT);
              D = ParseCancelOrderRequest(Req.GetXml());
              Assert.AreEqual(ORDER_NUMBER, D.googleordernumber);
              Assert.AreEqual(COMMENT, D.comment);
              Assert.AreEqual(REASON, D.reason);

              Req = new CancelOrderRequest(ORDER_NUMBER, REASON);
              D = ParseCancelOrderRequest(Req.GetXml());

              Req = new CancelOrderRequest(ORDER_NUMBER, REASON, COMMENT);
              D = ParseCancelOrderRequest(Req.GetXml());
        }
 public void InvalidCancelOrderRequest2()
 {
     // Reason is not allowed to be an empty string.
       CancelOrderRequest Req = new CancelOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox",
     ORDER_NUMBER, "");
 }
 public void InvalidCancelOrderRequest1()
 {
     // Reason is not allowed to be null.
       CancelOrderRequest Req = new CancelOrderRequest(MERCHANT_ID, MERCHANT_KEY, "Sandbox",
     ORDER_NUMBER, null);
 }