Exemplo n.º 1
0
 public static function get_data($order_id)
 {
     $order_data = array();
     $cloud = new CC_Cloud_API_V1();
     $url = $cloud->api . "orders/{$order_id}";
     $headers = array('Accept' => 'application/json');
     $response = wp_remote_get($url, $cloud->basic_auth_header($headers));
     if ($cloud->response_ok($response)) {
         $order_data = json_decode($response['body'], true);
         CC_Log::write('Order data: ' . print_r($order_data, true));
     }
     return $order_data;
 }
 public static function get_receipt_content($order_number)
 {
     if (empty(self::$receipt_content)) {
         $cloud = new CC_Cloud_API_V1();
         $url = $cloud->subdomain_url() . "receipt/{$order_number}";
         $response = wp_remote_get($url, array('sslverify' => false));
         if (!is_wp_error($response)) {
             if ($response['response']['code'] == '200') {
                 self::$receipt_content = $response['body'];
             }
         } else {
             CC_Log::write('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to locate a receipt with the order number: {$order_number}");
             throw new CC_Exception_Store_ReceiptNotFound('Unable to locate a receipt with the given order number.');
         }
     }
     return self::$receipt_content;
 }
 public static function load_from_cloud($secret_key = null)
 {
     self::$subdomain = null;
     $cloud = new CC_Cloud_API_V1();
     if (isset($secret_key)) {
         $cloud->secret_key = $secret_key;
     }
     $url = $cloud->api . 'subdomain';
     $headers = array('Accept' => 'text/html');
     $response = wp_remote_get($url, $cloud->basic_auth_header($headers));
     if ($cloud->response_ok($response)) {
         $subdomain = $response['body'];
         self::$subdomain = $subdomain;
         CC_Log::write('Successfully retrieved subdomain from the cloud: ' . self::$subdomain);
         // Send plugin version information to the cloud
         $messenger = new CC_Cloud_Messenger();
         $messenger->send_version_info();
         CC_Log::write('Sent version information to cloud after loading subdomain');
     }
     return self::$subdomain;
 }