Пример #1
0
        public void UpdatePayKey(vPayment payment, UserPaymentInfo senderPaymentInfo, UserPaymentInfo receiverPaymentInfo)
        {
            // check sender and receiver have payment information
            if (senderPaymentInfo == null)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PaymentInfoIsNotDefinedForUser_, ": " + payment.SenderFirstName + " " + payment.SenderLastName));
            }
            if (receiverPaymentInfo == null)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PaymentInfoIsNotDefinedForUser_, ": " + payment.ReceiverFirstName + " " + payment.ReceiverLastName));
            }

            // check sender has a valid email
            if (string.IsNullOrEmpty(senderPaymentInfo.UserPaymentInfoPayPalEmail) == true)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PayPalEmailAddressNotDefinedForUser_, ": " + payment.SenderFirstName + " " + payment.SenderLastName));
            }

            // check that receiver has a valid paypal email
            if (string.IsNullOrEmpty(receiverPaymentInfo.UserPaymentInfoPayPalEmail) == true)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PayPalEmailAddressNotDefinedForUser_, ": " + payment.ReceiverFirstName + " " + payment.ReceiverLastName));
            }

            // Check payment status is in Pending situation
            if (payment.PaymentStatusID != (int)EntityEnums.PaymentStatusEnum.NotStarted &&
                payment.PaymentStatusID != (int)EntityEnums.PaymentStatusEnum.PendingWithoutPayKey &&
                payment.PaymentStatusID != (int)EntityEnums.PaymentStatusEnum.PendingWithPayKey)
            {
                throw new BRException(BusinessErrorStrings.Payment.PaymentStatusIsNotPending);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets PayKey from PayPal and updates in the database
        /// </summary>
        /// <param name="paymentId">Payment indentifier</param>
        public Payment UpdatePayPalKey(long paymentId)
        {
            vPayment payment = (vPayment)GetByID(paymentId, new GetByIDParameters(GetSourceTypeEnum.View));

            IUserPaymentInfoService service =
                (IUserPaymentInfoService)EntityFactory.GetEntityServiceByName(vUserPaymentInfo.EntityName, "");

            UserPaymentInfo senderPaymentInfo   = (UserPaymentInfo)service.GetByID(payment.SenderUserID, new GetByIDParameters());
            UserPaymentInfo receiverPaymentInfo = (UserPaymentInfo)service.GetByID(payment.ReceiverUserID, new GetByIDParameters());

            // Checking the business rules first
            PaymentBR biz = (PaymentBR)this.BusinessLogicObject;

            biz.UpdatePayKey(payment, senderPaymentInfo, receiverPaymentInfo);

            VisitParallelPaymentParameters p = new VisitParallelPaymentParameters();

            p.paymentId       = paymentId;
            p.receiver1amount = payment.Amount - payment.ServiceChargeAmount;
            p.receiver2amount = payment.ServiceChargeAmount;
            p.receiver1email  = receiverPaymentInfo.UserPaymentInfoPayPalEmail;
            p.receiver2email  = FWUtils.ConfigUtils.GetAppSettings().Paypal.MainAccount;

            // DEVELOPER NOTE: PayPal Embedded Payment has a bug; it returns an error Payment can't be completed. This feature is currently unavailable.
            // In order to fix the bug, sender email should not be specified. In addition, not specifying sender email allows Guest Payment (without having a PayPal account)
            // Read more here: http://stackoverflow.com/questions/12666184/embedded-payments-and-this-function-is-temporarily-unavailable-error
            //p.senderEmail = senderPaymentInfo.UserPaymentInfoPayPalEmail;

            PayPalService payPal = new PayPalService();
            string        payKey = payPal.GetPayKey(p);

            // logging the details
            long?userId = null;

            if (FWUtils.SecurityUtils.IsUserAuthenticated())
            {
                userId = FWUtils.SecurityUtils.GetCurrentUserIDLong();
            }
            string logString = "" + p.senderEmail + "\t" + p.receiver1email + "\t" + p.receiver1amount + "\t" + p.receiver2amount;

            FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog()
            {
                AppLogTypeID = (short)EntityEnums.AppLogType.PayPal_UpdatePayKey, UserID = userId, ExtraBigInt = paymentId, ExtraString1 = payKey, ExtraString2 = logString
            });

            return(UpdatePaykeyInDatabase(payment.PaymentID, payKey));
        }
Пример #3
0
        /// <summary>
        /// Refunds the payment.
        /// </summary>
        /// <param name="payment">The payment.</param>
        /// <param name="receiverPaymentInfo">The receiver payment information.</param>
        /// <exception cref="BRException">
        /// </exception>
        public void RefundPayment(vPayment payment, UserPaymentInfo receiverPaymentInfo)
        {
            Check.Require(payment != null);

            if (payment.PaymentStatusID != (int)EntityEnums.PaymentStatusEnum.Done)
            {
                throw new BRException(BusinessErrorStrings.Payment.OnlyCompletedPaymentsCanBeRefunded);
            }

            // check sender and receiver have payment information
            if (receiverPaymentInfo == null)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PaymentInfoIsNotDefinedForUser_, " " + payment.ReceiverUserID + ": " + payment.ReceiverFirstName + " " + payment.ReceiverLastName));
            }

            // check that receiver has a valid paypal email
            if (string.IsNullOrEmpty(receiverPaymentInfo.UserPaymentInfoPayPalEmail) == true)
            {
                throw new BRException(string.Format(BusinessErrorStrings.Payment.PayPalEmailAddressNotDefinedForUser_, " " + payment.ReceiverUserID + ": " + payment.ReceiverFirstName + " " + payment.ReceiverLastName));
            }
        }
Пример #4
0
        /// <summary>
        /// Refunds the payment.
        /// </summary>
        /// <param name="paymentId">The payment identifier.</param>
        public void RefundPayment(long paymentId)
        {
            PaymentBR biz     = (PaymentBR)this.BusinessLogicObject;
            vPayment  payment = (vPayment)GetByID(paymentId, new GetByIDParameters(GetSourceTypeEnum.View));

            IUserPaymentInfoService paymentInfoService =
                (IUserPaymentInfoService)EntityFactory.GetEntityServiceByName(vUserPaymentInfo.EntityName, "");

            UserPaymentInfo receiverPaymentInfo = (UserPaymentInfo)paymentInfoService.GetByID(payment.ReceiverUserID, new GetByIDParameters());

            biz.RefundPayment(payment, receiverPaymentInfo);

            PayPalService paypalService   = new PayPalService();
            var           executionStatus = paypalService.GetPaymentExecutionStatus(payment.PayKey);

            if (executionStatus == PaypalApi.PaymentExecStatusSEnum.COMPLETED)
            {
                // logging the details
                long?userId = null;
                if (FWUtils.SecurityUtils.IsUserAuthenticated())
                {
                    userId = FWUtils.SecurityUtils.GetCurrentUserIDLong();
                }
                FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog()
                {
                    AppLogTypeID = (short)EntityEnums.AppLogType.PayPal_Refund, UserID = userId, ExtraBigInt = paymentId
                });

                RefundParameters p = new RefundParameters();
                p.payKey          = payment.PayKey;
                p.receiver1amount = payment.Amount - payment.ServiceChargeAmount;
                p.receiver2amount = payment.ServiceChargeAmount;
                p.receiver1email  = receiverPaymentInfo.UserPaymentInfoPayPalEmail;
                p.receiver2email  = FWUtils.ConfigUtils.GetAppSettings().Paypal.MainAccount;

                paypalService.RefundPayment(p);
                UpdateStatusPaymentInDatabase(paymentId, EntityEnums.PaymentStatusEnum.Refunded, true);
            }
        }