Exemplo n.º 1
0
        /// <summary>
        /// Refunds the order.
        /// </summary>
        public void RefundOrder()
        {
            var username = "******";
            var password = "******";

            var klarna  = new Klarna(username, password, KlarnaEnvironment.TestingEurope);
            var orderId = "abc-abcdefg-abc";

            try
            {
                var refundData = new RefundObject()
                {
                    RefundedAmount = 10000,
                    Description    = "Full refund for order",
                    OrderLines     = new List <OrderLine>()
                    {
                        new OrderLine
                        {
                            Type                = OrderLineType.physical,
                            Name                = "Foo",
                            Quantity            = 1,
                            UnitPrice           = 10000,
                            TaxRate             = 2500,
                            TotalAmount         = 10000,
                            TotalTaxAmount      = 2000,
                            TotalDiscountAmount = 0,
                        }
                    }
                };
                var refund = klarna.OrderManagement.CreateAndFetchRefund(orderId, refundData).Result;
                Console.WriteLine("Order has been refunded");
                Console.WriteLine(refund.RefundId);
                Console.WriteLine(refund.RefundedAt);
                Console.WriteLine(refund.RefundedAmount);
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.InnerExceptions)
                {
                    if (e is ApiException)
                    {
                        var apiException = (ApiException)e;
                        Console.WriteLine("Status code: " + apiException.StatusCode);
                        Console.WriteLine("Error: " + string.Join("; ", apiException.ErrorMessage.ErrorMessages));
                    }
                    else
                    {
                        // Rethrow any other exception or process it
                        Console.WriteLine(e.Message);
                        throw;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void submitRefund()
 {
     try
     {
         RefundObject.AddnewRefund(CurrentSession.CurrentUserObject.UserID);
     }
     catch (Exception E)
     {
         ExepionLogger.Logger.LogException(E);
         ExepionLogger.Logger.Show(E);
     }
     finally
     {
         this.Close();
     }
 }
        /// <summary>
        /// Creates a refund and follow the Location header to fetch the data
        /// <a href="https://developers.klarna.com/api/#order-management-api-create-a-refund">
        ///     https://developers.klarna.com/api/#order-management-api-create-a-refund
        /// </a>
        /// </summary>
        /// <param name="orderId">Id of order to create a refund</param>
        /// <param name="refund">The <see cref="OrderManagementRefund"/> object</param>
        /// <returns>Object of <see cref="OrderManagementGetRefundResponse"/> </returns>
        public async Task <Refund> CreateAndFetchRefund(string orderId, RefundObject refund)
        {
            var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{orderId}/refunds");

            var response = new Ref <HttpResponseMessage>();

            await Post(url, refund, null, response).ConfigureAwait(false);

            var headers = response.Value.Headers;

            url = headers.Location.ToString();

            if (!string.IsNullOrEmpty(url))
            {
                return(await Get <Refund>(url).ConfigureAwait(false));
            }

            return(default(Refund));
        }
        /// <summary>
        /// Creates a refund
        /// <a href="https://developers.klarna.com/api/#order-management-api-create-a-refund">
        ///     https://developers.klarna.com/api/#order-management-api-create-a-refund
        /// </a>
        /// </summary>
        /// <param name="orderId">Id of order to create a refund</param>
        /// <param name="refund">The <see cref="OrderManagementRefund"/> object</param>
        /// <returns></returns>
        public Task CreateRefund(string orderId, RefundObject refund)
        {
            var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{orderId}/refunds");

            return(Post(url, refund));
        }