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