Example #1
0
        public void RefundTransaction_PartialRefund_Success()
        {
            var response = transactionService.CreateTransaction(createTransactionRequest);

            CaptureTransactionRequest captureRequest = new CaptureTransactionRequest()
            {
                Amount        = createTransactionRequest.Amount,
                Currency      = createTransactionRequest.Currency,
                TransactionId = response.Content.Id
            };

            var captureResponse = transactionService.CaptureTransaction(captureRequest);

            var refundRequest = new RefundTransactionRequest()
            {
                TransactionId = captureResponse.Content.Id,
                Amount        = captureResponse.Content.Amount - 1
            };

            var refundResponse = transactionService.RefundTransaction(refundRequest);

            var transaction = refundResponse.Content;

            Assert.IsFalse(refundResponse.IsError);
            Assert.AreEqual(201, refundResponse.ResponseCode);
            Assert.IsNotNull(transaction.Id);
            Assert.AreEqual(captureResponse.Content.Amount - 1, transaction.RefundedAmount);
            Assert.AreEqual(createTransactionRequest.Amount, transaction.CapturedAmount);
        }
        public override Transaction DoRefund(RefundTransactionRequest creditRequest)
        {
            VerifyGatewayConfig();
            //MAKE SURE WE HAVE THE VALID TRANSACTION ID TO PROCESS REFUND
            bool        haveTransactionTokens = false;
            Transaction captureTransaction    = creditRequest.CaptureTransaction;

            if (captureTransaction != null)
            {
                string authCode = captureTransaction.AuthorizationCode;
                haveTransactionTokens = authCode.Contains(":");
            }
            if (!haveTransactionTokens)
            {
                return(Transaction.CreateErrorTransaction(this.PaymentGatewayId, TransactionType.Refund, creditRequest.Amount, string.Empty, "AbleCommerce does not have enough information to process the refund request.", creditRequest.RemoteIP));
            }
            //BUILD THE REFUND REQUEST
            string requestData = BuildRefundRequest(creditRequest);

            //RECORD REQUEST
            if (this.UseDebugMode)
            {
                this.RecordCommunication(this.Name, CommunicationDirection.Send, requestData, null);
            }
            //SEND REQUEST AND GET RESPONE
            String responseData = SendRequest(requestData);

            //RECORD RESPONSE
            if (this.UseDebugMode)
            {
                this.RecordCommunication(this.Name, CommunicationDirection.Receive, responseData, null);
            }
            //PARSE RESPONSE AND RETURN RESULT
            return(ProcessRefundResponse(responseData, creditRequest.Amount));
        }
Example #3
0
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result = new RefundPaymentResult();

            var refundRequest = new RefundTransactionRequest()
            {
                Amount        = (int)(Math.Round(refundPaymentRequest.AmountToRefund, 2) * 100),
                Descriptor    = _paylikePaymentSettings.RefundDescriptor,
                TransactionId = refundPaymentRequest.Order.CaptureTransactionId
            };

            var refundResponse = _paylikeTransactionService.RefundTransaction(refundRequest);

            if (refundResponse.IsError)
            {
                result.AddError(refundResponse.ErrorMessage);
                result.AddError(refundResponse.ErrorContent);
            }
            else
            {
                if (refundPaymentRequest.IsPartialRefund)
                {
                    result.NewPaymentStatus = PaymentStatus.PartiallyRefunded;
                }
                else
                {
                    result.NewPaymentStatus = PaymentStatus.Refunded;
                }
            }

            return(result);
        }
Example #4
0
        public void TestSimpleSalePaymentWithPartialRefund()
        {
            var paymentRequest = new PaymentRequest(merchantInfo, sessionToken, currency, amount, paymentOptionCard)
            {
                Items = items
            };

            var paymentResponse = requestExecutor.Payment(paymentRequest).GetAwaiter().GetResult();

            var request = new RefundTransactionRequest(
                merchantInfo,
                sessionToken,
                currency,
                "2",
                paymentResponse.TransactionId);

            var response = requestExecutor.RefundTransaction(request).GetAwaiter().GetResult();

            Assert.IsNotNull(response);
            Assert.IsEmpty(response.Reason);
            Assert.AreEqual(ResponseStatus.Success, response.Status);
            Assert.IsNull(response.GwErrorReason);
            Assert.IsNull(response.PaymentMethodErrorReason);
            Assert.AreNotEqual(ApiConstants.TransactionStatusError, response.TransactionStatus);
        }
Example #5
0
        public override Transaction DoRefund(RefundTransactionRequest creditRequest)
        {
            Payment payment = creditRequest.Payment;

            if (payment == null)
            {
                throw new ArgumentNullException("request.Payment");
            }
            return(CreateTransaction(creditRequest.TransactionType, creditRequest.Amount));
        }
        public override Transaction DoRefund(RefundTransactionRequest creditRequest)
        {
            VerifyStatus();
            Payment payment = creditRequest.Payment;

            if (payment == null)
            {
                throw new ArgumentNullException("request.Payment");
            }
            Transaction captureTransaction = creditRequest.CaptureTransaction;

            if (captureTransaction == null)
            {
                throw new ArgumentNullException("transactionRequest.AuthorizeTransaction");
            }

            CreditCardRequest request = InitializeRefundRequest(payment, captureTransaction, creditRequest.Amount);

            CreditCardResponse response = null;

            //RECORD REQUEST
            if (this.UseDebugMode)
            {
                string reqDebug = BuildRequestDebug(request);
                this.RecordCommunication(this.Name, CommunicationDirection.Send, reqDebug, null);
            }

            //TODO : Test mode is not supported.
            if (this.UseTestMode)
            {
                response = (CreditCardResponse)TransactionClient.doTransaction(request, this.AccountToken);
            }
            else
            {
                response = (CreditCardResponse)TransactionClient.doTransaction(request, this.AccountToken);
            }

            if (response != null)
            {
                //RECORD RESPONSE
                if (this.UseDebugMode)
                {
                    string respDebug = BuildResponseDebug(response);
                    this.RecordCommunication(this.Name, CommunicationDirection.Receive, respDebug, null);
                }
                return(ProcessResponse(payment, response, creditRequest.TransactionType, creditRequest.Amount));
            }
            else
            {
                throw new Exception("Operation Failed, Response is null.");
            }
        }
        public void TestEmptyConstructorsUsedForMappingFromConfigFile()
        {
            _ = new PaymentRequest();
            _ = new SettleTransactionRequest();
            _ = new VoidTransactionRequest();
            _ = new RefundTransactionRequest();
            _ = new GetPaymentStatusRequest();
            _ = new OpenOrderRequest();
            _ = new InitPaymentRequest();
            _ = new Authorize3dRequest();
            _ = new Verify3dRequest();
            _ = new PayoutRequest();
            _ = new GetCardDetailsRequest();
            _ = new GetMerchantPaymentMethodsRequest();

            Assert.Pass();
        }
Example #8
0
        public static Transaction RefundOrder(GoogleCheckout instance, RefundTransactionRequest refundRequest)
        {
            string env         = instance.UseTestMode ? "Sandbox" : "Production";
            string merchantId  = instance.MerchantID;
            string merchantKey = instance.MerchantKey;
            string orderNum    = refundRequest.Payment.Order.GoogleOrderNumber;
            string currency    = refundRequest.Payment.CurrencyCode;

            if (currency == null || currency.Length == 0)
            {
                currency = "USD";
            }
            LSDecimal amount       = refundRequest.Amount;
            LSDecimal totalCharged = refundRequest.Payment.Transactions.GetTotalCaptured();

            RefundOrderRequest request = new RefundOrderRequest(merchantId, merchantKey, env, orderNum, "Refund Requested", currency, amount, "");

            Util.GCheckoutResponse response = request.Send();

            Transaction transaction = new Transaction();

            transaction.Amount = refundRequest.Amount;
            transaction.ProviderTransactionId = orderNum;
            transaction.PaymentGatewayId      = instance.PaymentGatewayId;

            if (totalCharged > amount)
            {
                transaction.TransactionType = TransactionType.PartialRefund;
            }
            else
            {
                transaction.TransactionType = TransactionType.Refund;
            }

            if (response.IsGood)
            {
                transaction.TransactionStatus = TransactionStatus.Pending;
            }
            else
            {
                transaction.TransactionStatus = TransactionStatus.Failed;
                transaction.ResponseMessage   = response.ErrorMessage;
            }

            return(transaction);
        }
Example #9
0
        private void SetRequestForCreditCard(RefundTransactionRequest refundRequest)
        {
            if (HasValue(_AccountData, "AccountNumber"))
            {
                refundRequest.CardNumber = _AccountData["AccountNumber"];
            }
            else
            {
                refundRequest.CardNumber = CreditCardNumber.Text;
            }
            if (HasValue(_AccountData, "ExpirationMonth") && HasValue(_AccountData, "ExpirationYear"))
            {
                refundRequest.ExpirationMonth = AlwaysConvert.ToInt(_AccountData["ExpirationMonth"]);
                refundRequest.ExpirationYear  = AlwaysConvert.ToInt(_AccountData["ExpirationYear"]);
            }
            else
            {
                refundRequest.ExpirationMonth = AlwaysConvert.ToInt(CreditCardExpirationMonth.SelectedValue);
                refundRequest.ExpirationYear  = AlwaysConvert.ToInt(CreditCardExpirationYear.SelectedValue);
            }

            // SET ADDITIONAL FIELDS FOR INTERNATIONAL DEBIT
            if (DebitCardFields.Visible)
            {
                if (HasValue(_AccountData, "IssueNumber"))
                {
                    refundRequest.ExtendedProperties["IssueNumber"] = _AccountData.GetValue("IssueNumber");
                }
                else if (DebitCardIssueNumber.Text.Length > 0)
                {
                    refundRequest.ExtendedProperties["IssueNumber"] = DebitCardIssueNumber.Text;
                }
                if (HasValue(_AccountData, "StartDateMonth") || HasValue(_AccountData, "StartDateYear"))
                {
                    refundRequest.ExtendedProperties["StartDateMonth"] = _AccountData.GetValue("StartDateMonth");
                    refundRequest.ExtendedProperties["StartDateYear"]  = _AccountData.GetValue("StartDateYear");
                }
                else if (DebitCardStartMonth.SelectedIndex > 0 && DebitCardStartYear.SelectedIndex > 0)
                {
                    refundRequest.ExtendedProperties["StartDateMonth"] = DebitCardStartMonth.SelectedValue;
                    refundRequest.ExtendedProperties["StartDateYear"]  = DebitCardStartYear.SelectedValue;
                }
            }
        }
Example #10
0
        public async Task <RefundTransactionResponse> RefundTransaction(
            string currency,
            string amount,
            string relatedTransactionId,
            string clientUniqueId         = null,
            string clientRequestId        = null,
            string userId                 = null,
            UrlDetails urlDetails         = null,
            string authCode               = null,
            string customData             = null,
            string comment                = null,
            string customSiteName         = null,
            string productId              = null,
            DeviceDetails deviceDetails   = null,
            string rebillingType          = null,
            string authenticationTypeOnly = null,
            SubMerchant subMerchant       = null,
            Addendums addendums           = null)
        {
            var request = new RefundTransactionRequest(
                merchantInfo,
                sessionToken,
                currency,
                amount,
                relatedTransactionId)
            {
                AuthCode               = authCode,
                ClientUniqueId         = clientUniqueId,
                ClientRequestId        = clientRequestId,
                UserId                 = userId,
                UrlDetails             = urlDetails,
                CustomData             = customData,
                Comment                = comment,
                CustomSiteName         = customSiteName,
                ProductId              = productId,
                DeviceDetails          = deviceDetails,
                RebillingType          = rebillingType,
                AuthenticationTypeOnly = authenticationTypeOnly,
                SubMerchant            = subMerchant,
                Addendums              = addendums
            };

            return(await safechargeRequestExecutor.RefundTransaction(request));
        }
Example #11
0
        public override Transaction DoRefund(RefundTransactionRequest creditRequest)
        {
            VerifyStatus();
            Payment payment = creditRequest.Payment;

            if (payment == null)
            {
                throw new ArgumentNullException("request.Payment");
            }
            Transaction captureTransaction = creditRequest.CaptureTransaction;

            if (captureTransaction == null)
            {
                throw new ArgumentNullException("transactionRequest.AuthorizeTransaction");
            }

            Dictionary <string, string> sensitiveData = new Dictionary <string, string>();
            string requestData = InitializeRefundRequest(payment, creditRequest, captureTransaction, creditRequest.Amount, sensitiveData);

            //RECORD REQUEST
            if (this.UseDebugMode)
            {
                this.RecordCommunication(this.Name, CommunicationDirection.Send, requestData, sensitiveData);
            }

            string responseData = SendRequestToGateway(requestData);

            if (responseData != null)
            {
                //RECORD RESPONSE
                if (this.UseDebugMode)
                {
                    this.RecordCommunication(this.Name, CommunicationDirection.Receive, responseData, null);
                }

                return(ProcessResponse(payment, responseData, creditRequest.TransactionType, creditRequest.Amount));
            }
            else
            {
                throw new Exception("Operation Failed, Response is null.");
            }
        }
        private string BuildRefundRequest(RefundTransactionRequest creditRequest)
        {
            //INITIALIZE REQUEST FLAGS
            //BUILD THE XML REQUEST
            StringBuilder refundXml = new StringBuilder();

            refundXml.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TranxRequest>");
            refundXml.Append("<xxxTransType>11</xxxTransType>");
            refundXml.Append("<MerchantNumber>" + this.MerchantNumber + "</MerchantNumber>");
            refundXml.Append("<xxxInitialRequest>Y</xxxInitialRequest>");
            refundXml.Append("<xxxAttemptVoid>Y</xxxAttemptVoid>");
            refundXml.Append("</TranxRequest>");
            //RETURN THE REQUEST PROPERLY ENCODED INTO FORM DATA FOR POSTING
            Transaction   captureTransaction = creditRequest.CaptureTransaction;
            StringBuilder formData           = new StringBuilder();
            string        receiptNumber      = captureTransaction.ProviderTransactionId;

            string[] authCode = captureTransaction.AuthorizationCode.Split(":".ToCharArray());
            string   txGuid   = authCode[1];

            formData.Append("xxxRequestMode=X&TRX=" + receiptNumber + "&GUID=" + txGuid + "&xxxRequestData=" + HttpUtility.UrlEncode(refundXml.ToString()));
            return(formData.ToString());
        }
Example #13
0
        public static bool Refund(Cashflow.Message.Data.Transaction transaction, string username, string password)
        {
            if (transaction == null)
            {
                return(false);
            }

            TransactionClient transactionClient = new TransactionClient();

            RefundTransactionRequest refundTransactionRequest =
                new RefundTransactionRequest(RequestMode.Synchronous,
                                             transaction.TransactionID.ToString(),
                                             username,
                                             password,
                                             transaction.TransactionID,
                                             RefundReason.Custom,
                                             "MP: Refunding our payments!",
                                             null);

            RefundTransactionResponse refundTransactionResponse = transactionClient.RefundTransaction(refundTransactionRequest, null);

            return(refundTransactionResponse.Status.Code == MessageStatusCode.Success);
        }
Example #14
0
        protected void SubmitRefundButton_Click(object sender, EventArgs e)
        {
            //GET THE REFUND AMOUNT
            string originalRefundAmount = string.Format("{0:F2}", _Payment.Amount);


            decimal refundAmount = AlwaysConvert.ToDecimal(RefundAmount.Text);

            // AC8-2854, AC8-3117: IF amount is not changed by merchant then
            // to avoid rounding issues, restore the original amount upto 4 decimal digits
            if (originalRefundAmount == RefundAmount.Text)
            {
                refundAmount = _Payment.Amount;
            }

            if (refundAmount > 0 && _Payment.PaymentStatus == PaymentStatus.Captured)
            {
                RefundTransactionRequest refundRequest = new RefundTransactionRequest(_Payment, Request.UserHostAddress);
                if (CreditCardFields.Visible)
                {
                    SetRequestForCreditCard(refundRequest);
                }
                else if (CheckFields.Visible)
                {
                    SetRequestForCheck(refundRequest);
                }
                refundRequest.Amount = refundAmount;
                PaymentEngine.DoRefund(refundRequest);
                //_Payment.Refund(refundRequest);
                if (!string.IsNullOrEmpty(CustomerNote.Text))
                {
                    OrderNote note = new OrderNote(_Order.Id, AbleContext.Current.UserId, DateTime.UtcNow, CustomerNote.Text, NoteType.Public);
                    note.Save();
                }
            }
            Response.Redirect("Default.aspx?OrderNumber=" + _Order.OrderNumber.ToString());
        }
Example #15
0
 private void SetRequestForCheck(RefundTransactionRequest refundRequest)
 {
     if (HasValue(_AccountData, "BankName"))
     {
         refundRequest.ExtendedProperties["BankName"] = _AccountData["BankName"];
     }
     else
     {
         refundRequest.ExtendedProperties["BankName"] = CheckBankName.Text;
     }
     if (HasValue(_AccountData, "RoutingNumber"))
     {
         refundRequest.ExtendedProperties["RoutingNumber"] = _AccountData["RoutingNumber"];
     }
     else
     {
         refundRequest.ExtendedProperties["RoutingNumber"] = CheckRoutingNumber.Text;
     }
     if (HasValue(_AccountData, "AccountHolder"))
     {
         refundRequest.ExtendedProperties["AccountHolder"] = _AccountData["AccountHolder"];
     }
     else
     {
         refundRequest.ExtendedProperties["AccountHolder"] = CheckAccountHolderName.Text;
     }
     if (HasValue(_AccountData, "AccountNumber"))
     {
         refundRequest.ExtendedProperties["AccountNumber"] = _AccountData["AccountNumber"];
     }
     else
     {
         refundRequest.ExtendedProperties["AccountNumber"] = CheckAccountNumber.Text;
     }
     refundRequest.ExtendedProperties["AccountType"] = CheckAccountType.SelectedValue;
 }
Example #16
0
 public ApiResponse <Transaction> RefundTransaction(RefundTransactionRequest request)
 {
     return(SendApiRequest <RefundTransactionRequest, Transaction>(request));
 }
Example #17
0
 /// <summary>
 /// Not Supported.
 /// </summary>
 /// <param name="creditRequest"></param>
 /// <returns></returns>
 public override Transaction DoRefund(RefundTransactionRequest creditRequest)
 {
     throw new NotSupportedException("Operation Not Supported.");
 }
Example #18
0
 public override Transaction DoRefund(RefundTransactionRequest creditRequest)
 {
     return(AC.AcNotifier.RefundOrder(this, creditRequest));
 }
Example #19
0
        private string InitializeRefundRequest(Payment payment, RefundTransactionRequest refundRequest, Transaction authorizeTransaction, LSDecimal dAmount, Dictionary <string, string> sensitiveData)
        {
            Order order = payment.Order;
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = refundRequest.CardNumber;
            string expirationMonth = refundRequest.ExpirationMonth.ToString();
            string expirationYear  = refundRequest.ExpirationYear.ToString();

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", dAmount);
            string securityCode = accountData.GetValue("SecurityCode");

            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }

            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }
            data += Encode("dc_transaction_type", "CREDIT");
            data += Encode("dc_version", "1.2");
            data += Encode("dc_transaction_id", authorizeTransaction.ProviderTransactionId);
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);
            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            return(data);
        }
Example #20
0
 /// <summary>
 /// Submits a refund request for a previously captured transaction
 /// </summary>
 /// <param name="creditRequest">The refund request</param>
 /// <returns>Transaction that represents the result of the refund request</returns>
 public abstract Transaction DoRefund(RefundTransactionRequest creditRequest);
Example #21
0
        /// <summary>
        /// Refunds this payment
        /// </summary>
        /// <param name="remoteIp">Remote IP of the user initiating the request</param>
        public virtual void Refund(string remoteIp)
        {
            RefundTransactionRequest request = new RefundTransactionRequest(this, remoteIp);

            PaymentEngine.DoRefund(request);
        }
Example #22
0
 public async Task <RefundTransactionResponse> RefundTransaction(RefundTransactionRequest refundTransactionRequest)
 {
     return(await this.PostAsync <RefundTransactionResponse, RefundTransactionRequest>(refundTransactionRequest));
 }