Beispiel #1
0
 /**
  * Returns the BitPay Payment Method if available
  * @param  array $address Customer billing address
  * @return array|void BitPay Payment Method if available
  */
 public function getMethod($address)
 {
     // Check for connection to BitPay
     $this->bitpay->checkConnection();
     if ($this->bitpay->setting('connection') === 'disconnected') {
         $this->bitpay->log('warn', 'You cannot have BitPay enabled as a payment method without being connected to BitPay.');
         return;
     }
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int) $this->bitpay->setting('geo_zone_id') . "' AND country_id = '" . (int) $address['country_id'] . "' AND (zone_id = '" . (int) $address['zone_id'] . "' OR zone_id = '0')");
     // All Geo Zones configured or address is in configured Geo Zone
     if (!$this->config->get('bitpay_geo_zone_id') || $query->num_rows) {
         return array('code' => 'bitpay', 'title' => $this->language->get('text_title'), 'terms' => '', 'sort_order' => $this->bitpay->setting('sort_order'));
     }
 }
 /**
  * BitPay Payment Controller Constructor
  * @param Registry $registry
  */
 public function __construct($registry)
 {
     parent::__construct($registry);
     // Make langauge strings and BitPay Library available to all
     $this->load->language('payment/bitpay');
     $this->load->library('bitpay');
     $this->bitpay = new BitpayLibrary($registry);
     // Setup logging
     $this->logger = new Log('bitpay.log');
     // Is this an ajax request?
     if (!empty($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         $this->ajax = true;
     }
     // Check for connection
     if ($this->setting('connection') !== 'disconnected' && $this->setting('connection') !== null) {
         $was_connected = $this->setting('connection') === 'connected';
         $was_network = $this->setting('network');
         $this->bitpay->checkConnection();
     }
 }
Beispiel #3
0
 /**
  * Checks the connection to BitPay API
  * @return void
  */
 public function connected()
 {
     if ($this->setting('connection') !== 'disconnected' && $this->setting('connection') !== null) {
         $was_connected = $this->setting('connection') === 'connected';
         $was_network = $this->setting('network');
         $was_network = is_array($was_network) ? 'testnet' : $was_network;
         $this->bitpay->checkConnection();
         // Connection attempt successful!
         if (!$was_connected && $this->setting('connection') === 'connected') {
             if (is_array($this->setting('network'))) {
                 $network_title = 'Customnet(' . $this->setting('network')['url'] . ')';
             } else {
                 $network_title = ucwords($this->setting('network'));
             }
             $this->session->data['success'] = sprintf($this->language->get('success_connected'), $network_title);
         }
         // Helpful message if a connection breaks (token revoked, etc)
         if ($was_connected && $this->setting('connection') === 'disconnected' && true !== $this->session->data['manual_disconnect']) {
             $pair_url = $this->url->link('payment/bitpay/connect', 'network=' . $was_network . '&token=' . $this->session->data['token']);
             $notification = sprintf($this->language->get('warning_disconnected'), $pair_url);
             if ($this->ajax) {
                 $data = array('error' => $notification);
                 $this->response->setOutput(json_encode($data));
                 return;
             } else {
                 $this->session->data['warning'] = sprintf($this->language->get('warning_disconnected'), $pair_url);
             }
         }
         // Heartbeat for ajax
         if ($this->ajax) {
             $data = array('data' => 'connected');
             $this->response->setOutput(json_encode($data));
             return;
         }
     }
 }