Exemplo n.º 1
0
    protected void Insert()
    {
        Invoice invoice = UrlInvoice;
        int?    tyro_payment_type_id = UrlTyroPaymentTypeID;
        decimal?amount  = UrlAmount;
        decimal?cashout = UrlCashout;

        if (invoice == null)
        {
            throw new Exception("Invalid url field invoice_id");
        }
        if (tyro_payment_type_id == null)
        {
            throw new Exception("Invalid url field tyro_payment_type_id");
        }
        if (amount == null)
        {
            throw new Exception("Invalid url field amount");
        }
        if (cashout == null)
        {
            throw new Exception("Invalid url field cashout");
        }

        if (tyro_payment_type_id.Value == 1 && amount.Value > invoice.TotalDue)
        {
            Response.Write("OVERPAYMENT:$" + invoice.TotalDue);
            return;
        }
        if (tyro_payment_type_id.Value == 2 && amount.Value > invoice.ReceiptsTotal)
        {
            Response.Write("OVERREFUND:$" + invoice.ReceiptsTotal);
            return;
        }

        if (tyro_payment_type_id == 2)  // make it negative for refunds
        {
            amount = amount.Value * -1;
        }

        Tuple <int, string> dbFieds = TyroPaymentPendingDB.Insert(invoice.InvoiceID, Session["DB"].ToString(), tyro_payment_type_id.Value, amount.Value, cashout.Value);

        Response.Write(dbFieds.Item2);  // tyro_transaction_id
    }