Esempio n. 1
0
 protected function chargeCustomer()
 {
     if ($this->isPostBack() && !$this->input('mark_payed')) {
         $this->post->amount->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputFloat()]);
         if (!$this->hasErrors()) {
             $amount = (double) $this->input('amount') * 100;
             try {
                 Stripe::setApiKey(env('STRIPE_KEY'));
                 $stripe = Charge::create(['customer' => $this->organisation->stripe_identifier_id, 'amount' => $amount, 'currency' => $this->settings->getCurrency(), 'description' => 'NinjaImg ' . date('m-Y', strtotime($this->startDate)) . '-' . date('m-Y', strtotime($this->endDate))]);
                 if (!isset($stripe->paid) || !$stripe->paid) {
                     $this->setError('Failed to charge credit-card');
                 }
                 if (!$this->hasErrors()) {
                     $payment = new ModelPayment();
                     $payment->amount = $amount;
                     $payment->currency = $this->settings->getCurrency();
                     $payment->period_start = $this->startDate;
                     $payment->period_end = $this->endDate;
                     $payment->transaction_id = $stripe->id;
                     $payment->organisation_id = $this->organisation->id;
                     $payment->save();
                 }
             } catch (\Exception $e) {
                 $this->setError($e->getMessage());
             }
             if (!$this->hasErrors()) {
                 $this->organisation->getPayment($this->startDate, $this->endDate)->updateFreeCredits();
                 $this->setMessage('Successfully charged ' . $this->input('amount') . ' ' . $this->settings->getCurrency(), 'success');
             }
             response()->refresh();
         }
     }
 }
Esempio n. 2
0
 public function __construct()
 {
     parent::__construct();
     $this->settings = ModelSettings::getInstance();
     $this->startDate = $this->input('start_date', date('01-m-Y', strtotime('-1 month')));
     $this->endDate = $this->input('end_date', date('t-m-Y', strtotime('-1 month')));
     $this->payments = ModelPayment::getByPeriod($this->startDate, $this->endDate);
 }
Esempio n. 3
0
function shutdownAccount(\NinjaImg\Model\ModelOrganisation $organisation, $amount)
{
    $lastMonthDate = date('Y-m-01', strtotime('-1 month'));
    $currency = \NinjaImg\Model\ModelSettings::getInstance()->getCurrency();
    $lastPaymentDate = \NinjaImg\Model\ModelPayment::getLastPaymentDate($organisation->id, $lastMonthDate);
    if (!$lastPaymentDate) {
        $lastPaymentDate = \Pecee\Date::toDateTime();
        savePayment($organisation->id, $amount, $lastMonthDate);
    }
    $lastTryDaysAgo = daysAgo($lastPaymentDate, \Pecee\Date::toDateTime());
    if ($lastTryDaysAgo > MAX_PAYMENT_ATTEMPTS_DAYS) {
        echo sprintf('disabled due to no payment in %s days', MAX_PAYMENT_ATTEMPTS_DAYS);
        mailAdmins('[WARNING] ' . $organisation->name . ' shut down warning', sprintf("Hi bitches!\n\nThe organisation {$organisation->name} has been shut down due to invalid and/or no payment in over %s days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // TODO: Send notification to user about shutting down
        $organisation->disabled = true;
        $organisation->update();
    } else {
        $shutdownDays = MAX_PAYMENT_ATTEMPTS_DAYS - $lastTryDaysAgo;
        echo sprintf('%s days before shutting down account', $shutdownDays);
        mailAdmins('[INFO] ' . $organisation->name . ' payment not received', sprintf("Hi bitches!\n\nFailed to charge {$organisation->name} and will be automatically disabled in {$shutdownDays} days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // Register try
    }
}
Esempio n. 4
0
 protected function hasPayed(ModelOrganisation $organisation)
 {
     return ModelPayment::getByOrganisationPeriod($organisation->id, $this->startDate, $this->endDate)->hasRow();
 }