Ejemplo n.º 1
0
    static void Main()
    {
        int y;

        foo(out y);
        Contract.Assert(y != 10);

        int  witness;
        CaaS paypal = GlobalState.paypal;
        PayPalStandardPaymentProcessor1 merchant_sender = new PayPalStandardPaymentProcessor1();

        PayPalStandardReturn1 merchant_receiver = new PayPalStandardReturn1();
        Order init_order = p.NondetOrder();
        canonicalRequestResponse res_placeorder = p.NodetReqres();
        canonicalRequestResponse req_pay        = p.NodetReqres();
        canonicalRequestResponse res_pay        = p.NodetReqres();
        canonicalRequestResponse req_finish     = p.NodetReqres();

        // Computation on merchant - place order
        res_placeorder = merchant_sender.PostProcessPayment(init_order);
        // Message: merchant -> client -> CaaS
        // is the msg encrypted? if so, then:
        req_pay = res_placeorder;
        GlobalState.MerchantPaymentEmail = req_pay.payee;
        GlobalState.order.gross          = req_pay.gross;
        GlobalState.order.id             = req_pay.orderID;

        GlobalState.paypal.pay(req_pay); //Rui: there is no return for this call, because anything returned through the client should be havoced

        req_finish.orderID = p.NondetInt();
        witness            = merchant_receiver.Page_Load(null, null, req_finish.orderID);

        Contract.Assert(GlobalState.paypal.caas.payments[witness].orderID == req_finish.orderID);
        Contract.Assert(
            paypal.caas.payments[witness].orderID == req_finish.orderID &&
            paypal.caas.payments[witness].gross == GlobalState.tstore.orders[req_finish.orderID].gross &&
            paypal.caas.payments[witness].payee == GlobalState.tstore.myAccount &&
            paypal.caas.payments[witness].status == CaasReturnStatus.Sucess
            );
        Contract.Assert(0 <= witness && witness < paypal.caas.payments.Length);

        Contract.Assert(Contract.Exists(0, paypal.caas.payments.Length, i =>
                                        paypal.caas.payments[i].orderID == req_finish.orderID &&
                                        paypal.caas.payments[i].payee == GlobalState.tstore.myAccount &&
                                        paypal.caas.payments[i].status == CaasReturnStatus.Sucess &&
                                        paypal.caas.payments[i].gross == GlobalState.tstore.orders[req_finish.orderID].gross
                                        ));
    }
Ejemplo n.º 2
0
    static void Main()
    {
        PayPalStandardPaymentProcessor1 merchant_sender = new PayPalStandardPaymentProcessor1();

        PayPalStandardReturn1 merchant_receiver = new PayPalStandardReturn1();
        Order init_order = p.NondetOrder();

        GlobalState.order   = new orderRecord();
        GlobalState.payment = new orderRecord();
        canonicalRequestResponse res_placeorder = p.NodetReqres();
        canonicalRequestResponse req_pay        = p.NodetReqres();
        canonicalRequestResponse res_pay        = p.NodetReqres();
        canonicalRequestResponse req_finish     = p.NodetReqres();

        // Message: CaaS -> client -> merchant
        // Computation on merchant - finish order
        merchant_receiver.Page_Load(null, null);

        Contract.Assert(GlobalState.order.id == GlobalState.payment.id);
        Contract.Assert(GlobalState.MerchantPaymentEmail == GlobalState.payment.payee);
        Contract.Assert(GlobalState.order.gross == GlobalState.payment.gross);
        Contract.Assert(GlobalState.order.status == Global.OrderStatusEnum.Paid);
    }
Ejemplo n.º 3
0
        public int Page_Load(object sender, EventArgs e, int checkedOut_orderID)
        {
            int            tx = Convert.ToInt32(CommonHelper.QueryStringInt("tx"));
            int            witness;
            payment_record payment;

            orderRecord order;

            Dictionary <string, string> values = null;

            if ((witness = PayPalStandardPaymentProcessor1.getPDTDetails(tx, out payment)) >= 0)
            {
                string orderNumber = string.Empty;
                values.TryGetValue("custom", out orderNumber);
                Guid orderNumberGuid = Guid.Empty;

                try
                {
                    orderNumberGuid = new Guid(orderNumber);
                }
                catch { }
                //Order order = OrderManager.GetOrderByGuid(orderNumberGuid);

                //payment.orderID is essentially the custom field in PDT
                Contract.Assume(checkedOut_orderID == payment.orderID);      //this should be an assignment  "checkedOut_orderID = payment.orderID", but the support for "out parameter" is wierd
                order = GlobalState.tstore.orders[checkedOut_orderID];
                Contract.Assume(order.id == checkedOut_orderID);

                if (order != null)
                {
                    decimal total = decimal.Zero;
                    try
                    {
                        total = decimal.Parse(values["mc_gross"], new CultureInfo("en-US"));
                    }
                    catch (Exception exc)
                    {
                    }
                    if (order.gross != total)
                    {
                        Contract.Assume(false);
                    }

                    string payer_status = string.Empty;
                    values.TryGetValue("payer_status", out payer_status);
                    string payment_status = string.Empty;
                    values.TryGetValue("payment_status", out payment_status);
                    string pending_reason = string.Empty;
                    values.TryGetValue("pending_reason", out pending_reason);
                    string mc_currency = string.Empty;
                    values.TryGetValue("mc_currency", out mc_currency);
                    string txn_id = string.Empty;
                    values.TryGetValue("txn_id", out txn_id);
                    string payment_type = string.Empty;
                    values.TryGetValue("payment_type", out payment_type);
                    string payer_id = string.Empty;
                    values.TryGetValue("ayer_id", out payer_id);
                    string receiver_id = string.Empty;
                    values.TryGetValue("receiver_id", out receiver_id);
                    string invoice = string.Empty;
                    values.TryGetValue("invoice", out invoice);
                    string payment_fee = string.Empty;
                    values.TryGetValue("payment_fee", out payment_fee);

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Paypal PDT:");
                    sb.AppendLine("total: " + total);
                    sb.AppendLine("Payer status: " + payer_status);
                    sb.AppendLine("Payment status: " + payment_status);
                    sb.AppendLine("Pending reason: " + pending_reason);
                    sb.AppendLine("mc_currency: " + mc_currency);
                    sb.AppendLine("txn_id: " + txn_id);
                    sb.AppendLine("payment_type: " + payment_type);
                    sb.AppendLine("payer_id: " + payer_id);
                    sb.AppendLine("receiver_id: " + receiver_id);
                    sb.AppendLine("invoice: " + invoice);
                    sb.AppendLine("payment_fee: " + payment_fee);

                    OrderManager.InsertOrderNote(order.id, sb.ToString(), false, DateTime.UtcNow);
                }

                if (order.gross != payment.gross)
                {
                    Contract.Assume(false);
                }

                if (payment.status != CaasReturnStatus.Sucess)
                {
                    Contract.Assume(false);
                }
                order.status = Global.OrderStatusEnum.Paid;
            }
            else
            {
                Contract.Assume(false);
            }
            return(witness);
        }
Ejemplo n.º 4
0
        public void Page_Load(object sender, EventArgs e)
        {
            int tx = Convert.ToInt32(CommonHelper.QueryStringInt("tx"));
            Dictionary <string, string> values = null;
            string response;
            string digest_paypal;

            if (PayPalStandardPaymentProcessor1.getPDTDetails(tx, out GlobalState.payment))
            {
                string orderNumber = string.Empty;
                values.TryGetValue("custom", out orderNumber);
                Guid orderNumberGuid = Guid.Empty;
                try
                {
                    orderNumberGuid = new Guid(orderNumber);
                }
                catch { }
                Order order = OrderManager.GetOrderByGuid(orderNumberGuid);
                if (order != null)
                {
                    decimal total = decimal.Zero;
                    try
                    {
                        total = decimal.Parse(values["mc_gross"], new CultureInfo("en-US"));
                    }
                    catch (Exception exc)
                    {
                    }
                    if (order.OrderTotal != total)
                    {
                        Contract.Assume(false);
                    }

                    string payer_status = string.Empty;
                    values.TryGetValue("payer_status", out payer_status);
                    string payment_status = string.Empty;
                    values.TryGetValue("payment_status", out payment_status);
                    string pending_reason = string.Empty;
                    values.TryGetValue("pending_reason", out pending_reason);
                    string mc_currency = string.Empty;
                    values.TryGetValue("mc_currency", out mc_currency);
                    string txn_id = string.Empty;
                    values.TryGetValue("txn_id", out txn_id);
                    string payment_type = string.Empty;
                    values.TryGetValue("payment_type", out payment_type);
                    string payer_id = string.Empty;
                    values.TryGetValue("payer_id", out payer_id);
                    string receiver_id = string.Empty;
                    values.TryGetValue("receiver_id", out receiver_id);
                    string invoice = string.Empty;
                    values.TryGetValue("invoice", out invoice);
                    string payment_fee = string.Empty;
                    values.TryGetValue("payment_fee", out payment_fee);

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Paypal PDT:");
                    sb.AppendLine("total: " + total);
                    sb.AppendLine("Payer status: " + payer_status);
                    sb.AppendLine("Payment status: " + payment_status);
                    sb.AppendLine("Pending reason: " + pending_reason);
                    sb.AppendLine("mc_currency: " + mc_currency);
                    sb.AppendLine("txn_id: " + txn_id);
                    sb.AppendLine("payment_type: " + payment_type);
                    sb.AppendLine("payer_id: " + payer_id);
                    sb.AppendLine("receiver_id: " + receiver_id);
                    sb.AppendLine("invoice: " + invoice);
                    sb.AppendLine("payment_fee: " + payment_fee);

                    OrderManager.InsertOrderNote(order.OrderId, sb.ToString(), false, DateTime.UtcNow);
                }

                if (GlobalState.payment != null)
                {
                    if (GlobalState.order.gross != GlobalState.payment.gross)
                    {
                        Contract.Assume(false);
                    }
                    if (GlobalState.MerchantPaymentEmail != GlobalState.payment.payee)
                    {
                        Contract.Assume(false);
                    }
                    if (GlobalState.order.id == GlobalState.payment.id)
                    {
                        GlobalState.order.status = Global.OrderStatusEnum.Paid;
                    }
                    else
                    {
                        Contract.Assume(false);
                    }
                }
            }
            else
            {
                Contract.Assume(false);
            }
        }