protected void Submit_Click(object sender, EventArgs e) { // Create request object RefundTransactionRequestType request = new RefundTransactionRequestType(); request.TransactionID = transactionId.Value; if (refundType.SelectedIndex != 0) { request.RefundType = (RefundType) Enum.Parse(typeof(RefundType), refundType.SelectedValue); if (request.RefundType.Equals(RefundType.PARTIAL) && refundAmount.Value != "") { CurrencyCodeType currency = (CurrencyCodeType) Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue); request.Amount = new BasicAmountType(currency, refundAmount.Value); } } if (memo.Value != "") { request.Memo = memo.Value; } if (retryUntil.Text != "") { request.RetryUntil = retryUntil.Text; } if (refundSource.SelectedIndex != 0) { request.RefundSource = (RefundSourceCodeType) Enum.Parse(typeof(RefundSourceCodeType), refundSource.SelectedValue); } // Invoke the API RefundTransactionReq wrapper = new RefundTransactionReq(); wrapper.RefundTransactionRequest = request; PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(); RefundTransactionResponseType refundTransactionResponse = service.RefundTransaction(wrapper); // Check for API return status processResponse(service, refundTransactionResponse); }
/// <summary> /// Refunds a payment /// </summary> /// <param name="refundPaymentRequest">Request</param> /// <returns>Result</returns> public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { var result = new RefundPaymentResult(); string transactionId = refundPaymentRequest.Order.CaptureTransactionId; var req = new RefundTransactionReq(); req.RefundTransactionRequest = new RefundTransactionRequestType(); //NOTE: Specify amount in partial refund req.RefundTransactionRequest.RefundType = RefundType.FULL; req.RefundTransactionRequest.Version = GetApiVersion(); req.RefundTransactionRequest.TransactionID = transactionId; var service = GetService(); RefundTransactionResponseType response = service.RefundTransaction(req); string error; bool success = PaypalHelper.CheckSuccess(response, out error); if (success) { result.NewPaymentStatus = PaymentStatus.Refunded; //cancelPaymentResult.RefundTransactionID = response.RefundTransactionID; } else { result.AddError(error); } return result; }
/// <summary> /// /// </summary> ///<param name="refundTransactionReq"></param> ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> public RefundTransactionResponseType RefundTransaction(RefundTransactionReq refundTransactionReq, ICredential credential) { setStandardParams(refundTransactionReq.RefundTransactionRequest); DefaultSOAPAPICallHandler defaultHandler = new DefaultSOAPAPICallHandler(this.config, refundTransactionReq.ToXMLString(null, "RefundTransactionReq"), null, null); IAPICallPreHandler apiCallPreHandler = new MerchantAPICallPreHandler(this.config, defaultHandler, credential); ((MerchantAPICallPreHandler) apiCallPreHandler).SDKName = SDKName; ((MerchantAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion; ((MerchantAPICallPreHandler) apiCallPreHandler).PortName = "PayPalAPI"; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(Call(apiCallPreHandler)); return new RefundTransactionResponseType( xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='RefundTransactionResponse']") ); }
/// <summary> /// /// </summary> ///<param name="refundTransactionReq"></param> public RefundTransactionResponseType RefundTransaction(RefundTransactionReq refundTransactionReq) { return RefundTransaction(refundTransactionReq,(string) null); }
/** *AUTO_GENERATED */ public RefundTransactionResponseType RefundTransaction(RefundTransactionReq refundTransactionReq, string apiUserName) { IAPICallPreHandler apiCallPreHandler = null; string portName = "PayPalAPI"; setStandardParams(refundTransactionReq.RefundTransactionRequest); DefaultSOAPAPICallHandler defaultHandler = new DefaultSOAPAPICallHandler(refundTransactionReq.ToXMLString(null, "RefundTransactionReq"), null, null); apiCallPreHandler = new MerchantAPICallPreHandler(defaultHandler, apiUserName, getAccessToken(), getAccessTokenSecret()); ((MerchantAPICallPreHandler) apiCallPreHandler).SDKName = SDKName; ((MerchantAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion; ((MerchantAPICallPreHandler) apiCallPreHandler).PortName = portName; string response = Call(apiCallPreHandler); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(response); XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='RefundTransactionResponse']"); return new RefundTransactionResponseType(xmlNode); }
public IPaymentResult RefundPayment(IInvoice invoice, IPayment payment) { var transactionId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.TransactionId); var wrapper = new RefundTransactionReq { RefundTransactionRequest = { TransactionID = transactionId, RefundType = RefundType.FULL } }; RefundTransactionResponseType refundTransactionResponse = GetPayPalService().RefundTransaction(wrapper); if (refundTransactionResponse.Ack != AckCodeType.SUCCESS && refundTransactionResponse.Ack != AckCodeType.SUCCESSWITHWARNING) { return new PaymentResult(Attempt<IPayment>.Fail(payment), invoice, false); } return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true); }
/// <summary> /// Refunds a payment /// </summary> /// <param name="refundPaymentRequest">Request</param> /// <returns>Result</returns> public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { var result = new RefundPaymentResult(); string transactionId = refundPaymentRequest.Order.CaptureTransactionId; var req = new RefundTransactionReq(); req.RefundTransactionRequest = new RefundTransactionRequestType { Version = GetApiVersion(), TransactionID = transactionId }; if (refundPaymentRequest.IsPartialRefund) { req.RefundTransactionRequest.RefundType = RefundType.PARTIAL; req.RefundTransactionRequest.Amount = new BasicAmountType { currencyID = PaypalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)), value = refundPaymentRequest.AmountToRefund.ToString() }; } else req.RefundTransactionRequest.RefundType = RefundType.FULL; var service = GetService(); RefundTransactionResponseType response = service.RefundTransaction(req); string error; bool success = PaypalHelper.CheckSuccess(response, out error); if (success) { result.NewPaymentStatus = (refundPaymentRequest.IsPartialRefund && refundPaymentRequest.Order.RefundedAmount + refundPaymentRequest.AmountToRefund < refundPaymentRequest.Order.OrderTotal) ? PaymentStatus.PartiallyRefunded : PaymentStatus.Refunded; //set refund transaction id for preventing refund twice _genericAttributeService.SaveAttribute(refundPaymentRequest.Order, "RefundTransactionId", response.RefundTransactionID); } else result.AddError(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; }
protected void Submit_Click(object sender, EventArgs e) { // Create request object RefundTransactionRequestType request = new RefundTransactionRequestType(); // (Required) Unique identifier of the transaction to be refunded. // Note: Either the transaction ID or the payer ID must be specified. request.TransactionID = transactionId.Value; // Type of refund you are making. It is one of the following values: // * Full – Full refund (default). // * Partial – Partial refund. // * ExternalDispute – External dispute. (Value available since version 82.0) // * Other – Other type of refund. (Value available since version 82.0) if (refundType.SelectedIndex != 0) { request.RefundType = (RefundType) Enum.Parse(typeof(RefundType), refundType.SelectedValue); // (Optional) Refund amount. The amount is required if RefundType is Partial. // Note: If RefundType is Full, do not set the amount. if (request.RefundType.Equals(RefundType.PARTIAL) && refundAmount.Value != string.Empty) { CurrencyCodeType currency = (CurrencyCodeType) Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue); request.Amount = new BasicAmountType(currency, refundAmount.Value); } } // (Optional) Custom memo about the refund. if (memo.Value != string.Empty) { request.Memo = memo.Value; } // (Optional) Maximum time until you must retry the refund. if (retryUntil.Text != string.Empty) { request.RetryUntil = retryUntil.Text; } // (Optional)Type of PayPal funding source (balance or eCheck) that can be used for auto refund. It is one of the following values: // * any – The merchant does not have a preference. Use any available funding source. // * default – Use the merchant's preferred funding source, as configured in the merchant's profile. // * instant – Use the merchant's balance as the funding source. // * eCheck – The merchant prefers using the eCheck funding source. If the merchant's PayPal balance can cover the refund amount, use the PayPal balance. // Note: This field does not apply to point-of-sale transactions. if (refundSource.SelectedIndex != 0) { request.RefundSource = (RefundSourceCodeType) Enum.Parse(typeof(RefundSourceCodeType), refundSource.SelectedValue); } // Invoke the API RefundTransactionReq wrapper = new RefundTransactionReq(); wrapper.RefundTransactionRequest = request; // Configuration map containing signature credentials and other required configuration. // For a full list of configuration parameters refer in wiki page // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters] Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig(); // Create the PayPalAPIInterfaceServiceService service object to make the API call PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap); // # API call // Invoke the RefundTransaction method in service wrapper object RefundTransactionResponseType refundTransactionResponse = service.RefundTransaction(wrapper); // Check for API return status processResponse(service, refundTransactionResponse); }
private RefundTransactionReq GetRefundTransactionRequest(PaymentIn payment) { var retVal = new RefundTransactionReq(); retVal.RefundTransactionRequest = new RefundTransactionRequestType(); retVal.RefundTransactionRequest.TransactionID = payment.OuterId; //retVal.RefundTransactionRequest.Amount return retVal; }
/** *AUTO_GENERATED */ public RefundTransactionResponseType RefundTransaction(RefundTransactionReq refundTransactionReq, string apiUserName) { setStandardParams(refundTransactionReq.RefundTransactionRequest); string response = Call("RefundTransaction", refundTransactionReq.ToXMLString(), apiUserName); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(response); XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='RefundTransactionResponse']"); return new RefundTransactionResponseType(xmlNode); }
public RefundTransactionResponseType RefundTransaction(RefundTransactionReq RefundTransactionReq) { return RefundTransaction(RefundTransactionReq, null); }
/** * */ public RefundTransactionResponseType RefundTransaction(RefundTransactionReq RefundTransactionReq, string apiUsername) { setStandardParams(RefundTransactionReq.RefundTransactionRequest); string resp = call("RefundTransaction", RefundTransactionReq.toXMLString(), apiUsername); return new RefundTransactionResponseType(resp); }
// # RefundTransaction API Operation // The RefundTransaction API operation issues a refund to the PayPal account holder associated with a transaction public RefundTransactionResponseType RefundTransactionAPIOperation() { // Create the RefundTransactionResponseType object RefundTransactionResponseType responseRefundTransactionResponseType = new RefundTransactionResponseType(); try { // Create the RefundTransactionReq object RefundTransactionReq refundTransaction = new RefundTransactionReq(); RefundTransactionRequestType refundTransactionRequest = new RefundTransactionRequestType(); // Either the `transaction ID` or the `payer ID` must be specified. // PayerID is unique encrypted merchant identification number // For setting `payerId`, // `refundTransactionRequest.PayerID = "A9BVYX8XCR9ZQ";` // Unique identifier of the transaction to be refunded. refundTransactionRequest.TransactionID = "1GF88795WC5643301"; // Type of refund you are making. It is one of the following values: // // * `Full` - Full refund (default). // * `Partial` - Partial refund. // * `ExternalDispute` - External dispute. (Value available since version // 82.0) // * `Other` - Other type of refund. (Value available since version 82.0) refundTransactionRequest.RefundType = RefundType.PARTIAL; // `Refund amount`, which contains // // * `Currency Code` // * `Amount` // The amount is required if RefundType is Partial. // `Note: // If RefundType is Full, do not set the amount.` BasicAmountType amount = new BasicAmountType(CurrencyCodeType.USD, "1.00"); refundTransactionRequest.Amount = amount; refundTransaction.RefundTransactionRequest = refundTransactionRequest; // Create the service wrapper object to make the API call PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(); // # API call // Invoke the RefundTransaction method in service wrapper object responseRefundTransactionResponseType = service.RefundTransaction(refundTransaction); if (responseRefundTransactionResponseType != null) { // Response envelope acknowledgement string acknowledgement = "RefundTransaction API Operation - "; acknowledgement += responseRefundTransactionResponseType.Ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseRefundTransactionResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // Unique transaction ID of the refund logger.Info("Refund Transaction ID : " + responseRefundTransactionResponseType.RefundTransactionID + "\n"); Console.WriteLine("Refund Transaction ID : " + responseRefundTransactionResponseType.RefundTransactionID + "\n"); } // # Error Values else { List<ErrorType> errorMessages = responseRefundTransactionResponseType.Errors; foreach (ErrorType error in errorMessages) { logger.Debug("API Error Message : " + error.LongMessage); Console.WriteLine("API Error Message : " + error.LongMessage + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message logger.Debug("Error Message : " + ex.Message); Console.WriteLine("Error Message : " + ex.Message); } return responseRefundTransactionResponseType; }