Exemplo n.º 1
0
 public function getOpenTransactions()
 {
     $dbh = $this->getDatabaseHandler();
     $stmt = $dbh->prepare("SELECT * FROM transactions WHERE status='pending'");
     $stmt->execute();
     $transactions = array();
     foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $data) {
         $trans = new Transaction();
         $trans->exchangeArray($data);
         $transactions[] = $trans;
     }
     return $transactions;
 }
Exemplo n.º 2
0
 public function approveRegistration(Request $request, $customerId)
 {
     if (!isset($request->request['amount'])) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_REQUEST_PARAMETER);
     }
     $amount = $request->request['amount'];
     if (!filter_var($amount, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\d*(\$|\\.\\d\\d\$)/")))) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_AMOUNT);
     }
     $amount = floatval($amount);
     $customerRepository = $this->getCustomerRepository();
     $customer = $customerRepository->getCustomerById($customerId);
     if (is_null($customer)) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_CUSTOMER_ID);
     }
     if ($customer->status == 'pending') {
         $credentials = $customerRepository->getCustomerCredentials($customer);
         if (is_null($credentials['scs_pin'])) {
             $password = Helper::randomString(5);
             $message = "Dear {$customer->firstname} {$customer->lastname}," . PHP_EOL . "your Account was successfully approved!" . "You can now login and make transactions with your tan list" . $password . PHP_EOL . PHP_EOL . "Best Regards," . PHP_EOL . "SitzBank";
             $mail = Helper::getPhpMailer();
             $mail->addAddress($customer->email, $customer->firstname . ' ' . $customer->lastname);
             $mail->Subject = "Account approved!";
             $mail->Body = $message;
             if (!$mail->send()) {
                 return JsonErrorResponse::fromKey(JsonErrorResponse::MAIL_ERROR);
             }
         } else {
             // using the scs generator
             $message = "Dear {$customer->firstname} {$customer->lastname}," . PHP_EOL . "your Account was successfully approved! You chose to use the scs tan generator." . PHP_EOL . "You can download the generator in the logged in area (make a transfer section)." . PHP_EOL . "Your scs pin is " . $credentials['scs_pin'] . PHP_EOL . "Best Regards," . PHP_EOL . "SitzBank";
             $mail = Helper::getPhpMailer();
             $mail->addAddress($customer->email, $customer->firstname . ' ' . $customer->lastname);
             $mail->Subject = "Welcome to Sitzbank!";
             $mail->Body = $message;
             if (!$mail->send()) {
                 return JsonErrorResponse::fromKey(JsonErrorResponse::MAIL_ERROR);
             }
         }
     }
     if ($customerRepository->approveRegistration($customerId)) {
         if ($amount > 0) {
             $transaction = Transaction::withData(1, $customer->id, $amount, "Initial Account Balance", 'approved');
             $this->getTransactionRepository()->createTransaction($transaction);
         }
         return new JsonResponse(array('success' => true));
     }
     return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
 }