/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Started...'); Subscription::chunk(200, function ($subscriptions) { $accepted = 0; $declined = 0; $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2'); foreach ($subscriptions as $subscription) { $expiration = Carbon::createFromTimeStamp(strtotime($subscription->expires_at)); if ($expiration->isToday() || $expiration->isPast()) { $sale = $subscription->payment()->orderBy('id', 'desc')->where('is_success', '=', 1)->orWhere('is_success', '=', 2)->first(); if ($sale->is_success == 2) { $resale_params = array('id_authorization' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'); $status = $client->resaleByAuthorization($resale_params); } else { if ($sale->is_success == 1) { $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'); $status = $client->resaleBySale($params); } } if ($client->isSuccess()) { $accepted++; $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale'])); $subscription->expires_at = Carbon::now()->addDays(30); $subscription->is_active = 1; $subscription->save(); $user = User::find($subscription->user_id); $user->level = 2; $user->save(); $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get(); if ($configs->count() > 0) { foreach ($configs as $config) { $config->is_active = 1; $config->save(); } } EmailNotification::where('subscription_id', '=', $subscription->id)->delete(); $faktura = $subscription->company_id == 0 ? false : true; Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura)); } else { $declined++; $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0, 'sale_id' => $status['error']['error_number'])); Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at)); } } } $this->info('Accepted:' . $accepted); $this->info('Declined:' . $declined); }); $this->info('Done'); }
if ($configs->count() > 0) { foreach ($configs as $config) { $config->is_active = 1; $config->save(); } } EmailNotification::where('subscription_id', '=', $subscription->id)->delete(); $faktura = $subscription->company_id == 0 ? false : true; Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura)); } } } }); Event::listen('subscriptions.check', function () { Subscription::chunk(200, function ($subscriptions) { $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2'); foreach ($subscriptions as $subscription) { $expiration = Carbon::createFromTimeStamp(strtotime($subscription->expires_at)); if ($expiration->isToday() || $expiration->isPast()) { $sale = $subscription->payment()->orderBy('id', 'desc')->where('is_success', '=', 1)->orWhere('is_success', '=', 2)->first(); if ($sale->is_success == 2) { $resale_params = array('id_authorization' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'); $status = $client->resaleByAuthorization($resale_params); } else { if ($sale->is_success == 1) { $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'); $status = $client->resaleBySale($params); } } if ($client->isSuccess()) { $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
public function postPayment() { if (Auth::check()) { $rules = array('paylane_token' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'address' => 'required', 'zip' => 'required', 'city' => 'required', 'state' => 'required', 'company_name' => 'required_with:faktura', 'company_id' => 'required_with:faktura', 'company_address' => 'required_with:faktura', 'company_zip' => 'required_with:faktura', 'company_city' => 'required_with:faktura', 'company_state' => 'required_with:faktura'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('/konto/pro/platnosci')->withInput(Input::flash())->withErrors($validator)->with('alert', array('type' => 'error', 'content' => 'Błąd! Sprawdź wszystkie pola.')); } else { $user = Auth::user(); $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2'); $card_params = array('sale' => array('amount' => 189.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'), 'customer' => array('name' => Input::get('first_name') . ' ' . Input::get('last_name'), 'email' => Input::get('email'), 'ip' => '127.0.0.1', 'address' => array('street_house' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'country_code' => 'PL')), 'card' => array('token' => Input::get('paylane_token'))); $status = $client->cardSaleByToken($card_params); if ($client->isSuccess()) { $subscription = Subscription::where('user_id', '=', $user->id); $faktura = false; if ($subscription->count() > 0) { $subscription = $subscription->first(); $subscription->user_id = $user->id; $subscription->is_active = 1; $subscription->first_name = Input::get('first_name'); $subscription->last_name = Input::get('last_name'); $subscription->email = Input::get('email'); $subscription->address = Input::get('address'); $subscription->zip = Input::get('zip'); $subscription->city = Input::get('city'); $subscription->state = Input::get('state'); $subscription->expires_at = Carbon::now()->addDays(30); if (Input::has('faktura')) { $faktura = true; $subscription->is_active = 1; $subscription->company_name = Input::get('company_name'); $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id')); $subscription->company_address = Input::get('company_address'); $subscription->company_city = Input::get('company_city'); $subscription->company_state = Input::get('company_state'); $subscription->company_zip = Input::get('company_zip'); } $subscription->save(); } else { $subscription = new Subscription(); $subscription->user_id = $user->id; $subscription->first_name = Input::get('first_name'); $subscription->last_name = Input::get('last_name'); $subscription->email = Input::get('email'); $subscription->address = Input::get('address'); $subscription->zip = Input::get('zip'); $subscription->city = Input::get('city'); $subscription->state = Input::get('state'); $subscription->expires_at = Carbon::now()->addDays(30); if (Input::has('faktura')) { $faktura = true; $subscription->company_name = Input::get('company_name'); $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id')); $subscription->company_address = Input::get('company_address'); $subscription->company_city = Input::get('company_city'); $subscription->company_state = Input::get('company_state'); $subscription->company_zip = Input::get('company_zip'); } $subscription->save(); } $payment = Payment::create(array('user_id' => $user->id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale'], 'is_success' => 1)); Event::fire('invoice.email', array($user->id, $subscription->id, $payment->id, $faktura)); EmailNotification::where('subscription_id', '=', $subscription->id)->delete(); //here $user->level = 2; $user->save(); return Redirect::to('/konto/pro/subskrypcja')->with('alert', array('type' => 'success', 'content' => 'Dziękujemy! Płatność zaakceptowana.')); } else { if (isset($status['error'])) { return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['error_description'])); return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['description'])); } else { return Redirect::back()->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak!')); } } } } }