Exemplo n.º 1
0
        public void RefundTransaction(string TransactionID)
        {
            RefundTransactionRequestType refundRequest = new RefundTransactionRequestType();
            BasicAmountType amount = new BasicAmountType();

            amount.currencyID           = CurrencyCodeType.USD;
            refundRequest.Memo          = "Transaction ID: " + TransactionID;
            refundRequest.RefundType    = RefundPurposeTypeCodeType.Full;
            refundRequest.TransactionID = TransactionID;
            refundRequest.Version       = "2.0";

            RefundTransactionReq request = new RefundTransactionReq();

            request.RefundTransactionRequest = refundRequest;

            try
            {
                RefundTransactionResponseType response = service.RefundTransaction(request);
                string errors = CheckForErrors(response);

                if (errors == string.Empty)
                {
                    IsSubmissionSuccess = true;
                }
                else
                {
                    IsSubmissionSuccess = false;
                    SubmissionError     = errors;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Refunds or partially refunds a payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="amount">
        /// The amount of the refund.
        /// </param>
        /// <returns>
        /// The <see cref="PayPalExpressTransactionRecord"/>.
        /// </returns>
        public ExpressCheckoutResponse Refund(IInvoice invoice, IPayment payment, decimal amount)
        {
            var record = payment.GetPayPalTransactionRecord();

            // Ensure the currency code
            if (record.Data.CurrencyCode.IsNullOrWhiteSpace())
            {
                var ex = new PayPalApiException("CurrencyCode was not found in payment extended data PayPal transaction data record.  Cannot perform refund.");
                return(_responseFactory.Build(ex));
            }

            // Ensure the transaction id
            if (record.Data.CaptureTransactionId.IsNullOrWhiteSpace())
            {
                var ex = new PayPalApiException("CaptureTransactionId was not found in payment extended data PayPal transaction data record.  Cannot perform refund.");
                return(_responseFactory.Build(ex));
            }

            // Get the decimal configuration for the current currency
            var currencyCodeType   = PayPalApiHelper.GetPayPalCurrencyCode(record.Data.CurrencyCode);
            var basicAmountFactory = new PayPalBasicAmountTypeFactory(currencyCodeType);

            ExpressCheckoutResponse result = null;

            if (amount > payment.Amount)
            {
                amount = payment.Amount;
            }

            try
            {
                var request = new RefundTransactionRequestType
                {
                    InvoiceID     = invoice.PrefixedInvoiceNumber(),
                    PayerID       = record.Data.PayerId,
                    RefundSource  = RefundSourceCodeType.DEFAULT,
                    Version       = record.DoCapture.Version,
                    TransactionID = record.Data.CaptureTransactionId,
                    Amount        = basicAmountFactory.Build(amount)
                };

                var wrapper = new RefundTransactionReq {
                    RefundTransactionRequest = request
                };

                var refundTransactionResponse = GetPayPalService().RefundTransaction(wrapper);

                result = _responseFactory.Build(refundTransactionResponse, record.Data.Token);
            }
            catch (Exception ex)
            {
                result = _responseFactory.Build(ex);
            }

            return(result);
        }
        /// <summary>
        /// Process payment when a refund request happens.
        /// </summary>
        /// <remarks>
        /// <para>
        /// See API doc here https://www.x.com/developers/paypal/documentation-tools/api/refundtransaction-api-operation-soap
        /// </para>
        /// <para>
        /// You may offer a refund only for a limited time, usually 60 days. If you need to make a refund after that time, you will need to initiate a new PayPal payment to your buyer.
        /// If you offer the buyer a partial refund, she has 10 days to decline it if she wishes. (Full refunds are automatically processed.)
        /// </para>
        /// </remarks>
        /// <param name="payment">The payment to process.</param>
        /// <param name="orderGroup">The order group to process.</param>
        /// <returns>True if refund was completed, otherwise false and set the message will make the WorkFlow activity raise PaymentExcetion(message).</returns>
        private PaymentProcessingResult ProcessPaymentRefund(IOrderGroup orderGroup, IPayment payment)
        {
            // Implement refund feature logic for current payment gateway
            var refundAmount  = payment.Amount;
            var purchaseOrder = (orderGroup as IPurchaseOrder);

            if (purchaseOrder == null || refundAmount <= 0)
            {
                return(PaymentProcessingResult.CreateUnsuccessfulResult(Utilities.Translate("PayPalRefundError")));
            }

            // Call payment gateway API to do refund business
            // Create the Refund Request
            var refundRequest = new RefundTransactionRequestType
            {
                TransactionID = payment.ProviderTransactionID, // original transactionID (which payPal gave us when do ExpressCheckout)
                Memo          = $"[{payment.PaymentMethodName}-{payment.TransactionID}] refunds {refundAmount}{purchaseOrder.Currency} for [PurchaseOrder-{purchaseOrder.OrderNumber}]",
                // NOTE: If RefundType is Full, do not set the amount.
                // refundRequest.RefundType = RefundType.Full; //refund a full or partial amount
                RefundType = RefundType.PARTIAL,                                                //refund a partial amount
                Amount     = _payPalAPIHelper.ToPayPalAmount(refundAmount, orderGroup.Currency) // if refund with Partial, we have to set the Amount
            };

            var caller         = PayPalAPIHelper.GetPayPalAPICallerServices(_paymentMethodConfiguration);
            var refundResponse = caller.RefundTransaction(new RefundTransactionReq {
                RefundTransactionRequest = refundRequest
            });
            var errorCheck = _payPalAPIHelper.CheckErrors(refundResponse);

            if (!string.IsNullOrEmpty(errorCheck))
            {
                _logger.Error(errorCheck);
                return(PaymentProcessingResult.CreateUnsuccessfulResult(PaymentTransactionFailedMessage));
            }

            // Extract the response details.
            payment.TransactionID = refundResponse.RefundTransactionID;

            var message = $"[{payment.PaymentMethodName}] [RefundTransaction-{refundResponse.RefundTransactionID}] " +
                          $"Response: {refundResponse.Ack.ToString()} at Timestamp={refundResponse.Timestamp.ToString()}: {refundResponse.GrossRefundAmount.value}{refundResponse.GrossRefundAmount.currencyID}";

            // add a new order note about this refund
            AddNoteToPurchaseOrder("REFUND", message, purchaseOrder.CustomerId, purchaseOrder);

            _orderRepository.Save(purchaseOrder);

            return(PaymentProcessingResult.CreateSuccessfulResult(message));
        }
Exemplo n.º 4
0
        public RefundTransactionResponseType RefundTransaction(string trxID, string refundType, string amount)
        {
            // Create the request object
            RefundTransactionRequestType concreteRequest = new RefundTransactionRequestType();

            concreteRequest.TransactionID = trxID;

            concreteRequest.RefundType          = RefundType.Partial;
            concreteRequest.RefundTypeSpecified = true;
            concreteRequest.Amount = new BasicAmountType();

            concreteRequest.Amount.currencyID = CurrencyCodeType.USD;
            concreteRequest.Amount.Value      = amount;

            return((RefundTransactionResponseType)caller.Call("RefundTransaction", concreteRequest));
        }
Exemplo n.º 5
0
        public RefundTransactionResponseType RefundTransaction(string trxID, string refundType, string amount,
                                                               CurrencyCodeType storeCurrency)
        {
            // Create the request object
            var concreteRequest = new RefundTransactionRequestType
            {
                TransactionID       = trxID,
                RefundType          = RefundType.Partial,
                RefundTypeSpecified = true,
                Amount = new BasicAmountType
                {
                    currencyID = storeCurrency,
                    Value      = amount
                }
            };

            return((RefundTransactionResponseType)caller.Call("RefundTransaction", concreteRequest));
        }
Exemplo n.º 6
0
        public string RefundTransaction(string TransactionID, bool DoFullRefund)
        {
            string sReturn = "";

            // Create the Refund Request
            RefundTransactionRequestType refundRequest = new RefundTransactionRequestType();
            BasicAmountType amount = new BasicAmountType();

            CurrencyCodeType currType = (CurrencyCodeType)this._currencyCode;

            amount.currencyID = currType;

            if (DoFullRefund)
            {
                refundRequest.RefundType = RefundType.Full;
            }
            else
            {
                refundRequest.RefundType = RefundType.Partial;
            }
            refundRequest.TransactionID = TransactionID;
            refundRequest.Version       = PayPalServiceUtility.PayPalAPIVersionNumber;

            RefundTransactionReq request = new RefundTransactionReq();

            request.RefundTransactionRequest = refundRequest;

            try {
                RefundTransactionResponseType response = service.RefundTransaction(request);
                string ErrorCheck = CheckErrors(response);
                if (ErrorCheck != "")
                {
                    sReturn = ErrorCheck;
                }
                else
                {
                    sReturn = "Success";
                }
            }
            catch (Exception x) {
                sReturn = "SSL Failure, the transaction did not go through. Error: " + x.Message;
            }
            return(sReturn);
        }
Exemplo n.º 7
0
        public string RefundTransaction(string TransactionID, decimal RefundAmount, string Memo, string currencyCode)
        {
            string           sReturn  = "";
            CurrencyCodeType currType = (CurrencyCodeType)StringToEnum(typeof(CurrencyCodeType), currencyCode);
            // Create the Refund Request
            RefundTransactionRequestType refundRequest = new RefundTransactionRequestType();
            BasicAmountType amount = new BasicAmountType();

            amount.currencyID = currType;

            amount.Value         = RefundAmount.ToString();
            refundRequest.Memo   = Memo;
            refundRequest.Amount = amount;


            refundRequest.RefundType    = RefundType.Partial;
            refundRequest.TransactionID = TransactionID;
            refundRequest.Version       = PayPalServiceUtility.PayPalAPIVersionNumber;

            RefundTransactionReq request = new RefundTransactionReq();

            request.RefundTransactionRequest = refundRequest;


            try {
                RefundTransactionResponseType response = service.RefundTransaction(request);

                string ErrorCheck = CheckErrors(response);
                if (ErrorCheck != "")
                {
                    sReturn = ("The transaction was not successful: " + ErrorCheck);
                }
                else
                {
                    sReturn = ("Success");
                }
            }
            catch (Exception x) {
                sReturn = "SSL Failure, the transaction did not go through. Error: " + x.Message;
            }
            return(sReturn);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        // if RefundAmount == 0.0M, then then ENTIRE order amount will be refunded!
        public override string RefundOrder(int OriginalOrderNumber, int NewOrderNumber, decimal RefundAmount, String RefundReason, Address UseBillingAddress)
        {
            String result = String.Empty;

            DB.ExecuteSQL("update orders set RefundTXCommand=NULL, RefundTXResult=NULL where OrderNumber=" + OriginalOrderNumber.ToString());
            String  TransID    = String.Empty;
            Decimal OrderTotal = System.Decimal.Zero;

            using (var con = new SqlConnection(DB.GetDBConn()))
            {
                con.Open();
                using (var rs = DB.GetRS("select * from Orders  with (NOLOCK)  where OrderNumber=" + OriginalOrderNumber.ToString(), con))
                {
                    if (rs.Read())
                    {
                        TransID    = Regex.Match(DB.RSField(rs, "AuthorizationPNREF"), "(?<=CAPTURE=)[0-9A-Z]+", RegexOptions.Compiled).ToString();
                        OrderTotal = DB.RSFieldDecimal(rs, "OrderTotal");
                    }
                }
            }

            if (TransID.Length == 0 || TransID == "0")
            {
                result = "Invalid or Empty Transaction ID";
            }
            else
            {
                try
                {
                    RefundTransactionReq          RefundReq         = new RefundTransactionReq();
                    RefundTransactionRequestType  RefundRequestType = new RefundTransactionRequestType();
                    RefundTransactionResponseType RefundResponse;
                    BasicAmountType BasicAmount = new BasicAmountType();

                    RefundRequestType.TransactionID = TransID;
                    RefundRequestType.Version       = API_VER;

                    BasicAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true);

                    //If partial refund set value ( like 1.95). If FULL Refund leave it empty. The transactionID will take care of the amount
                    if (OrderTotal == RefundAmount || RefundAmount == 0.0M)
                    {
                        RefundRequestType.RefundType = RefundType.Full;
                    }
                    else
                    {
                        BasicAmount.Value            = Localization.CurrencyStringForGatewayWithoutExchangeRate(RefundAmount);
                        RefundRequestType.RefundType = RefundType.Partial;
                    }
                    RefundRequestType.Amount = BasicAmount;
                    RefundRequestType.RefundTypeSpecified = true;

                    if (!String.IsNullOrEmpty(RefundReason))
                    {
                        RefundRequestType.Memo = RefundReason;
                    }

                    RefundReq.RefundTransactionRequest = RefundRequestType;

                    DB.ExecuteSQL("update orders set RefundTXCommand=" + DB.SQuote(XmlCommon.SerializeObject(RefundRequestType, RefundRequestType.GetType())) + " where OrderNumber=" + OriginalOrderNumber.ToString());

                    RefundResponse = (RefundTransactionResponseType)IPayPalRefund.RefundTransaction(RefundReq);


                    //if (LogToErrorTable)
                    //{
                    //    PayPalController.Log(XmlCommon.SerializeObject(RefundReq, RefundReq.GetType()), "RefundTransaction Request");
                    //    PayPalController.Log(XmlCommon.SerializeObject(RefundResponse, RefundResponse.GetType()), "RefundTransaction Response");
                    //}

                    DB.ExecuteSQL("update orders set RefundTXCommand=" + DB.SQuote(XmlCommon.SerializeObject(RefundReq, RefundReq.GetType()))
                                  + ", RefundTXResult=" + DB.SQuote(XmlCommon.SerializeObject(RefundResponse, RefundResponse.GetType())) + " where OrderNumber=" + OriginalOrderNumber.ToString());

                    String RefundTXResult = String.Empty;
                    if (RefundResponse != null && RefundResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase))
                    {
                        result = AppLogic.ro_OK;
                        String RefundTransID = RefundResponse.RefundTransactionID;
                        DB.ExecuteSQL("update orders set AuthorizationPNREF=AuthorizationPNREF+'|REFUND=" + RefundTransID + "' where OrderNumber=" + OriginalOrderNumber.ToString());
                    }
                    else
                    {
                        if (RefundResponse.Errors != null)
                        {
                            bool first = true;
                            for (int ix = 0; ix < RefundResponse.Errors.Length; ix++)
                            {
                                if (!first)
                                {
                                    result += ", ";
                                }
                                result += "Error: [" + RefundResponse.Errors[ix].ErrorCode + "] " + RefundResponse.Errors[ix].LongMessage;
                                first   = false;
                            }

                            result += "Note: If you are using Accelerated Boarding for PayPal Express you will not be able to modify orders until you sign up for a full account and enter your API credentials.";
                        }
                    }
                }
                catch
                {
                    result = "NO RESPONSE FROM GATEWAY!";
                }
            }
            return(result);
        }
Exemplo n.º 10
0
        public RefundTransactionResponseType RefundTransaction(string trxID, string refundType, string amount)
        {
            // Create the request object
            RefundTransactionRequestType concreteRequest = new RefundTransactionRequestType();
            concreteRequest.TransactionID = trxID;
                        
            concreteRequest.RefundType = RefundType.Partial;
            concreteRequest.RefundTypeSpecified = true;
            concreteRequest.Amount = new BasicAmountType();

            concreteRequest.Amount.currencyID = CurrencyCodeType.USD;
            concreteRequest.Amount.Value = amount;            

            return (RefundTransactionResponseType)caller.Call("RefundTransaction", concreteRequest);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Refunds or partially refunds a payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="amount">
        /// The amount of the refund.
        /// </param>
        /// <returns>
        /// The <see cref="PayPalExpressTransactionRecord"/>.
        /// </returns>
        public ExpressCheckoutResponse Refund(IInvoice invoice, IPayment payment, decimal amount)
        {
            var record = payment.GetPayPalTransactionRecord();

            // Ensure the currency code
            if (record.Data.CurrencyCode.IsNullOrWhiteSpace())
            {
                var ex = new PayPalApiException("CurrencyCode was not found in payment extended data PayPal transaction data record.  Cannot perform refund.");
                return _responseFactory.Build(ex);
            }

            // Ensure the transaction id
            if (record.Data.CaptureTransactionId.IsNullOrWhiteSpace())
            {
                var ex = new PayPalApiException("CaptureTransactionId was not found in payment extended data PayPal transaction data record.  Cannot perform refund.");
                return _responseFactory.Build(ex);
            }

            // Get the decimal configuration for the current currency
            var currencyCodeType = PayPalApiHelper.GetPayPalCurrencyCode(record.Data.CurrencyCode);
            var basicAmountFactory = new PayPalBasicAmountTypeFactory(currencyCodeType);

            ExpressCheckoutResponse result = null;

            if (amount > payment.Amount) amount = payment.Amount;

            try
            {
                var request = new RefundTransactionRequestType
                    {
                        InvoiceID = invoice.PrefixedInvoiceNumber(),
                        PayerID = record.Data.PayerId,
                        RefundSource = RefundSourceCodeType.DEFAULT,
                        Version = record.DoCapture.Version,
                        TransactionID = record.Data.CaptureTransactionId,
                        Amount = basicAmountFactory.Build(amount)
                    };

                var wrapper = new RefundTransactionReq { RefundTransactionRequest = request };

                var refundTransactionResponse = GetPayPalService().RefundTransaction(wrapper);

                result = _responseFactory.Build(refundTransactionResponse, record.Data.Token);
            }
            catch (Exception ex)
            {
                result = _responseFactory.Build(ex);
            }

            return result;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Credits the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialTransaction Credit(FinancialTransaction transaction, decimal amount, string comment, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (transaction == null ||
                string.IsNullOrWhiteSpace(transaction.TransactionCode) ||
                transaction.FinancialGateway == null)
            {
                errorMessage = "Invalid original transaction, transaction code, or gateway.";
                return(null);
            }

            // Create the RefundTransactionResponseType object
            RefundTransactionResponseType responseRefundTransactionResponseType = new RefundTransactionResponseType();

            try
            {
                // Create the RefundTransactionReq object
                RefundTransactionReq         refundTransaction        = new RefundTransactionReq();
                RefundTransactionRequestType refundTransactionRequest = new RefundTransactionRequestType();

                refundTransactionRequest.TransactionID = transaction.TransactionCode;
                refundTransactionRequest.RefundType    = RefundType.FULL;

                // Set the amount
                refundTransactionRequest.Amount = new BasicAmountType(CurrencyCodeType.USD, amount.ToString());

                refundTransaction.RefundTransactionRequest = refundTransactionRequest;

                // Create the service wrapper object to make the API call
                PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(GetCredentials(transaction.FinancialGateway));

                // # API call
                // Invoke the RefundTransaction method in service wrapper object
                responseRefundTransactionResponseType = service.RefundTransaction(refundTransaction);

                if (responseRefundTransactionResponseType != null)
                {
                    // # Success values
                    if (responseRefundTransactionResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                    {
                        var refundFinancialTransaction = new FinancialTransaction();
                        refundFinancialTransaction.TransactionCode = responseRefundTransactionResponseType.RefundTransactionID;
                        return(refundFinancialTransaction);
                    }
                    // # Error Values
                    else
                    {
                        List <ErrorType> errorMessages = responseRefundTransactionResponseType.Errors;
                        foreach (ErrorType error in errorMessages)
                        {
                            errorMessage = string.Format("[{0}] {1}", responseRefundTransactionResponseType.Ack, error.LongMessage);
                        }
                    }
                }
                else
                {
                    errorMessage = "Invalid transaction response from the financial gateway";
                }
            }
            catch (System.Exception ex)
            {
                // Log the exception message
                errorMessage = ex.Message;
            }
            return(null);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
    // # 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);
    }