コード例 #1
0
        /// <summary>
        /// Allows a single line-item / adjutsment to be refunded.
        /// </summary>
        /// <param name="adjustment">The adjustment to be refunded.</param>
        /// <param name="options">The options for the refund invoice.</param>
        /// <returns>new Invoice object</returns>
        public Invoice Refund(Adjustment adjustment, RefundOptions options)
        {
            var adjustments = new List <Adjustment>();

            adjustments.Add(adjustment);
            return(Refund(adjustments, options));
        }
コード例 #2
0
        /// <summary>
        /// Allows you to refund a specific amount from an invoice.
        /// </summary>
        /// <param name="amountIncents">The amount in cents to refund from the invoice.</param>
        /// <param name="options">The options for the refund invoice.</param>
        /// <returns>new Invoice object</returns>
        public Invoice RefundAmount(int amountInCents, RefundOptions options)
        {
            var refundInvoice = new Invoice();
            var refund        = new OpenAmountRefund(amountInCents, options);

            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                                                            memberUrl() + "/refund",
                                                            refund.WriteXml,
                                                            refundInvoice.ReadXml);

            if (HttpStatusCode.Created == statusCode || HttpStatusCode.OK == statusCode)
            {
                return(refundInvoice);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Allows specific line items / adjutsments to be refunded.
        /// </summary>
        /// <param name="adjustments">The list of adjustments to refund.</param>
        /// <param name="options">The options for the refund invoice.</param>
        /// <returns>new Invoice object</returns>
        public Invoice Refund(IEnumerable <Adjustment> adjustments, RefundOptions options)
        {
            var refunds = new RefundList(adjustments, options);
            var invoice = new Invoice();

            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                                                            memberUrl() + "/refund",
                                                            refunds.WriteXml,
                                                            invoice.ReadXml);

            if (HttpStatusCode.Created == statusCode || HttpStatusCode.OK == statusCode)
            {
                return(invoice);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: CoinbaseApi.cs プロジェクト: ryanmwilliams/Coinbase
        /// <summary>
        /// Authenticated resource which refunds an order or a mispayment to an order. Returns a snapshot of the order data, updated with refund transaction details.
        /// This endpoint will only refund the full amount of the order or mispayment, specified as either the original BTC amount or native currency amount (such as USD). To issue partial refunds, you can use the regular api/v1/transactions/send_money endpoint.
        /// https://www.coinbase.com/api/doc/1.0/orders/refund.html
        /// </summary>
        /// <param name="orderId">id_or_custom_field URL parameter</param>
        /// <param name="refundOptions">Refund options for this order ID</param>
        /// <returns>If the order has status completed and the refund processed successfully, the order data will contain the refund transaction details in RefundTransaction. If the refund does not process, order['errors'] will be present, specifying any problems.</returns>
        public RefundResponse Refund(string orderId, RefundOptions refundOptions)
        {
            var client = CreateClient();
            var body   = new RefundRequest()
            {
                RefundOptions = refundOptions
            };
            var post = CreateRequest("orders/{orderId}/refund")
                       .AddUrlSegment("orderId", orderId)
                       .AddBody(body);

            var resp = client.Execute <RefundResponse>(post);

            if (resp.ErrorException != null)
            {
                throw resp.ErrorException;
            }

            return(resp.Data);
        }
コード例 #5
0
        public void create_refund_test()
        {
            // arrange
            var api = new CoinbaseApi(apiKey: "my_api_key", apiSecret: "my_api_secret");

            var refundOptions = new RefundOptions
            {
                RefundIsoCurrency = Currency.BTC,

                //By default, refunds will be issued to the refund_address
                //that is set on the order.
                //Additionally, if you want to send the refund to a different
                //bitcoin address other than the one that was in the original order
                //set ExteranlRefundAddress property.
                //OPTIONAL:
                ExternalRefundAddress = "BITCOIN_REFUND_ADDRESS"
            };

            var orderIdToRefund = "COINBASE_ORDER_ID";

            // act
            var refundResult = api.Refund(orderIdToRefund, refundOptions);

            if (refundResult.Order.Errors != null)
            {
                //Some Refund Error
            }
            else if (refundResult.Order.Status == Status.Completed)
            {
                //The refund was successful
                var refundTxn = refundResult.Order.RefundTransaction;
            }

            // assert
            refundResult.Should().NotBeNull();
        }
コード例 #6
0
        protected void LoadPartialRefundLines()
        {
            try
            {
                TableRow lineRow = new TableRow();

                Sh = (List <SalesHeader>)Session["SalesHeaders"];

                List <ReturnReason>  rrList = (List <ReturnReason>)Session["ReturnReasons"];
                List <RefundOptions> ro     = new RefundOptions().Populate();

                User u = (User)Session["ActiveUser"];


                int    lineCount  = 0;
                double orderTotal = 0;
                string filterNo   = string.Empty;

                filterNo = tcNo.Text;

                foreach (SalesHeader head in Sh)
                {
                    foreach (ShipmentHeader header in head.ShipmentHeaderObject)
                    {
                        if (head.SalesOrderNo == filterNo)
                        {
                            foreach (ShipmentLine line in header.ShipmentLines)
                            {
                                if (line.Quantity > 0)
                                {
                                    lineCount++;

                                    TableRow singleRow = new TableRow();

                                    TableCell itemNo           = new TableCell();
                                    TableCell desc             = new TableCell();
                                    TableCell qty              = new TableCell();
                                    TableCell actionQty        = new TableCell();
                                    TableCell returnReasonCode = new TableCell();
                                    TableCell refundOption     = new TableCell();
                                    TableCell lineAmount       = new TableCell();
                                    TableCell refundAmount     = new TableCell();

                                    DropDownList ddlReturnReasonCode = new DropDownList
                                    {
                                        DataValueField = "Display",
                                        DataSource     = rrList.Where(x => x.Category == "Partial Refund" || x.Category == ""),
                                        ID             = "ddlReturnReasonCode_" + lineCount.ToString(),
                                        CssClass       = "inputBox"
                                    };

                                    DropDownList ddlRefundOption = new DropDownList
                                    {
                                        DataValueField = "Option",
                                        DataSource     = ro.Where(o => o.Tier == u.RefundTier),
                                        ID             = "ddlRefundOption_" + lineCount.ToString(),
                                        CssClass       = "inputBox"
                                    };

                                    TextBox actionQtyInsert = new TextBox
                                    {
                                        ID       = "actionQtyInsert_" + lineCount.ToString(),
                                        Text     = (line.Quantity).ToString(),
                                        Width    = new Unit("15%"),
                                        CssClass = "inputBox"
                                    };

                                    ddlReturnReasonCode.DataBind();
                                    ddlRefundOption.DataBind();

                                    itemNo.ID           = "itemNo_" + lineCount.ToString();
                                    qty.ID              = "itemQuanity_" + lineCount.ToString();
                                    desc.ID             = "desc_" + lineCount.ToString();
                                    actionQty.ID        = "actionQty_" + lineCount.ToString();
                                    returnReasonCode.ID = "returnReasonCode_" + lineCount.ToString();
                                    refundOption.ID     = "refundOption_" + lineCount.ToString();
                                    lineAmount.ID       = "lineAmount_" + lineCount.ToString();
                                    refundAmount.ID     = "refundAmount_" + lineCount.ToString();

                                    itemNo.Text = line.ItemNo;
                                    desc.Text   = line.Description;
                                    qty.Text    = (line.Quantity).ToString();
                                    actionQty.Controls.Add(actionQtyInsert);
                                    returnReasonCode.Controls.Add(ddlReturnReasonCode);
                                    refundOption.Controls.Add(ddlRefundOption);
                                    lineAmount.Text = "$      " + line.LineAmount.ToGBString();

                                    if (ro.Count > 0)
                                    {
                                        refundAmount.Text = "$      " + Math.Round((line.LineAmount * 0.1), 2).ToGBString(); //10% is default
                                    }

                                    orderTotal += line.LineAmount;

                                    qty.HorizontalAlign       = HorizontalAlign.Center;
                                    actionQty.HorizontalAlign = HorizontalAlign.Center;

                                    singleRow.ID = "partialRefundLineRow_" + lineCount.ToString();

                                    singleRow.Cells.Add(itemNo);
                                    singleRow.Cells.Add(desc);
                                    singleRow.Cells.Add(qty);
                                    singleRow.Cells.Add(actionQty);
                                    singleRow.Cells.Add(returnReasonCode);
                                    singleRow.Cells.Add(refundOption);
                                    singleRow.Cells.Add(lineAmount);
                                    singleRow.Cells.Add(refundAmount);

                                    if (lineCount % 2 == 0)
                                    {
                                        singleRow.BackColor           = Color.White;
                                        actionQtyInsert.BackColor     = Color.White;
                                        ddlReturnReasonCode.BackColor = Color.White;
                                        ddlRefundOption.BackColor     = Color.White;
                                    }
                                    else
                                    {
                                        singleRow.BackColor           = ColorTranslator.FromHtml("#EFF3FB");
                                        actionQtyInsert.BackColor     = ColorTranslator.FromHtml("#EFF3FB");
                                        ddlReturnReasonCode.BackColor = ColorTranslator.FromHtml("#EFF3FB");
                                        ddlRefundOption.BackColor     = ColorTranslator.FromHtml("#EFF3FB");
                                    }

                                    singleRow.Attributes.CssStyle.Add("border-collapse", "collapse");
                                    tblPartialRefundDetails.Rows.Add(singleRow);
                                }
                            }
                        }
                    }
                }

                Session["OrderTotal"] = orderTotal;

                // Implements 20 dollar refund tier
                if (orderTotal <= 20)
                {
                    for (int i = 1; i < lineCount + 1; i++)
                    {
                        foreach (TableRow row in tblPartialRefundDetails.Rows)
                        {
                            foreach (TableCell cell in row.Cells)
                            {
                                foreach (Control c in cell.Controls)
                                {
                                    if (c.ID.Contains("ddlRefundOption_" + i.ToString()))
                                    {
                                        DropDownList ddlRefundOption = (DropDownList)c;
                                        ddlRefundOption.DataSource = ro.Where(o => o.Tier == "20Dollar");
                                        ddlRefundOption.DataBind();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                ClientScript.RegisterStartupScript(this.GetType(), "exceptionAlert", "alert('" + ex.Message + "');", true);
            }
        }
コード例 #7
0
        protected void BtnCreatePartialRefund_Click(object sender, EventArgs e)
        {
            StringBuilder lineBuild = new StringBuilder();
            string        lineError = "";

            try
            {
                no    = tcNo.Text;
                docNo = tcDocNo.Text;

                User u = (User)Session["ActiveUser"];

                string validateMsg   = string.Empty;
                bool   allValidLines = true;
                int    rowCount      = 0;
                int    controlCount  = 0;

                if (!String.IsNullOrWhiteSpace(txtZendeskTicketNo.Text) || !String.IsNullOrEmpty(txtZendeskTicketNo.Text))
                {
                    if (txtZendeskTicketNo.Text.Length == 7)
                    {
                        int.TryParse(txtZendeskTicketNo.Text, out zendeskTicketNo);
                    }
                    else
                    {
                        validateMsg = "Zendesk Ticket # should be 7 numeric characters.";
                    }
                }

                if (validateMsg == string.Empty)
                {
                    foreach (TableRow row in tblPartialRefundDetails.Rows)
                    {
                        rowCount++;
                        string  itemNo       = string.Empty;
                        int     qtyLine      = 0;
                        int     actionQty    = 0;
                        string  reasonCode   = string.Empty;
                        decimal refundOption = 0;

                        controlCount = 0;
                        int cellCount = 0;

                        foreach (TableCell cell in row.Cells)
                        {
                            cellCount++;

                            if (cell.ID.Contains("itemNo_"))
                            {
                                itemNo = cell.Text.ToString();
                            }

                            if (cell.ID.Contains("itemQuanity_"))
                            {
                                int.TryParse(cell.Text.ToString(), out qtyLine);
                            }

                            foreach (Control c in cell.Controls)
                            {
                                controlCount++;

                                if (c.GetType() == typeof(TextBox))
                                {
                                    string value = ((TextBox)c).Text;
                                    int.TryParse(value, out actionQty);
                                }

                                if (c.GetType() == typeof(DropDownList))
                                {
                                    int index = ((DropDownList)c).SelectedIndex;

                                    if (c.ID.Contains("ddlReturnReasonCode_"))
                                    {
                                        List <ReturnReason> sr = (List <ReturnReason>)Session["ReturnReasons"];
                                        List <ReturnReason> rl = new List <ReturnReason>();
                                        foreach (ReturnReason item in sr)
                                        {
                                            if (item.Category == "Partial Refund" || item.Category == "")
                                            {
                                                rl.Add(item);
                                            }
                                        }
                                        reasonCode = (rl)[index].ReasonCode;
                                    }

                                    if (c.ID.Contains("ddlRefundOption"))
                                    {
                                        List <RefundOptions> ro    = new RefundOptions().Populate();
                                        List <RefundOptions> newRo = new List <RefundOptions>();
                                        double total = 0;

                                        foreach (RefundOptions option in ro)
                                        {
                                            if (Session["OrderTotal"] != null)
                                            {
                                                total = Convert.ToDouble(Session["OrderTotal"]);
                                            }

                                            if (total <= 20)
                                            {
                                                if (option.Tier == "20Dollar")
                                                {
                                                    newRo.Add(option);
                                                }
                                            }
                                            else if (option.Tier == u.RefundTier)
                                            {
                                                newRo.Add(option);
                                            }
                                        }

                                        string value = (newRo)[index].Option.Replace("%", "");
                                        Decimal.TryParse(value, out refundOption);
                                    }
                                }
                            }

                            string lineValidMessage = string.Empty;

                            if ((rowCount > 1 && controlCount == 3 && actionQty != 0 && cellCount == 6))
                            {
                                lineValidMessage = ValidateLine(itemNo, qtyLine, actionQty, reasonCode);

                                if (lineValidMessage == "Valid Line Input")
                                {
                                    lineBuild.Append(itemNo).Append(":");
                                    lineBuild.Append(actionQty).Append(":");
                                    lineBuild.Append(reasonCode).Append(":");
                                    lineBuild.Append(refundOption).Append(',');
                                }
                                else
                                {
                                    allValidLines = false;

                                    if (lineError == "")
                                    {
                                        lineError = lineValidMessage;
                                    }
                                }
                            }
                        }
                    }

                    if (allValidLines)
                    {
                        string      lineValues = lineBuild.ToString();
                        SendService ss         = new SendService();

                        ss.PartialRefund(no, docNo, lineValues, zendeskTicketNo);
                        Session["NoUserInteraction"] = true;

                        ClientScript.RegisterStartupScript(this.GetType(), "refundedOrder", "alert('Order " + no + " has been partially refunded.');", true);
                        ClientScript.RegisterStartupScript(this.GetType(), "closeRefundOrder", "CloseAfterCancel();", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "lineError", "alert('" + lineError + "');", true);
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "validateMsg", "alert('" + validateMsg + "');", true);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);

                ClientScript.RegisterStartupScript(this.GetType(), "exceptionAlert", "alert('" + ex.Message.Replace("'", "\"") + "');", true);

                if (ex.Message.ToLower().Contains("session"))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "closeErrorAlert", "parent.window.close();", true);
                }
            }
        }