public static function confirmCardOwnership($paymentId)
 {
     $sql = 'SELECT payment_method_id from payment_method WHERE payment_method_id = ? AND fk_payment_method_user = ?';
     return Checkout_helper::runConfirmationQuery($sql, $paymentId);
 }
 public function paymentMethod()
 {
     require_once '../app/models/Payment_method.php';
     require_once '../app/models/Address.php';
     if (isset($_POST['paymentMethodId']) && Checkout_helper::confirmCardOwnership($_POST['paymentMethodId'])) {
         $_SESSION['checkout']['properties']['paymentMethod'] = $_POST['paymentMethodId'];
         $this->redirect_to('checkout/confirm');
         break;
     }
     if (isset($_SESSION['payment_method'])) {
         $paymentMethod = $_SESSION['payment_method'];
         if (count($paymentMethod->errorsList) == 0) {
             $_SESSION['checkout']['properties']['paymentMethod'] = $_SESSION['paymentMethodId'];
             unset($_SESSION['paymentMethodId']);
             unset($_SESSION['payment_method']);
             $this->redirect_to('checkout/confirm');
             break;
         }
     } else {
         $paymentMethod = new Payment_Method();
         unset($_SESSION['payment_method']);
         unset($_SESSION['paymentMethodId']);
     }
     if (isset($_SESSION['address'])) {
         $address = $_SESSION['address'];
     } else {
         $address = new Address();
     }
     $addressList = $address->findByUserId($_SESSION['user_id']);
     $paymentList = $paymentMethod->findByUserId($_SESSION['user_id']);
     $addressAttributes = ['full_name', 'address_line_1', 'address_line_2', 'city', 'county', 'postcode', 'country', 'phone_number'];
     $view = new View('checkout/payment_method', ['header' => false, 'footer' => false]);
     $view->set_title('Payment Method');
     $view->pass_data('payment_method', $paymentMethod);
     $view->pass_data('paymentList', $paymentList);
     $view->pass_data('redirect', 'checkout/paymentmethod');
     $view->pass_data('addressAttributes', $addressAttributes);
     $view->pass_data('address', $address);
     $view->pass_data('addressList', $addressList);
     $view->load_page();
     unset($_SESSION['address']);
     unset($_SESSION['payment_method']);
 }