shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

squareup.php (2239B)


      1 <?php
      2 
      3 class ModelExtensionCreditCardSquareup extends Model {
      4     public function addCustomer($data) {
      5         $this->db->query("INSERT INTO `" . DB_PREFIX . "squareup_customer` SET customer_id='" . (int)$data['customer_id'] . "', sandbox='" . (int)$data['sandbox'] . "', square_customer_id='" . $this->db->escape($data['square_customer_id']) . "'");
      6     }
      7 
      8     public function getCustomer($customer_id, $sandbox) {
      9         return $this->db->query("SELECT * FROM `" . DB_PREFIX . "squareup_customer` WHERE customer_id = '" . (int)$customer_id . "' AND sandbox='" . (int)$sandbox . "'")->row;
     10     }
     11 
     12     public function addCard($customer_id, $sandbox, $data) {
     13         $this->db->query("INSERT INTO `" . DB_PREFIX . "squareup_token` SET customer_id='" . (int)$customer_id . "', sandbox='" . (int)$sandbox . "', token='" . $this->db->escape($data['id']) . "', brand='" . $this->db->escape($data['card_brand']) . "', ends_in='" . (int)$data['last_4'] . "', date_added=NOW()");
     14     }
     15 
     16     public function getCard($squareup_token_id) {
     17         return $this->db->query("SELECT * FROM `" . DB_PREFIX . "squareup_token` WHERE squareup_token_id='" . (int)$squareup_token_id . "'")->row;
     18     }
     19     
     20     public function getCards($customer_id, $sandbox) {
     21         return $this->db->query("SELECT * FROM `" . DB_PREFIX . "squareup_token` WHERE customer_id='" . (int)$customer_id . "' AND sandbox='" . (int)$sandbox . "'")->rows;
     22     }
     23 
     24     public function cardExists($customer_id, $data) {
     25         return $this->db->query("SELECT * FROM `" . DB_PREFIX . "squareup_token` WHERE customer_id='" . (int)$customer_id . "' AND brand='" . $this->db->escape($data['card_brand']) . "' AND ends_in='" . (int)$data['last_4'] . "'")->num_rows > 0;
     26     }
     27 
     28     public function verifyCardCustomer($squareup_token_id, $customer_id) {
     29         return $this->db->query("SELECT * FROM `" . DB_PREFIX . "squareup_token` WHERE squareup_token_id='" . (int)$squareup_token_id . "' AND customer_id='" . (int)$customer_id . "'")->num_rows > 0;
     30     }
     31 
     32     public function deleteCard($squareup_token_id) {
     33         $this->db->query("DELETE FROM `" . DB_PREFIX . "squareup_token` WHERE squareup_token_id='" . (int)$squareup_token_id . "'");
     34     }
     35 }