/// <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)); }
/// <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); } }