Пример #1
0
        /// <summary>
        /// Refunds a payment
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var result    = new RefundPaymentResult();
            var bpManager = new BluePayManager
            {
                AccountId = _bluePayPaymentSettings.AccountId,
                UserId    = _bluePayPaymentSettings.UserId,
                SecretKey = _bluePayPaymentSettings.SecretKey,
                IsSandbox = _bluePayPaymentSettings.UseSandbox,
                MasterId  = refundPaymentRequest.Order.CaptureTransactionId,
                Amount    = refundPaymentRequest.IsPartialRefund ?
                            GetUsdAmount(refundPaymentRequest.AmountToRefund).ToString("F", new CultureInfo("en-US")) : null
            };

            bpManager.Refund();

            if (bpManager.IsSuccessful)
            {
                result.NewPaymentStatus = (refundPaymentRequest.IsPartialRefund &&
                                           refundPaymentRequest.Order.RefundedAmount + refundPaymentRequest.AmountToRefund < refundPaymentRequest.Order.OrderTotal) ?
                                          PaymentStatus.PartiallyRefunded : PaymentStatus.Refunded;
            }
            else
            {
                result.AddError(bpManager.Message);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result    = new VoidPaymentResult();
            var bpManager = new BluePayManager
            {
                AccountId = _bluePayPaymentSettings.AccountId,
                UserId    = _bluePayPaymentSettings.UserId,
                SecretKey = _bluePayPaymentSettings.SecretKey,
                IsSandbox = _bluePayPaymentSettings.UseSandbox,
                MasterId  = !string.IsNullOrEmpty(voidPaymentRequest.Order.AuthorizationTransactionId) ?
                            voidPaymentRequest.Order.AuthorizationTransactionId : voidPaymentRequest.Order.CaptureTransactionId
            };

            bpManager.Void();

            if (bpManager.IsSuccessful)
            {
                result.NewPaymentStatus = PaymentStatus.Voided;
            }
            else
            {
                result.AddError(bpManager.Message);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result    = new CapturePaymentResult();
            var bpManager = new BluePayManager
            {
                AccountId = _bluePayPaymentSettings.AccountId,
                UserId    = _bluePayPaymentSettings.UserId,
                SecretKey = _bluePayPaymentSettings.SecretKey,
                IsSandbox = _bluePayPaymentSettings.UseSandbox,
                MasterId  = capturePaymentRequest.Order.AuthorizationTransactionId,
                Amount    = GetUsdAmount(capturePaymentRequest.Order.OrderTotal).ToString("F", new CultureInfo("en-US"))
            };

            bpManager.Capture();

            if (bpManager.IsSuccessful)
            {
                result.NewPaymentStatus         = PaymentStatus.Paid;
                result.CaptureTransactionId     = bpManager.TransactionId;
                result.CaptureTransactionResult = bpManager.Message;
            }
            else
            {
                result.AddError(bpManager.Message);
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Cancels a recurring payment
        /// </summary>
        /// <param name="cancelPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public CancelRecurringPaymentResult CancelRecurringPayment(CancelRecurringPaymentRequest cancelPaymentRequest)
        {
            var result    = new CancelRecurringPaymentResult();
            var bpManager = new BluePayManager
            {
                AccountId = _bluePayPaymentSettings.AccountId,
                UserId    = _bluePayPaymentSettings.UserId,
                SecretKey = _bluePayPaymentSettings.SecretKey,
                MasterId  = cancelPaymentRequest.Order.SubscriptionTransactionId
            };

            bpManager.CancelRecurring();

            if (!bpManager.IsSuccessfulCancelRecurring)
            {
                result.AddError(bpManager.Message);
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Process recurring payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);

            if (customer == null)
            {
                throw new Exception("Customer cannot be loaded");
            }

            var result    = new ProcessPaymentResult();
            var bpManager = new BluePayManager
            {
                AccountId  = _bluePayPaymentSettings.AccountId,
                UserId     = _bluePayPaymentSettings.UserId,
                SecretKey  = _bluePayPaymentSettings.SecretKey,
                IsSandbox  = _bluePayPaymentSettings.UseSandbox,
                CustomerIP = _webHelper.GetCurrentIpAddress(),
                CustomId1  = customer.Id.ToString(),
                CustomId2  = customer.CustomerGuid.ToString(),
                FirstName  = customer.BillingAddress.FirstName,
                LastName   = customer.BillingAddress.LastName,
                Email      = customer.BillingAddress.Email,
                Address1   = customer.BillingAddress.Address1,
                Address2   = customer.BillingAddress.Address2,
                City       = customer.BillingAddress.City,
                Country    = customer.BillingAddress.Country != null ? customer.BillingAddress.Country.ThreeLetterIsoCode : null,
                Zip        = customer.BillingAddress.ZipPostalCode,
                Phone      = customer.BillingAddress.PhoneNumber,
                State      = customer.BillingAddress.StateProvince != null ? customer.BillingAddress.StateProvince.Abbreviation : null,
                CardNumber = processPaymentRequest.CreditCardNumber,
                CardExpire = string.Format("{0:MMyy}",
                                           new DateTime(processPaymentRequest.CreditCardExpireYear, processPaymentRequest.CreditCardExpireMonth, 1)),
                CardCvv2        = processPaymentRequest.CreditCardCvv2,
                Amount          = GetUsdAmount(processPaymentRequest.OrderTotal).ToString("F", new CultureInfo("en-US")),
                OrderId         = processPaymentRequest.OrderGuid.ToString(),
                InvoiceId       = processPaymentRequest.OrderGuid.ToString(),
                DoRebill        = "1",
                RebillAmount    = GetUsdAmount(processPaymentRequest.OrderTotal).ToString("F", new CultureInfo("en-US")),
                RebillCycles    = processPaymentRequest.RecurringTotalCycles > 0 ? (processPaymentRequest.RecurringTotalCycles - 1).ToString() : null,
                RebillFirstDate = string.Format("{0} {1}", processPaymentRequest.RecurringCycleLength,
                                                processPaymentRequest.RecurringCyclePeriod.ToString().TrimEnd('s').ToUpperInvariant()),
                RebillExpression = string.Format("{0} {1}", processPaymentRequest.RecurringCycleLength,
                                                 processPaymentRequest.RecurringCyclePeriod.ToString().TrimEnd('s').ToUpperInvariant())
            };

            bpManager.SaleRecurring();

            if (bpManager.IsSuccessful)
            {
                result.NewPaymentStatus             = PaymentStatus.Paid;
                result.SubscriptionTransactionId    = bpManager.RebillId;
                result.AuthorizationTransactionCode = bpManager.AuthCode;
                result.AvsResult = bpManager.AVS;
                result.AuthorizationTransactionId = bpManager.TransactionId;
                result.CaptureTransactionId       = bpManager.TransactionId;
                result.CaptureTransactionResult   = bpManager.Message;
            }
            else
            {
                result.AddError(bpManager.Message);
            }

            return(result);
        }