/**
  * IPN Handler
  * @return void
  */
 public function callback()
 {
     $this->load->model('checkout/order');
     $post = file_get_contents("php://input");
     if (empty($post)) {
         $this->log('warn', 'IPN handler called with no data');
         return;
     }
     $json = @json_decode($post, true);
     if (empty($json)) {
         $this->log('warn', 'IPN handler called with invalid data');
         $this->log('trace', 'Invalid JSON: ' . $post);
         return;
     }
     if (!array_key_exists('id', $json)) {
         $this->log('warn' . 'IPN handler called with invalid data');
         $this->log('trace', 'Invoice object missing ID field: ' . $var_export($json, true));
         return;
     }
     if (!array_key_exists('url', $json)) {
         $this->log('warn' . 'IPN handler called with invalid data');
         $this->log('trace', 'Invoice object missing URL field: ' . $var_export($json, true));
         return;
     }
     // Try to set the network based on the url first since the merchant may have
     // switched networks while test invoices are still being confirmed
     $network = null;
     if (true === strpos($json['url'], 'https://test.bitpay.com')) {
         $network = 'testnet';
     } elseif (true === strpos($json['url'], 'https://bitpay.com')) {
         $network = 'livenet';
     }
     $invoice = $this->bitpay->getInvoice($json['id'], $network);
     switch ($invoice->getStatus()) {
         case 'paid':
             $order_status_id = $this->setting('paid_status');
             $order_message = $this->language->get('text_progress_paid');
             break;
         case 'confirmed':
             $order_status_id = $this->setting('confirmed_status');
             $order_message = $this->language->get('text_progress_confirmed');
             break;
         case 'complete':
             $order_status_id = $this->setting('complete_status');
             $order_message = $this->language->get('text_progress_complete');
             break;
         default:
             $this->response->redirect($this->url->link('checkout/checkout'));
             return;
     }
     // Progress the order status
     $this->model_checkout_order->addOrderHistory($invoice->getOrderId(), $order_status_id);
 }
Exemple #2
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'));
     }
 }
Exemple #3
0
 /**
  * Install the extension by setting up some smart defaults
  * @return void
  */
 public function install()
 {
     $this->load->model('localisation/order_status');
     $order_statuses = $this->model_localisation_order_status->getOrderStatuses();
     $default_paid = null;
     $default_confirmed = null;
     $default_complete = null;
     foreach ($order_statuses as $order_status) {
         if ($order_status['name'] == 'Processing') {
             $default_paid = $order_status['order_status_id'];
         } elseif ($order_status['name'] == 'Processed') {
             $default_confirmed = $order_status['order_status_id'];
         } elseif ($order_status['name'] == 'Complete') {
             $default_complete = $order_status['order_status_id'];
         }
     }
     $this->load->model('setting/setting');
     $default_settings = array('bitpay_private_key' => null, 'bitpay_public_key' => null, 'bitpay_connection' => 'disconnected', 'bitpay_network' => null, 'bitpay_token' => null, 'bitpay_risk_speed' => 'high', 'bitpay_send_buyer_info' => '0', 'bitpay_geo_zone_id' => '0', 'bitpay_status' => '0', 'bitpay_sort_order' => null, 'bitpay_paid_status' => $default_paid, 'bitpay_confirmed_status' => $default_confirmed, 'bitpay_complete_status' => $default_complete, 'bitpay_notify_url' => null, 'bitpay_return_url' => null, 'bitpay_debug' => '0', 'bitpay_version' => $this->bitpay->version);
     $this->model_setting_setting->editSetting('bitpay', $default_settings);
     $this->bitpay->generateId();
 }