예제 #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);
        }
예제 #2
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);
            }
        }
예제 #3
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);
        }