public ITransactionRefundResult Refund(ITransactionRefundRequest request) { //to refund a transaction, we'll need capture id previously obtained from paypal var captureId = request.GetParameterAs <string>(PaymentParameterNames.CaptureId); var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode); //create a capture request for paypal var doRefundRequest = new RefundTransactionReq() { RefundTransactionRequest = new RefundTransactionRequestType() { Version = ApiVersion, TransactionID = captureId, Amount = new BasicAmountType() { value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-us")), currencyID = paypalCurrency }, RefundType = request.IsPartialRefund ? RefundType.PARTIAL : RefundType.FULL } }; //get the service for paypal api var service = GetPayPalApiInterfaceServiceService(); var paypalResponse = service.RefundTransaction(doRefundRequest); var result = new TransactionResult(); string error; var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error); if (success) { result.Success = true; result.SetParameter(PaymentParameterNames.RefundId, paypalResponse.RefundTransactionID); result.SetParameter(PaymentParameterNames.RefundResult, paypalResponse.Ack); } else { result.SetParameter(PaymentParameterNames.ErrorMessage, error); } return(result); }
public ITransactionRefundResult Refund(ITransactionRefundRequest request) { //to refund a transaction, we'll need capture id previously obtained from paypal var captureId = request.GetParameterAs<string>(PaymentParameterNames.CaptureId); var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode); //create a capture request for paypal var doRefundRequest = new RefundTransactionReq() { RefundTransactionRequest = new RefundTransactionRequestType() { Version = ApiVersion, TransactionID = captureId, Amount = new BasicAmountType() { value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-us")), currencyID = paypalCurrency }, RefundType = request.IsPartialRefund ? RefundType.PARTIAL : RefundType.FULL } }; //get the service for paypal api var service = GetPayPalApiInterfaceServiceService(); var paypalResponse = service.RefundTransaction(doRefundRequest); var result = new TransactionResult(); string error; var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error); if (success) { result.Success = true; result.SetParameter(PaymentParameterNames.RefundId, paypalResponse.RefundTransactionID); result.SetParameter(PaymentParameterNames.RefundResult, paypalResponse.Ack); } else { result.SetParameter(PaymentParameterNames.ErrorMessage, error); } return result; }