Ejemplo n.º 1
0
        /// <summary>
        /// Gets the latest information about the payment from its related website (i.e. PayPal)
        /// and updates data based on that
        /// </summary>
        /// <param name="paymentId">paymentId</param>
        public Payment SyncPaymentInfoFromPaymentWebsite(Payment payment)
        {
            //Payment payment = (Payment)GetByID(paymentId, new GetByIDParameters());
            PaymentBR biz = (PaymentBR)this.BusinessLogicObject;

            biz.UpdatePaymentInfoFromPaymentWebsite(payment);

            if (string.IsNullOrEmpty(payment.PayKey) == false)
            {
                PayPalService paypalService   = new PayPalService();
                var           executionStatus = paypalService.GetPaymentExecutionStatus(payment.PayKey);
                if (executionStatus == PaypalApi.PaymentExecStatusSEnum.COMPLETED)
                {
                    this.CompletePaymentInDatabase(payment);
                }
                else if (executionStatus == PaypalApi.PaymentExecStatusSEnum.EXPIRED ||
                         executionStatus == PaypalApi.PaymentExecStatusSEnum.ERROR ||
                         executionStatus == PaypalApi.PaymentExecStatusSEnum.REVERSALERROR ||
                         executionStatus == PaypalApi.PaymentExecStatusSEnum.INCOMPLETE)
                {
                    // if there was an error (like token expiration) just get a new key and try again
                    return(this.UpdatePayPalKey(payment.PaymentID));
                }
            }
            else
            {
                return(this.UpdatePayPalKey(payment.PaymentID));
            }

            return(payment);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the payment status if completed.
        /// </summary>
        /// <param name="paymentId">The payment identifier.</param>
        /// <returns>if it completed then the payment object</returns>
        public Payment CompletePayment(long paymentId)
        {
            Payment       payment         = (Payment)GetByID(paymentId, new GetByIDParameters());
            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_CompletePayment, UserID = userId, ExtraBigInt = paymentId
                });

                return(CompletePaymentInDatabase(payment));
            }
            throw new BRException(BusinessErrorStrings.Payment.PaymentIsNotCompletedInPayPal);
        }