Exemple #1
0
        public static TransactionResult ProcessRefund(TransactionRequest request, PaypalWithRedirectSettings settings)
        {
            var order = request.Order;

            var refund = new RefundRequest()
            {
                Amount = new Amount()
                {
                    Total    = (request.Amount ?? order.OrderTotal).ToString("N"),
                    Currency = order.CurrencyCode
                },
                Reason = "Admin Initiated Refund",
            };
            var saleRefundRequest = new SaleRefundRequest(request.Parameters["saleId"].ToString());

            saleRefundRequest.RequestBody(refund);
            var environment = GetEnvironment(settings);

            var client            = new PayPalHttpClient(environment);
            var transactionResult = new TransactionResult();

            try
            {
                var response = client.Execute(saleRefundRequest).Result;
                var result   = response.Result <DetailedRefund>();
                transactionResult.Success            = true;
                transactionResult.NewStatus          = result.State == "approved" || result.State == "pending" ? PaymentStatus.Refunded : PaymentStatus.OnHold;
                transactionResult.OrderGuid          = order.Guid;
                transactionResult.TransactionAmount  = result.Amount.Total.GetDecimal();
                transactionResult.ResponseParameters = new Dictionary <string, object>()
                {
                    { "id", result.Id },
                    { "parentPayment", result.ParentPayment },
                    { "createTime", result.CreateTime },
                    { "state", result.State },
                    { "updateTime", result.UpdateTime },
                };
            }
            catch (BraintreeHttp.HttpException ex)
            {
                transactionResult.Exception = ex;
            }

            return(transactionResult);
        }
Exemple #2
0
        public async Task <ApiResponse <SaleRefundResponse> > SaleRefund(Guid saleUUID, SaleRefundRequest saleRefundRequest)
        {
            var response = await _restClient.Put <SaleRefundResponse>($"transactions/{saleUUID}/refund", saleRefundRequest);

            return(response);
        }