function getError()
 {
     if ($this->error[0] != 'CURLERR') {
         $xml_parser = new Espresso_gc_XmlParser($this->error[1]);
         $data = $xml_parser->GetData();
         $error = $data['error']['error-message']['VALUE'];
     } else {
         $error = $this->error[1];
     }
     return array('status_code' => $this->error[0], 'message' => $error);
 }
Ejemplo n.º 2
0
 /**
  * Submit a server-to-server request.
  * 
  * more info:
  * {@link http://code.google.com/apis/checkout/developer/index.html#alternate_technique}
  * 
  * @param string $xml_cart the cart's xml
  * @param bool $die whether to die() or not after performing the request,
  *                  defaults to true
  * 
  * @return array with the returned http status code (200 if OK) in index 0 
  *               and the redirect url returned by the server in index 1
  */
 function SendServer2ServerCart($xml_cart, $die = true)
 {
     list($status, $body) = $this->SendReq($this->merchant_checkout, $this->GetAuthenticationHeaders(), $xml_cart);
     if ($status != 200) {
         return array($status, $body);
     } else {
         require_once dirname(__FILE__) . '/xml-processing/gc_xmlparser.php';
         $xml_parser = new Espresso_gc_XmlParser($body);
         $root = $xml_parser->GetRoot();
         $data = $xml_parser->GetData();
         $redirect_url = $data[$root]['redirect-url']['VALUE'];
         $this->log->logRequest("Redirecting to: " . $redirect_url);
         if (strpos($redirect_url, "shoppingcartshoppingcart") != false) {
             $redirect_url = str_replace("shoppingcartshoppingcart", "shoppingcart&shoppingcart", $redirect_url);
         }
         header('Location: ' . $redirect_url);
         if ($die) {
             die($redirect_url);
         } else {
             return array(200, $redirect_url);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Get the Google Checkout button's html to be used with the html api.
  * 
  * {@link http://code.google.com/apis/checkout/developer/index.html#google_checkout_buttons}
  * 
  * @param string $size the size of the button, one of 'large', 'medium' or
  *                     'small'.
  *                     defaults to 'large'
  * @param bool $variant true for an enabled button, false for a 
  *                      disabled one. defaults to true. will be ignored if
  *                      SetButtonVariant() was used before.
  * @param string $loc the locale of the button's text, the only valid value
  *                    is 'en_US' (used as default)
  * @param bool $showtext whether to show Google Checkout text or not, 
  *                       defaults to true.
  * @param string $style the background style of the button, one of 'white'
  *                      or 'trans'. defaults to "trans"
  * 
  * @return string the button's html
  */
 function CheckoutHTMLButtonCode($size = "large", $variant = true, $loc = "en_US", $showtext = true, $style = "trans")
 {
     switch (strtolower($size)) {
         case "medium":
             $width = "168";
             $height = "44";
             break;
         case "small":
             $width = "160";
             $height = "43";
             break;
         case "large":
         default:
             $width = "180";
             $height = "46";
             break;
     }
     if ($this->variant == false) {
         switch ($variant) {
             case false:
                 $this->variant = "disabled";
                 break;
             case true:
             default:
                 $this->variant = "text";
                 break;
         }
     }
     $data = "<div style=\"width: " . $width . "px\">";
     if ($this->variant == "text") {
         $data .= "<div align=\"center\"><form method=\"post\" action=\"" . $this->checkoutForm_url . "\"" . ($this->googleAnalytics_id ? " onsubmit=\"setUrchinInputCode();\"" : "") . ">";
         $request = $this->GetXML();
         require_once dirname(__FILE__) . '/xml-processing/gc_xmlparser.php';
         $xml_parser = new Espresso_gc_XmlParser($request);
         $root = $xml_parser->GetRoot();
         $XMLdata = $xml_parser->GetData();
         $this->xml2html($XMLdata[$root], '', $data);
         $data .= "<input type=\"image\" name=\"Checkout\" alt=\"Checkout\" " . "src=\"" . $this->server_url . "buttons/checkout.gif?merchant_id=" . $this->merchant_id . "&w=" . $width . "&h=" . $height . "&style=" . $style . "&variant=" . $this->variant . "&loc=" . $loc . "\" \n                height=\"" . $height . "\" width=\"" . $width . "\" />";
         if ($this->googleAnalytics_id) {
             $data .= "<input type=\"hidden\" name=\"analyticsdata\" value=\"\" />";
         }
         $data .= "</form></div>";
         if ($this->googleAnalytics_id) {
             $data .= "<!-- Start Google analytics -->\n            <script src=\"https://ssl.google-analytics.com/urchin.js\" type=\"" . "text/javascript\">\n            </script>\n            <script type=\"text/javascript\">\n            _uacct = \"" . $this->googleAnalytics_id . "\";\n            urchinTracker();\n            </script>\n            <script src=\"https://checkout.google.com/files/digital/urchin_po" . "st.js\" type=\"text/javascript\"></script>  \n            <!-- End Google analytics -->";
         }
     } else {
         $data .= "<div align=\"center\"><img alt=\"Checkout\" src=\"" . "" . $this->server_url . "buttons/checkout.gif?merchant_id=" . "" . $this->merchant_id . "&amp;w=" . $width . "&amp;h=" . $height . "&amp;style=" . $style . "&amp;variant=" . $this->variant . "&amp;loc=" . $loc . "\" height=\"" . $height . "\"" . " width=\"" . $width . "\" /></div>";
     }
     if ($showtext) {
         $data .= "<div align=\"center\"><a href=\"javascript:void(window.ope" . "n('http://checkout.google.com/seller/what_is_google_checkout.html'" . ",'whatischeckout','scrollbars=0,resizable=1,directories=0,height=2" . "50,width=400'));\" onmouseover=\"return window.status = 'What is G" . "oogle Checkout?'\" onmouseout=\"return window.status = ''\"><font " . "size=\"-2\">What is Google Checkout?</font></a></div>";
     }
     $data .= "</div>";
     return $data;
 }