コード例 #1
0
    /// <summary>
    /// FROM AP
    /// </summary>
    public static void MarkAsPaid(PayoutRequest request)
    {
        request.IsPaid = true;
        request.Save();

        //Add payment proof
        Member User = new Member(request.Username);

        PaymentProof.Add(User, request);

        //Add history
        History.AddCashout(request.Username, request.Amount);
    }
コード例 #2
0
    public string TryMakePayout()
    {
        ValidatePayout();

        string paymentAddress = PaymentAccountDetails.GetPaymentProcessorUserAccount(user, paymentProcessor);

        var         request     = new TransactionRequest(user.Name, paymentAddress, amountToPayout);
        Transaction transaction = TransactionFactory.CreateTransaction(request, paymentProcessor);
        var         response    = transaction.Commit();

        if (!response.IsSuccess)
        {
            if (request != null && response != null)
            {
                PayoutManager.logPayout("Commission Balance Payout unsuccessful", request, response, paymentProcessor);
            }
            throw new MsgException(response.Note);
        }

        PayoutRequest req = new PayoutRequest();

        req.Amount           = amountToPayout;
        req.IsPaid           = true;
        req.RequestDate      = DateTime.Now;
        req.Username         = user.Name;
        req.IsRequest        = false;
        req.BalanceType      = BalanceType.CommissionBalance;
        req.PaymentAddress   = paymentAddress;
        req.PaymentProcessor = paymentProcessor;
        req.Save();

        user.SubtractFromCommissionBalance(amountToPayout, "Payout");
        user.SaveBalances();

        History.AddCashout(user.Name, amountToPayout);
        PayoutManager.logPayout("Commission Balance Payout successful", request, response, paymentProcessor);
        PaymentProof.Add(user, req);

        return(U3501.AUTOMATICCASHOUTSUCC + ": " + response.Note);
    }
コード例 #3
0
    /// <summary>
    /// FROM AP
    /// </summary>
    /// <param name="request"></param>
    /// <param name="gateway"></param>
    /// <param name="transaction"></param>
    /// <returns></returns>
    public static bool MakePayout(PayoutRequest request, PaymentAccountDetails gateway, ref Transaction transaction)
    {
        transaction.Commit();
        if (transaction.Response.IsSuccess)
        {
            request.IsPaid    = true;
            request.IsRequest = false;
            request.Save();

            Member User = new Member(request.Username);

            //Add payment proof
            PaymentProof.Add(User, request);

            //Add statistics
            var stats = new Statistics(StatisticsType.Cashflow);
            stats.AddToData2(request.Amount);
            stats.Save();

            //Add history
            History.AddCashout(request.Username, request.Amount);


            if (gateway is PayPalAccountDetails)
            {
                // Log because payment may have response status SuccessWithWarning
                // More on this: https://developer.paypal.com/webapps/developer/docs/classic/api/NVPAPIOverview/
                logPayout("Payout successful", request, transaction.Response, request.PaymentProcessor);
            }

            return(true);
        }
        else
        {
            logPayout("Payout unsuccessful", request, transaction.Response, request.PaymentProcessor);
            return(false);
        }
    }
コード例 #4
0
    /// <summary>
    /// FROM AP
    /// </summary>
    /// <param name="request"></param>
    public static void RejectRequest(PayoutRequest request)
    {
        Member User = new Member(request.Username);

        try
        {
            PaymentProcessor processor = PaymentAccountDetails.GetFromStringType(request.PaymentProcessor);
            PaymentProportionsManager.UndoMemberPaidOut(request.Amount, processor, User);
        }
        catch
        {
            //processor = custom processor
        }

        request.IsPaid           = true;
        request.PaymentProcessor = "REJECTED";
        request.Save();

        User.MoneyCashout -= request.Amount;
        User.AddToMainBalance(request.Amount, "Payout rejected");
        User.Save();

        History.AddCashoutRejection(User.Name, request.Amount.ToString());
    }
コード例 #5
0
    private string TryMakeManualPayout(Money fee)
    {
        //Manual, add to payoutrequests
        PayoutRequest req = new PayoutRequest();

        //Calculate fees for CustomPP
        Money Fees = fee;

        if (IsCustomPayoutProcessor)
        {
            CustomPayoutProcessor CPP = new CustomPayoutProcessor(CustomPayoutProcessorId);
            Fees = Fees + CPP.MoneyFee;
            Fees = Fees + (AmountToPayout * (CPP.PercentageFee * new Money(0.01)));

            if (string.IsNullOrWhiteSpace(TargetAccount))
            {
                throw new MsgException(U4200.ACCOUNTFIELDNOTBLANK);
            }
        }

        req.Amount      = AmountToPayout - Fees;
        req.IsPaid      = false;
        req.RequestDate = DateTime.Now;
        req.Username    = User.Name;
        req.IsRequest   = true;
        req.BalanceType = BalanceType.MainBalance;

        if (IsCustomPayoutProcessor)
        {
            //CustomPP
            CustomPayoutProcessor CPP = new CustomPayoutProcessor(CustomPayoutProcessorId);
            req.PaymentAddress   = TargetAccount;
            req.PaymentProcessor = CPP.Name;

            //MPesa check
            if (CPP.Name.ToLower() == "mpesa" && (TargetAccount.Length != 10 || !TargetAccount.StartsWith("07")))
            {
                throw new MsgException("Check your phone number format. The number should be 07******** (10 length)");
            }
        }
        else
        {
            string paymentAddress = PaymentAccountDetails.GetPaymentProcessorUserAccount(User, TargetPaymentProcessor);

            if (String.IsNullOrEmpty(paymentAddress))
            {
                throw new MsgException(U5004.YOUMUST);
            }

            if (TargetPaymentProcessor == "Payeer" && paymentAddress.Contains("@"))
            {
                throw new MsgException(U6006.VALIDPAYEER);
            }

            req.PaymentAddress   = paymentAddress;
            req.PaymentProcessor = TargetPaymentProcessor;
        }

        req.Save();

        User.SubtractFromMainBalance(AmountToPayout, "Payout");
        User.MoneyCashout += (AmountToPayout - Fees);
        User.IsPhoneVerifiedBeforeCashout = false;
        User.CashoutsProceed++;
        User.Save();

        //Update payout proportions
        if (!IsCustomPayoutProcessor)
        {
            PaymentProportionsManager.MemberPaidOut(AmountToPayout - Fees, PaymentAccountDetails.GetFromStringType(TargetPaymentProcessor), User, IsCustomPayoutProcessor);
        }

        if (IsAutomaticButAvoveTheLimit)
        {
            return(U3501.CASHOUTSUCC + ": " + U3500.CASHOUT_APPROVE.Replace("%n%", TheLimit.ToString()));
        }
        else
        {
            return(U3501.CASHOUTSUCC + ": " + U3500.CASHOUT_MESSAGE.Replace("%n1%", (AmountToPayout - Fees).ToString()).Replace("%n2%", Fees.ToString()));
        }
    }
コード例 #6
0
    private string TryMakeInstantPayout(Money fee)
    {
        // payoutRequest --> change property to false (it isn't request)
        PayoutRequest req = new PayoutRequest();

        req.Amount      = AmountToPayout - fee;
        req.IsPaid      = true;
        req.RequestDate = DateTime.Now;
        req.Username    = User.Name;
        req.IsRequest   = false;
        req.BalanceType = BalanceType.MainBalance;

        //Check if daily limit is not reached
        if (AppSettings.Payments.GlobalCashoutsToday + AmountToPayout - fee > AppSettings.Payments.GlobalCashoutLimitPerDay)
        {
            throw new MsgException(L1.TOOMANYCASHOUTS + " " + AppSettings.Payments.GlobalCashoutLimitPerDay.ToString());
        }

        //User payment address
        string paymentAddress = PaymentAccountDetails.GetPaymentProcessorUserAccount(User, TargetPaymentProcessor);

        if (String.IsNullOrEmpty(paymentAddress))
        {
            throw new MsgException(U5004.YOUMUST);
        }

        request = new TransactionRequest(User.Name, paymentAddress, AmountToPayout - fee);
        Transaction transaction = TransactionFactory.CreateTransaction(request, TargetPaymentProcessor);

        response = transaction.Commit();

        req.PaymentAddress   = paymentAddress;
        req.PaymentProcessor = TargetPaymentProcessor;

        if (!response.IsSuccess)
        {
            if (request != null && response != null)
            {
                PayoutManager.logPayout("Payout unsuccessful", request, response, req.PaymentProcessor);
            }
            throw new MsgException(response.Note);
        }

        req.Save();

        History.AddCashout(User.Name, AmountToPayout);

        User.SubtractFromMainBalance(AmountToPayout, "Payout");
        User.MoneyCashout += AmountToPayout - fee;
        User.IsPhoneVerifiedBeforeCashout = false;
        User.CashoutsProceed++;
        User.Save();

        //Update payout proportions
        PaymentProportionsManager.MemberPaidOut(AmountToPayout - fee, PaymentAccountDetails.GetFromStringType(TargetPaymentProcessor), User, IsCustomPayoutProcessor);

        //Add to daily cashout
        AppSettings.Payments.GlobalCashoutsToday += AmountToPayout - fee;
        AppSettings.Payments.Save();

        //Add outcome to stats (Data2);
        var stats = new Statistics(StatisticsType.Cashflow);

        stats.AddToData2(AmountToPayout);
        stats.Save();

        //Add paymentproof
        PaymentProof.Add(User.Id, AmountToPayout, PaymentType.Instant, PaymentAccountDetails.GetFromStringType(TargetPaymentProcessor));

        // Log because payment may have response status SuccessWithWarning
        // More on this: https://developer.paypal.com/webapps/developer/docs/classic/api/NVPAPIOverview/
        logPayout("Payout successful", request, response, req.PaymentProcessor);

        return(U3501.AUTOMATICCASHOUTSUCC + ": " + response.Note);
    }
コード例 #7
0
    public bool TryMakeInvestmentLevelsPayout()
    {
        // payoutRequest --> change property to false (it isn't request)
        var req = new PayoutRequest
        {
            Amount      = AmountToPayout,
            IsPaid      = true,
            RequestDate = DateTime.Now,
            Username    = User.Name,
            IsRequest   = false,
            BalanceType = BalanceType.InvestmentLevels
        };

        //User payment address
        string paymentAddress = PaymentAccountDetails.GetPaymentProcessorUserAccount(User, TargetPaymentProcessor);

        if (String.IsNullOrEmpty(paymentAddress))
        {
            throw new MsgException(U5004.YOUMUST);
        }

        request = new TransactionRequest(User.Name, paymentAddress, AmountToPayout);
        Transaction transaction = TransactionFactory.CreateTransaction(request, TargetPaymentProcessor);

        response = transaction.Commit();

        req.PaymentAddress   = paymentAddress;
        req.PaymentProcessor = TargetPaymentProcessor;

        if (!response.IsSuccess)
        {
            if (request != null && response != null)
            {
                logPayout("Payout unsuccessful", request, response, req.PaymentProcessor);
            }
            return(false);
        }
        req.Save();

        History.AddInvestmentLevelCashout(User.Name, AmountToPayout);

        //Add to daily cashout
        AppSettings.Payments.GlobalCashoutsToday += AmountToPayout;
        AppSettings.Payments.Save();

        //Add outcome to stats (Data2);
        var stats = new Statistics(StatisticsType.Cashflow);

        stats.AddToData2(AmountToPayout);
        stats.Save();

        //Add paymentproof
        PaymentProof.Add(User.Id, AmountToPayout, PaymentType.Instant, PaymentAccountDetails.GetFromStringType(TargetPaymentProcessor));

        // Log because payment may have response status SuccessWithWarning
        // More on this: https://developer.paypal.com/webapps/developer/docs/classic/api/NVPAPIOverview/
        logPayout("Payout successful", request, response, req.PaymentProcessor);

        ErrorLogger.Log(string.Format("{0}: {1}", U3501.AUTOMATICCASHOUTSUCC, response.Note));
        return(true);
    }