/** * Save payment in database * * @param $user_id * @param $amount * @return integer id */ public function saveCharge($user_id, $amount) { $payment = new Payments(); $payment->user_id = $user_id; $payment->amount = $amount; $payment->method = 'STRIPE'; $payment->save(); return $payment->id; }
public static function addPayments($input, $id) { $data = new Payments(); $data->idexpense = $id; $data->name = $input['name']; $data->date = time(); $data->type = $input['type']; $data->price = $input['price']; $data->save(); }
/** * Updates an existing Suspense model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->status == 'yes') { try { //FIND CUSTOMER RECORDS $customer = Clients::findOne(['clientAcc' => $model->mpesa_acc]); //HOW MUCH MONEY CLIENTS SHOULD PAY A MONTH $billing = Bills::findOne(['id' => 1]); //IF NO CLIENT FOUND, SUBMIT THIS TO SUSPENSE ACCOUNT if (count($customer) >= 1) { // IF A CLIENT IS FOUND, THEN DO THE FOLLOWING AND SAVE $payment = new Payments(); $payment->mpesa_id = $model->mpesa_id; $payment->original = $model->original; $payment->destination = $model->destination; $payment->customer_id = $model->customer_id; $payment->test = $model->test; $payment->mpesa_code = $model->mpesa_code; $payment->mpesa_acc = $model->mpesa_acc; $payment->mpesa_msidn = $model->mpesa_msidn; $payment->mpesa_amount = $model->mpesa_amount; $payment->mpesa_sender = $model->mpesa_sender; $payment->timestamp = $model->timestamp; $payment->save(); echo "<pre>"; //print_r($payment); echo "</pre>"; //IS THE CLIENT ACTIVE OR INACTIVE? BASED ON THE PROFILE $customer_radgroup = Radusergroup::findOne(['username' => $customer->username]); //print_r($customer_radgroup); //COLLECT ALL RADGROUPS $radgroups = Radgroupcheck::find()->all(); if ($payment->mpesa_amount >= $billing->monthly_charge) { //IF USER WAS DISCONNECTED, AND HAS PAID MORE THAN THE BILLING AMOUNT, SAY: 3000, THEN ACTIVATE THAT USER if (count($customer_radgroup) >= 1) { if ($customer_radgroup->groupname == "daloRADIUS-Disabled-Users") { try { //Yii::$app->db->createCommand()->delete('radusergroup', ['username' => $customer->username])->execute(); if ($customer_radgroup->delete()) { echo "Deleted"; } } catch (Exception $e) { } } } if ($customer->arrears < 0 && $customer->balances >= $billing->monthly_charge) { $customer->arrears += $payment->mpesa_amount; if ($customer->arrears > 0) { $customer->balances += $customer->arrears; } } elseif ($customer->arrears < 0 && $customer->balances < $billing->monthly_charge) { $difference = $billing->monthly_charge - $customer->balances; $topup = $billing->monthly_charge - $customer->balances; //$customer->balances = 2500; //$billing->monthly_charge = 3000; //$difference = 1000; //$payment->mpesa_amount = 2000 if ($payment->mpesa_amount > $topup) { $remainder = $payment->mpesa_amount - $topup; $customer->balances += $billing->monthly_charge; $customer->arrears += $remainder; if ($customer->arrears > 0) { $customer->balances += $customer->arrears; } } else { $customer->balances += $payment->mpesa_amount; } } else { $customer->balances += $payment->mpesa_amount; } } else { if ($customer->balances >= $billing->monthly_charge && $customer->arrears < 0) { //$customer->balances = 2000; //$billing->monthly_charge = 3000; //$difference = 1000; //$payment->mpesa_amount = 2000 $customer->arrears += $payment->mpesa_amount; if ($customer->arrears > 0) { $customer->balances += $customer->arrears; } } elseif ($customer->balances <= $billing->monthly_charge && $customer->arrears < 0) { if ($payment->mpesa_amount + $customer->balances > $billing->monthly_charge) { $topup = $billing->monthly_charge - $customer->balances; $customer->balances += $topup; // $excess = $payment->mpesa_amount - $topup; $customer->arrears += $excess; } else { $customer->balances += $payment->mpesa_amount; } } if ($customer->balances >= $billing->monthly_charge && count($customer_radgroup) >= 1) { if ($customer_radgroup->groupname == "daloRADIUS-Disabled-Users") { try { //Yii::$app->db->createCommand()->delete('radusergroup', ['username' => $customer->username])->execute(); if ($customer_radgroup->delete()) { echo "Deleted"; } } catch (Exception $e) { } } } } try { $customer->balances = (string) $customer->balances; $customer->arrears = (string) $customer->arrears; $customer->save(); } catch (Exception $e) { } } //return $this->render('collection', ["status"=>"Records saved"] ); } catch (Exception $e) { //return $this->render('collection', ["status"=>"Client Account details not found!"] ); } if ($model->save()) { //return $this->redirect(['view', 'id' => $model->id]); return $this->render('update', ['model' => $model, 'result' => $payment]); } } elseif ($model->load(Yii::$app->request->post()) && $model->save() && $model->status == 'no') { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
/** * Creates a new Payments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Payments(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }