Ejemplo n.º 1
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);
    }