/// <remarks/> public void RefundTransactionAsync(RefundTransactionReq RefundTransactionReq, object userState) { if ((this.RefundTransactionOperationCompleted == null)) { this.RefundTransactionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRefundTransactionOperationCompleted); } this.InvokeAsync("RefundTransaction", new object[] { RefundTransactionReq}, this.RefundTransactionOperationCompleted, userState); }
/// <summary> /// Refunds the specified transaction id. /// </summary> /// <param name="transactionId">The transaction id.</param> /// <param name="args">The args.</param> /// <returns></returns> internal Transaction Refund(Transaction transaction, Order order) { Transaction refundTransaction = null; RefundTransactionRequestType refundTransactionRequestType = new RefundTransactionRequestType(); if(order != null ) { if(order.Total == transaction.GrossAmount) { refundTransactionRequestType.RefundType = RefundType.Full; } else { refundTransactionRequestType.RefundType = RefundType.Partial; } } else { refundTransactionRequestType.RefundType = RefundType.Full; } refundTransactionRequestType.RefundTypeSpecified = true; refundTransactionRequestType.Version = PayPalServiceUtility.PayPalVersionNumber; refundTransactionRequestType.TransactionID = transaction.GatewayTransactionId; //Note: Only specify amount in partial refund if(refundTransactionRequestType.RefundType == RefundType.Partial) { Currency currency = new Currency(); decimal total = GetOrderTotal(currency, order); refundTransactionRequestType.Amount = GetBasicAmount(total); } RefundTransactionReq refundTransactionRequest = new RefundTransactionReq(); refundTransactionRequest.RefundTransactionRequest = refundTransactionRequestType; RefundTransactionResponseType refundTransactionResponseType = payPalAPISoapBinding.RefundTransaction(refundTransactionRequest); string errorList = ValidateResponse(refundTransactionResponseType); if(refundTransactionResponseType.Ack != AckCodeType.Success || refundTransactionResponseType.Ack != AckCodeType.SuccessWithWarning) { if(!string.IsNullOrEmpty(errorList)) { throw new PayPalServiceException(errorList); } } refundTransaction = new Transaction(); refundTransaction.OrderId = transaction.OrderId; refundTransaction.TransactionTypeDescriptorId = (int)TransactionType.Refund; refundTransaction.PaymentMethod = PAYPAL; refundTransaction.GatewayName = PAYPALPRO; refundTransaction.GatewayResponse = refundTransactionResponseType.Ack.ToString(); refundTransaction.GatewayTransactionId = refundTransactionResponseType.RefundTransactionID; decimal grossAmount = 0.00M; decimal.TryParse(refundTransactionResponseType.GrossRefundAmount.Value, out grossAmount); refundTransaction.GrossAmount = grossAmount; decimal netAmount = 0.00M; decimal.TryParse(refundTransactionResponseType.NetRefundAmount.Value, out netAmount); refundTransaction.NetAmount = netAmount; decimal feeAmount = 0.00M; decimal.TryParse(refundTransactionResponseType.FeeRefundAmount.Value, out feeAmount); refundTransaction.FeeAmount = feeAmount; refundTransaction.TransactionDate = DateTime.Now; refundTransaction.GatewayErrors = errorList; return refundTransaction; }
/// <remarks/> public void RefundTransactionAsync(RefundTransactionReq RefundTransactionReq) { this.RefundTransactionAsync(RefundTransactionReq, null); }