//public bool ExecuteMonthlyPayout(int year, int month, List<BasePayoutSelectionToken> include, out int execId, out string error) //{ // error = string.Empty; // execId = -1; // try // { // var today = DateTime.Now; // var firstCurrent = new DateTime(today.Year, today.Month, 1); // var firstReport = new DateTime(year, month, 1); // if (firstCurrent.Date <= firstReport.Date) // { // error = "payout for future period not allowed"; // return false; // } // using (var context = new lfeAuthorEntities()) // { // //create data // context.sp_PO_SaveMonthlyPayoutStatment(year, month, LFE_COMMISSION_PERCENT, CurrentUserId); // var token = GetPayoutExecutionDto(year, month); // if (token.ExecutionId < 0) // { // error = "Data saving failed. Contact development team"; // return false; // } // execId = token.ExecutionId; // if (include.Count > 0) // { // var statments = UserPayoutStatmentsRepository.GetMany(x => x.ExecutionId == token.ExecutionId && x.StatusId == (byte)BillingEnums.ePayoutStatuses.WAIT).ToList(); // foreach (var statement in statments.Where(statement => !include.Any(x => x.userId == statement.UserId && x.currId == statement.CurrencyId))) // { // UpdateUserPayoutRecord(statement.PayoutId, BillingEnums.ePayoutStatuses.SKIP, "skipped by admin"); // } // } // var list2Pay = GetPayoutStatments(token.ExecutionId).Where(x=>x.Status == BillingEnums.ePayoutStatuses.WAIT).ToArray(); // foreach (var po_token in list2Pay) // { // ExecuteSinglePayment(po_token, out error); // } // var payouts = UserPayoutStatmentsRepository.GetMany(x=>x.ExecutionId == token.ExecutionId).ToArray(); // var successCount = payouts.Count(x => x.StatusId == (byte) BillingEnums.ePayoutStatuses.COMPLETED); // if (successCount.Equals(0)) // { // UpdatePayoutExecutionRecord(token.ExecutionId,BillingEnums.ePayoutStatuses.FAILED); // return true; // } // if(successCount < payouts.Count()) // { // UpdatePayoutExecutionRecord(token.ExecutionId, BillingEnums.ePayoutStatuses.PARTIALLY); // return true; // } // UpdatePayoutExecutionRecord(token.ExecutionId, BillingEnums.ePayoutStatuses.COMPLETED); // return true; // } // } // catch (Exception ex) // { // error = FormatError(ex); // Logger.Error("ExecuteMonthlyPayout::"+year+"::"+month, ex, CommonEnums.LoggerObjectTypes.Payout); // return false; // } //} public bool ExecuteSinglePayment(PayoutStatmentDTO token, out string error) { if (token.PayoutType == null) { error = "Payout option not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(false); } if (token.PayoutType != BillingEnums.ePayoutTypes.PAYPAL) { error = "Payout Paypal option not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(false); } if (String.IsNullOrEmpty(token.PaypalEmail)) { error = "Paypal Email not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(false); } if (token.Amount <= 0) { error = "Amount should be grater as zero"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(false); } var payment = new PaypalPaymentExecutionToken { ReceiverEmail = token.PaypalEmail, Amount = token.Amount, InvoiceId = token.PayoutId.ToString(), Currency = new BaseCurrencyDTO { ISO = token.Currency.ISO } }; string payKey; var result = _paypalPaymentServices.ExecutePayment(payment, out payKey, out error); UpdateUserPayoutRecord(token.PayoutId, result ? BillingEnums.ePayoutStatuses.COMPLETED : BillingEnums.ePayoutStatuses.FAILED, result ? string.Empty : error, payKey); return(result); }
private MassPayRequestItemType CreateMassPayRequestItem(PayoutStatmentDTO token, string note, out string error) { error = string.Empty; if (token.PayoutType == null) { error = "Payout option not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(null); } if (token.PayoutType != BillingEnums.ePayoutTypes.PAYPAL) { error = "Payout Paypal option not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(null); } if (String.IsNullOrEmpty(token.PaypalEmail)) { error = "Paypal Email not defined for user"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(null); } if (token.Amount <= 0) { error = "Amount should be grater as zero"; UpdateUserPayoutRecord(token.PayoutId, BillingEnums.ePayoutStatuses.FAILED, error); return(null); } var item = new MassPayRequestItemType { ReceiverEmail = token.PaypalEmail , UniqueId = token.PayoutId.ToString() , Note = note , Amount = new BasicAmountType { value = token.Amount.FormatMoney(2).ToString() , currencyID = token.Currency.Currency2PaypalCurrencyCode() } }; return(item); }