public RefundPaymentResponse RefundPayment(PayPalPayment payment) { var executor = GetExecutor(); RefundPaymentRequest request = new RefundPaymentRequest(executor); request.Currency = "GBP"; return request.Execute(payment); }
public RefundPaymentResponse Execute(PayPalPayment payment, bool partial = false, decimal amount = 0M, string note = null) { NVPCodec encoder = new NVPCodec(); encoder["TRANSACTIONID"] = payment.TransactionID; encoder["METHOD"] = METHOD; if (partial) { encoder["REFUNDTYPE"] = "Partial"; encoder["AMT"] = amount.ToString("#.##"); // TODO: Reference Decimal Format for PayPal encoder["CURRENCYCODE"] = this.Currency; } else { encoder["REFUNDTYPE"] = "Full"; } var decoder = executorService.Execute(encoder); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { payment.RefundTransactionID = decoder["REFUNDTRANSACTIONID"]; payment.FeeRefundAmount = decimal.Parse(decoder["FEEREFUNDAMT"]); payment.GrossRefundAmount = decimal.Parse(decoder["GROSSREFUNDAMT"]); payment.NetRefundAmount = decimal.Parse(decoder["NETREFUNDAMT"]); //payment.TotalRefundAmount = decimal.Parse(decoder["TOTALREFUNDEDAMT"]); payment.Refunded = true; return new RefundPaymentResponse() { RefundPayment = payment }; } else { throw new PayPalExeception(decoder["L_ERRORCODE0"], decoder["L_SHORTMESSAGE0"], decoder["L_LONGMESSAGE0"]); } }
public ActionResult Shipping(string token, string payerId) { // Get the address details from the paypal service var response = payPalService.ShippingDetails(token); var basket = basketService.GetBasket(); var customer = dbContext.Customers.Where(x => x.ExternalReference == response.Customer.ExternalReference).SingleOrDefault(); if (customer == null) { // We need to save the customer dbContext.Customers.Add(response.Customer); dbContext.SaveChanges(); } else { response.Customer = customer; } // Creates a new paypal payment var payment = new PayPalPayment(); payment.PayerID = payerId; payment.Token = token; payment.Status = "Pending"; Order order = new Order(); order.ShippingAddress = response.ShippingAddress; order.Customer = response.Customer; order.Items = basket.Items; order.Payment = payment; order.Status = "Initial"; order.Created = DateTime.Now; order.Updated = DateTime.Now; // Selects the first shipping method the customer can select another later in order summary order.ShippingMethod = shippingService.GetShippingMethods(order.ShippingAddress, order.TotalWeight, 0, 0, 0).First(); //TODO: Remove this it will not be needed much longer! orderService.SetCurrentOrder(order); //TODO: Establish the customer here customerService.EstablishCustomer(order.Customer); dbContext.Orders.Add(order); try { dbContext.SaveChanges(); } catch (DbEntityValidationException ex) { var error = ex.ToString(); } //var confirm = payPalService.ConfirmPayment(basket); return RedirectToAction("Shipping", "Order"); }