コード例 #1
0
    void FinalizeTransaction()
    {
        string orderId    = web.Param("orderId");
        string CustomerID = web.CustomerID();

        // check that transaction was approved and get it transactionID
        SteamApi api = new SteamApi();

        SteamXML.MicroTnxResponse resp = api.QueryTxn(orderId);
        //System.Diagnostics.Debug.WriteLine("@@@QueryTxn: " + api.lastData_);
        if (!ParseResponse(resp))
        {
            return;
        }
        if (resp.params_.status != "Approved")
        {
            Response.Write("WO_5");
            Response.Write(string.Format("bad status: {0}", resp.params_.status));
            return;
        }

        // finalize transaction in steam. NOTE: f*****g steam give http error instead of valid answer here
        resp = api.FinalizeTxn(orderId);
        //System.Diagnostics.Debug.WriteLine("@@@FinalizeTxn: " + api.lastData_);
        if (!ParseResponse(resp))
        {
            return;
        }

        // note: we can't pass transaction id as bigint here, because stream using *unsigned* int64.
        string transid = resp.params_.transid;

        // finalize transaction in DB and get new balance
        SqlCommand sqcmd = new SqlCommand();

        sqcmd.CommandType = CommandType.StoredProcedure;
        sqcmd.CommandText = "WO_SteamFinishOrder";
        sqcmd.Parameters.AddWithValue("@in_IP", LastIP);
        sqcmd.Parameters.AddWithValue("@in_CustomerID", CustomerID);
        sqcmd.Parameters.AddWithValue("@in_OrderID", orderId);
        sqcmd.Parameters.AddWithValue("@in_transid", transid);
        if (!CallWOApi(sqcmd))
        {
            return;
        }

        // return new GP balance
        reader.Read();
        int balance = getInt("Balance");

        Response.Write("WO_0");
        Response.Write(balance.ToString());
    }