public function create($slurp_url = '')
 {
     $url = self::$cloud->api . 'carts';
     // Build the headers to create the cart
     $headers = array('Accept' => 'application/json');
     $args = self::$cloud->basic_auth_header($headers);
     $data = array('ip_address' => $_SERVER['REMOTE_ADDR']);
     $data = json_encode($data);
     $args['body'] = $data;
     // Post to create cart
     // CC_Log::write("Create cart via library call to Cart66 Cloud: $url " . print_r( $args, true ) );
     $response = wp_remote_post($url, $args);
     if (!self::$cloud->response_created($response)) {
         CC_Log::write('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Failed to create new cart in Cart66 Cloud: {$url} :: " . print_r($response, true));
         throw new CC_Exception_API('Failed to create new cart in Cart66 Cloud');
     }
     $cart_data = json_decode($response['body']);
     // CC_Log::write( 'data received from cloud after creating cart: ' . print_r( $cart_data, true) );
     $cart_key = $cart_data->key;
     self::$cart_key = $cart_key;
     cc_set_cookie('cc_cart_key', $cart_key);
     return $cart_key;
 }
Esempio n. 2
0
 /**
  * Drop the cc_cart_key cookie
  */
 public static function drop_cart()
 {
     cc_set_cookie('cc_cart_key', '');
     unset($_COOKIE['cc_cart_key']);
 }