shop.balmet.com

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

squareup.php (4383B)


      1 <?php
      2 
      3 class ControllerExtensionCreditCardSquareup extends Controller {
      4     public function index() {
      5         if (!$this->customer->isLogged()) {
      6             $this->session->data['redirect'] = $this->url->link('account/account', '', true);
      7 
      8             $this->response->redirect($this->url->link('account/login', '', true));
      9         }
     10 
     11         $this->load->language('extension/credit_card/squareup');
     12 
     13         $this->load->model('extension/credit_card/squareup');
     14 
     15         $this->document->setTitle($this->language->get('heading_title'));
     16 
     17         $data['breadcrumbs'] = array();
     18 
     19         $data['breadcrumbs'][] = array(
     20             'text' => $this->language->get('text_home'),
     21             'href' => $this->url->link('common/home')
     22         );
     23 
     24         $data['breadcrumbs'][] = array(
     25             'text' => $this->language->get('text_account'),
     26             'href' => $this->url->link('account/account', '', true)
     27         );
     28 
     29         $data['breadcrumbs'][] = array(
     30             'text' => $this->language->get('heading_title'),
     31             'href' => $this->url->link('extension/credit_card/squareup', '', true)
     32         );
     33 
     34         if (isset($this->session->data['success'])) {
     35             $data['success'] = $this->session->data['success'];
     36 
     37             unset($this->session->data['success']);
     38         } else {
     39             $data['success'] = '';
     40         } 
     41 
     42         if (isset($this->session->data['error'])) {
     43             $data['error'] = $this->session->data['error'];
     44 
     45             unset($this->session->data['error']);
     46         } else {
     47             $data['error'] = '';
     48         } 
     49 
     50         $data['back'] = $this->url->link('account/account', '', true);
     51 
     52         $data['cards'] = array();
     53 
     54         foreach ($this->model_extension_credit_card_squareup->getCards($this->customer->getId(), $this->config->get('payment_squareup_enable_sandbox')) as $card) {
     55             $data['cards'][] = array(
     56                 'text' => sprintf($this->language->get('text_card_ends_in'), $card['brand'], $card['ends_in']),
     57                 'delete' => $this->url->link('extension/credit_card/squareup/forget', 'squareup_token_id=' . $card['squareup_token_id'], true)
     58             );
     59         }
     60 
     61         $data['column_left'] = $this->load->controller('common/column_left');
     62         $data['column_right'] = $this->load->controller('common/column_right');
     63         $data['content_top'] = $this->load->controller('common/content_top');
     64         $data['content_bottom'] = $this->load->controller('common/content_bottom');
     65         $data['footer'] = $this->load->controller('common/footer');
     66         $data['header'] = $this->load->controller('common/header');
     67         
     68         $this->response->setOutput($this->load->view('extension/credit_card/squareup', $data));
     69     }
     70 
     71     public function forget() {
     72         if (!$this->customer->isLogged()) {
     73             $this->session->data['redirect'] = $this->url->link('account/account', '', true);
     74 
     75             $this->response->redirect($this->url->link('account/login', '', true));
     76         }
     77 
     78         $this->load->language('extension/credit_card/squareup');
     79 
     80         $this->load->model('extension/credit_card/squareup');
     81 
     82         $this->load->library('squareup');
     83 
     84         $squareup_token_id = !empty($this->request->get['squareup_token_id']) ?
     85             $this->request->get['squareup_token_id'] : 0;
     86 
     87         if ($this->model_extension_credit_card_squareup->verifyCardCustomer($squareup_token_id, $this->customer->getId())) {
     88             $card_info = $this->model_extension_credit_card_squareup->getCard($squareup_token_id);
     89 
     90             $customer_info = $this->model_extension_credit_card_squareup->getCustomer($this->customer->getId(), $card_info['sandbox']);
     91             
     92             try {
     93                 $this->squareup->deleteCard($customer_info['square_customer_id'], $card_info['token']);
     94                 
     95                 $this->model_extension_credit_card_squareup->deleteCard($squareup_token_id);
     96                 
     97                 $this->session->data['success'] = $this->language->get('text_success_card_delete');
     98             } catch (\Squareup\Exception $e) {
     99                 $this->session->data['error'] = $e->getMessage();
    100             }
    101         }
    102 
    103         $this->response->redirect($this->url->link('extension/credit_card/squareup', '', true));
    104     }
    105 }