This commit is contained in:
rGaillard
2011-07-06 10:10:43 +00:00
parent 31d94236ac
commit d1a13007b9
4695 changed files with 0 additions and 339293 deletions
File diff suppressed because it is too large Load Diff
-161
View File
@@ -1,161 +0,0 @@
<?php
/*
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Classes used to represent an item to be used for Google Checkout
* @version $Id: googleitem.php 1234 2007-09-25 14:58:57Z ropu $
*/
/**
* Creates an item to be added to the shopping cart.
* A new instance of the class must be created for each item to be added.
*
* Required fields are the item name, description, quantity and price
* The private-data and tax-selector for each item can be set in the
* constructor call or using individual Set functions
*/
class GoogleItem {
var $item_name;
var $item_description;
var $unit_price;
var $quantity;
var $merchant_private_item_data;
var $merchant_item_id;
var $tax_table_selector;
var $email_delivery;
var $digital_content=false;
var $digital_description;
var $digital_key;
var $digital_url;
var $item_weight;
var $numeric_weight;
/**
* {@link http://code.google.com/apis/checkout/developer/index.html#tag_item <item>}
*
* @param string $name the name of the item -- required
* @param string $desc the description of the item -- required
* @param integer $qty the number of units of this item the customer has
* in its shopping cart -- required
* @param double $price the unit price of the item -- required
* @param string $item_weight the weight unit used to specify the item's
* weight,
* one of 'LB' (pounds) or 'KG' (kilograms)
* @param double $numeric_weight the weight of the item
*
*/
function GoogleItem($name, $desc, $qty, $price, $item_weight='', $numeric_weight='') {
$this->item_name = $name;
$this->item_description= $desc;
$this->unit_price = $price;
$this->quantity = $qty;
if($item_weight != '' && $numeric_weight !== '') {
switch(strtoupper($item_weight)){
case 'KG':
$this->item_weight = strtoupper($item_weight);
break;
case 'LB':
default:
$this->item_weight = 'LB';
}
$this->numeric_weight = (double)$numeric_weight;
}
}
function SetMerchantPrivateItemData($private_data) {
$this->merchant_private_item_data = $private_data;
}
/**
* Set the merchant item id that the merchant uses to uniquely identify an
* item. Google Checkout will include this value in the
* merchant calculation callbacks
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_merchant-item-id <merchant-item-id>}
*
* @param mixed $item_id the value that identifies this item on the
* merchant's side
*
* @return void
*/
function SetMerchantItemId($item_id) {
$this->merchant_item_id = $item_id;
}
/**
* Sets the tax table selector which identifies an alternate tax table that
* should be used to calculate tax for a particular item.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_tax-table-selector <tax-table-selector>}
*
* @param string $tax_selector this value should correspond to the name
* of an alternate-tax-table.
*
* @return void
*/
function SetTaxTableSelector($tax_selector) {
$this->tax_table_selector = $tax_selector;
}
/**
* Used when the item's content is digital, sets whether the merchant will
* send an email to the buyer explaining how to access the digital content.
* Email delivery allows the merchant to charge the buyer for an order
* before allowing the buyer to access the digital content.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_email-delivery <email-delivery>}
*
* @param bool $email_delivery true if email_delivery applies, defaults to
* false
*
* @return void
*/
function SetEmailDigitalDelivery($email_delivery='false') {
$this->digital_url = '';
$this->digital_key = '';
$this->digital_description = '';
$this->email_delivery = $email_delivery;
$this->digital_content=true;
}
/**
* Sets the information related to the digital delivery of the item.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_digital-content <digital-content>}
*
* @param string $digital_url the url the customer must go to download the
* item. --optional
* @param string $digital_key the key which allows to download or unlock the
* digital content item -- optional
* @param string $digital_description instructions for downloading adigital
* content item, 1024 characters max, can
* contain xml-escaped HTML -- optional
*
* @return void
*/
function SetURLDigitalContent($digital_url, $digital_key, $digital_description) {
$this->digital_url = $digital_url;
$this->digital_key = $digital_key;
$this->digital_description = $digital_description;
$this->email_delivery = 'false';
$this->digital_content = true;
}
}
-96
View File
@@ -1,96 +0,0 @@
<?php
/**
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Log levels
define("L_OFF", 0); // No log
define("L_ERR", 1); // Log Errors
define("L_RQST", 2); // Log Request from GC
define("L_RESP", 4); // Log Resoponse To Google
define("L_ERR_RQST", L_ERR | L_RQST);
define("L_ALL", L_ERR | L_RQST | L_RESP);
class GoogleLog {
var $errorLogFile;
var $messageLogFile;
// L_ALL (err+requests+responses), L_ERR, L_RQST, L_RESP, L_OFF
var $logLevel = L_ERR_RQST;
/**
* SetLogFiles
*/
function GoogleLog($errorLogFile, $messageLogFile, $logLevel=L_ERR_RQST, $die=true){
$this->logLevel = $logLevel;
if($logLevel == L_OFF) {
$this->logLevel = L_OFF;
} else {
if (!$this->errorLogFile = @fopen($errorLogFile, "a")) {
header('HTTP/1.0 500 Internal Server Error');
$log = "Cannot open " . $errorLogFile . " file.\n" .
"Logs are not writable, set them to 777";
error_log($log, 0);
if($die) {
die($log);
}else {
echo $log;
$this->logLevel = L_OFF;
}
}
if (!$this->messageLogFile = @fopen($messageLogFile, "a")) {
fclose($this->errorLogFile);
header('HTTP/1.0 500 Internal Server Error');
$log = "Cannot open " . $messageLogFile . " file.\n" .
"Logs are not writable, set them to 777";
error_log($log, 0);
if($die) {
die($log);
}else {
echo $log;
$this->logLevel = L_OFF;
}
}
}
$this->logLevel = $logLevel;
}
function LogError($log){
if($this->logLevel & L_ERR){
fwrite($this->errorLogFile,
sprintf("\n%s:- %s\n",date("D M j G:i:s T Y"),$log));
return true;
}
return false;
}
function LogRequest($log){
if($this->logLevel & L_RQST){
fwrite($this->messageLogFile,
sprintf("\n%s:- %s\n",date("D M j G:i:s T Y"),$log));
return true;
}
return false;
}
function LogResponse($log) {
if($this->logLevel & L_RESP){
$this->LogRequest($log);
return true;
}
return false;
}
}
@@ -1,115 +0,0 @@
<?php
/*
* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Used to create the merchant callback results when a
* merchant-calculated feedback structure is received.
*
* Multiple results are generated depending on the possible
* combinations for shipping options and address ids
*
* More info: {@link http://code.google.com/apis/checkout/developer/index.html#understanding_merchant_calculation_results}
*/
// refer to demo/responsehandler.php for generating these results
class GoogleMerchantCalculations {
var $results_arr;
var $currency;
var $schema_url = "http://checkout.google.com/schema/2";
/**
* @param string $currency the currency used for the calculations,
* one of "USD" or "GBP"
*
* @return void
*/
function GoogleMerchantCalculations($currency = "USD") {
$this->results_arr = array();
$this->currency = $currency;
}
/**
* Add a result of a merchant calculation to the response to be sent.
*
* @param GoogleResult $results the result of a particular merchant
* calculation
* @return void
*/
function AddResult($results) {
$this->results_arr[] = $results;
}
/**
* Builds the merchant calculation response xml to be sent to
* Google Checkout.
*
* @return string the response xml
*/
function GetXML() {
require_once('xml-processing/gc_xmlbuilder.php');
$xml_data = new gc_XmlBuilder();
$xml_data->Push('merchant-calculation-results',
array('xmlns' => $this->schema_url));
$xml_data->Push('results');
foreach($this->results_arr as $result) {
if($result->shipping_name != "") {
$xml_data->Push('result', array('shipping-name' =>
$result->shipping_name, 'address-id' => $result->address_id));
$xml_data->Element('shipping-rate', $result->ship_price,
array('currency' => $this->currency));
$xml_data->Element('shippable', $result->shippable);
} else
$xml_data->Push('result', array('address-id' => $result->address_id));
if($result->tax_amount != "")
$xml_data->Element('total-tax', $result->tax_amount,
array('currency' => $this->currency));
if((count($result->coupon_arr) != 0) ||
(count($result->giftcert_arr) != 0) ) {
$xml_data->Push('merchant-code-results');
foreach($result->coupon_arr as $curr_coupon) {
$xml_data->Push('coupon-result');
$xml_data->Element('valid', $curr_coupon->coupon_valid);
$xml_data->Element('code', $curr_coupon->coupon_code);
$xml_data->Element('calculated-amount', $curr_coupon->coupon_amount,
array('currency'=> $this->currency));
$xml_data->Element('message', $curr_coupon->coupon_message);
$xml_data->Pop('coupon-result');
}
foreach($result->giftcert_arr as $curr_gift) {
$xml_data->Push('gift-result');
$xml_data->Element('valid', $curr_gift->gift_valid);
$xml_data->Element('code', $curr_gift->gift_code);
$xml_data->Element('calculated-amount', $curr_gift->gift_amount,
array('currency'=> $this->currency));
$xml_data->Element('message', $curr_gift->gift_message);
$xml_data->Pop('gift-result');
}
$xml_data->Pop('merchant-code-results');
}
$xml_data->Pop('result');
}
$xml_data->Pop('results');
$xml_data->Pop('merchant-calculation-results');
return $xml_data->GetXML();
}
}
-757
View File
@@ -1,757 +0,0 @@
<?php
/*
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
/** This class is instantiated everytime any notification or
* order processing commands are received.
*
* @version $Id: googlerequest.php 1234 2007-09-25 14:58:57Z ropu $
* It has a SendReq function to post different requests to the Google Server
* Send functions are provided for most of the commands that are supported
* by the server for this code
*/
define('PHP_SAMPLE_CODE_VERSION', 'v1.2.5');
define('ENTER', "\r\n");
define('DOUBLE_ENTER', ENTER.ENTER);
// Max size of the Google Messsage string
define('GOOGLE_MESSAGE_LENGTH', 254);
define('GOOGLE_REASON_LENGTH', 140);
/**
* Send requests to the Google Checkout server to perform different actions
*/
// refer demo/responsehandlerdemo.php for different use case scenarios
class GoogleRequest {
var $merchant_id;
var $merchant_key;
var $currency;
var $server_url;
var $schema_url;
var $base_url;
var $checkout_url;
var $checkout_diagnose_url;
var $request_url;
var $request_diagnose_url;
var $merchant_checkout;
var $proxy = array();
var $certPath='';
var $log;
/**
* @param string $id the merchant id
* @param string $key the merchant key
* @param string $server_type the server type of the server to be used, one
* of 'sandbox' or 'production'.
* defaults to 'sandbox'
* @param string $currency the currency of the items to be added to the cart
* , as of now values can be 'USD' or 'GBP'.
* defaults to 'USD'
*/
function GoogleRequest($id, $key, $server_type="sandbox", $currency="USD") {
$this->merchant_id = $id;
$this->merchant_key = $key;
$this->currency = $currency;
if(strtolower($server_type) == "sandbox") {
$this->server_url = "https://sandbox.google.com/checkout/";
} else {
$this->server_url = "https://checkout.google.com/";
}
$this->schema_url = "http://checkout.google.com/schema/2";
$this->base_url = $this->server_url . "api/checkout/v2/";
$this->request_url = $this->base_url . "request/Merchant/" . $this->merchant_id;
$this->merchant_checkout = $this->base_url . "merchantCheckout/Merchant/" . $this->merchant_id;
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'.');
require_once('googlelog.php');
$this->log = new GoogleLog('', '', L_OFF);
}
function SetLogFiles($errorLogFile, $messageLogFile, $logLevel=L_ERR_RQST) {
$this->log = new GoogleLog($errorLogFile, $messageLogFile, $logLevel);
}
/**
* Submit a SetCertificatePath request.
*
* GC Accepted SSL Certs:
* {@link http://googlecheckoutapi.blogspot.com/2007/07/accepting-50-additional-ssl-root-cas.html}
*
* @param string $certPath The name of a file holding one or more certificates
* to verify the peer with
*/
function SetCertificatePath($certPath) {
$this->certPath = $certPath;
}
/**
* 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
*/
public 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 {
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'.');
require_once('xml-processing/gc_xmlparser.php');
$xml_parser = new gc_xmlparser($body);
$root = $xml_parser->GetRoot();
$data = $xml_parser->GetData();
$this->log->logRequest("Redirecting to: ".
$data[$root]['redirect-url']['VALUE']);
header('Location: ' . $data[$root]['redirect-url']['VALUE']);
if($die) {
die($data[$root]['redirect-url']['VALUE']);
}
else {
return array(200, $data[$root]['redirect-url']['VALUE']);
}
}
}
/**
* Send a <charge-order> command to the Google Checkout server
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#charge_order_example}
*
* @param string $google_order the google id of the order
* @param double $amount the amount to be charged, if empty the whole
* amount of the order will be charged
*
* @return array the status code and body of the response
*/
function SendChargeOrder($google_order, $amount='') {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<charge-order xmlns=\"".$this->schema_url.
"\" google-order-number=\"". $google_order. "\">";
if ($amount != '') {
$postargs .= "<amount currency=\"" . $this->currency . "\">" .
$amount . "</amount>";
}
$postargs .= "</charge-order>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <refund-order> command to the Google Checkout server
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#refund_order_example}
*
* @param string $google_order the google id of the order
* @param double $amount the amount to be refunded, if empty the whole
* amount of the order will be refunded
* @param string $reason the reason why the refund is taking place
* @param string $comment a comment about the refund
*
* @return array the status code and body of the response
*/
function SendRefundOrder($google_order, $amount, $reason,
$comment='') {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<refund-order xmlns=\"".$this->schema_url.
"\" google-order-number=\"". $google_order. "\">" .
"<reason>". $reason . "</reason>";
if($amount!=0) {
$postargs .= "<amount currency=\"" . $this->currency . "\">".
htmlentities($amount)."</amount>";
}
$postargs .= "<comment>". htmlentities($comment) . "</comment>
</refund-order>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <cancel-order> command to the Google Checkout server
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#refund_order_example}
*
* @param string $google_order the google id of the order
* @param string $reason the reason why the order is being cancelled
* @param string $comment a comment about the cancellation
*
* @return array the status code and body of the response
*/
function SendCancelOrder($google_order, $reason, $comment) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<cancel-order xmlns=\"".$this->schema_url.
"\" google-order-number=\"". $google_order. "\">
<reason>".
(substr(htmlentities(strip_tags($reason)),0,GOOGLE_REASON_LENGTH)) .
"</reason>
<comment>".
(substr(htmlentities(strip_tags($comment)),0,GOOGLE_REASON_LENGTH)) .
"</comment>
</cancel-order>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send an <add-tracking-data> command to the Google Checkout server, which
* will associate a shipper's tracking number with an order.
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#add_tracking_data_example}
*
* @param string $google_order the google id of the order
* @param string $carrier the carrier, valid values are "DHL", "FedEx",
* "UPS", "USPS" and "Other"
* @param string $tracking_no the shipper's tracking number
*
* @return array the status code and body of the response
*/
function SendTrackingData($google_order, $carrier,
$tracking_no) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<add-tracking-data xmlns=\"". $this->schema_url .
"\" google-order-number=\"". $google_order . "\">
<tracking-data>
<carrier>". htmlentities($carrier) . "</carrier>
<tracking-number>". $tracking_no . "</tracking-number>
</tracking-data>
</add-tracking-data>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send an <add-merchant-order-number> command to the Google Checkout
* server, which will associate a merchant order number with an order
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#add_merchant_order_number_example}
*
* @param string $google_order the google id of the order
* @param string $merchant_order the merchant id of the order
*
* @return array the status code and body of the response
*/
function SendMerchantOrderNumber($google_order,
$merchant_order, $timeout=false) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<add-merchant-order-number xmlns=\"". $this->schema_url .
"\" google-order-number=\"". $google_order . "\">
<merchant-order-number>" . $merchant_order .
"</merchant-order-number>
</add-merchant-order-number>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs, $timeout);
}
/**
* Send a <send-buyer-message> command to the Google Checkout
* server, which will place a message in the customer's Google Checkout
* account
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#send_buyer_message_example}
*
* @param string $google_order the google id of the order
* @param string $message the message to be sent to the customer
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendBuyerMessage($google_order, $message,
$send_mail="true", $timeout=false) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<send-buyer-message xmlns=\"". $this->schema_url .
"\" google-order-number=\"". $google_order . "\">
<message>" .
(substr(htmlentities(strip_tags($message)),0,GOOGLE_MESSAGE_LENGTH))
. "</message>
<send-email>" . strtolower($send_mail) . "</send-email>
</send-buyer-message>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs, $timeout);
}
/**
* Send a <process-order> command to the Google Checkout
* server, which will update an order's fulfillment state from NEW to
* PROCESSING
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#process_order_example}
*
* @param string $google_order the google id of the order
*
* @return array the status code and body of the response
*/
function SendProcessOrder($google_order) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<process-order xmlns=\"".$this->schema_url .
"\" google-order-number=\"". $google_order. "\"/> ";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <deliver-order> command to the Google Checkout server, which
* will update an order's fulfillment state from either NEW or PROCESSING
* to DELIVERED
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#deliver_order_example}
*
* @param string $google_order the google id of the order
* @param string $carrier the carrier, valid values are "DHL", "FedEx",
* "UPS", "USPS" and "Other"
* @param string $tracking_no the shipper's tracking number
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendDeliverOrder($google_order, $carrier="",
$tracking_no="", $send_mail = "true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<deliver-order xmlns=\"". $this->schema_url .
"\" google-order-number=\"". $google_order . "\">";
if($carrier != "" && $tracking_no != "") {
$postargs .= "<tracking-data>
<carrier>". htmlentities($carrier) . "</carrier>
<tracking-number>". htmlentities($tracking_no) . "</tracking-number>
</tracking-data>";
}
$postargs .= "<send-email>". strtolower($send_mail) . "</send-email>
</deliver-order>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <archive-order> command to the Google Checkout
* server, which removes an order from the merchant's Merchant Center Inbox
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#archive_order_example}
*
* @param string $google_order the google id of the order
*
* @return array the status code and body of the response
*/
function SendArchiveOrder($google_order) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<archive-order xmlns=\"".$this->schema_url.
"\" google-order-number=\"". $google_order. "\"/>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <archive-order> command to the Google Checkout
* server, which returns a previously archived order to the merchant's
* Merchant Center Inbox
*
* info: {@link http://code.google.com/apis/checkout/developer/index.html#unarchive_order_example}
*
* @param string $google_order the google id of the order
*
* @return array the status code and body of the response
*/
function SendUnarchiveOrder($google_order) {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<unarchive-order xmlns=\"".
$this->schema_url."\" google-order-number=\"".
$google_order. "\"/>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Ship items API Commands
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html}
*
*
*/
/**
* Send a <ship-items> command to the Google Checkout
* server,
*
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html#tag_ship-items}
*
* @param string $google_order the google id of the order
* @param array $items_list a list of GoogleShipItem classes.
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendShipItems($google_order, $items_list=array(), $send_mail="true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<ship-items xmlns=\"". $this->schema_url .
"\" google-order-number=\"". $google_order . "\">" .
"<item-shipping-information-list>\n";
foreach($items_list as $item) {
$postargs .= "<item-shipping-information>
<item-id>
<merchant-item-id>" . $item->merchant_item_id . "</merchant-item-id>
</item-id>\n";
if(count($item->tracking_data_list)) {
$postargs .= "<tracking-data-list>\n";
foreach($item->tracking_data_list as $tracking_data) {
$postargs .= "<tracking-data>
<carrier>". htmlentities($tracking_data['carrier']) . "</carrier>
<tracking-number>". $tracking_data['tracking-number'] . "</tracking-number>
</tracking-data>\n";
}
$postargs .= "</tracking-data-list>\n";
}
$postargs .= "</item-shipping-information>\n";
}
$postargs .= "</item-shipping-information-list>\n" .
"<send-email>". strtolower($send_mail) . "</send-email>
</ship-items>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <backorder-items> command to the Google Checkout
*
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html#tag_backorder-items}
*
* @param string $google_order the google id of the order
* @param array $items_list a list of GoogleShipItem classes.
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendBackorderItems($google_order, $items_list=array(), $send_mail="true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<backorder-items xmlns=\"".
$this->schema_url."\" google-order-number=\"".
$google_order. "\">";
$postargs .= "<item-ids>";
foreach($items_list as $item) {
$postargs .= "<item-id>
<merchant-item-id>" . $item->merchant_item_id . "</merchant-item-id>
</item-id>";
}
$postargs .= "</item-ids>";
$postargs .= "<send-email>". strtolower($send_mail) . "</send-email>
</backorder-items>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <cancel-items> command to the Google Checkout
*
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html#tag_cancel-items}
*
* @param string $google_order the google id of the order
* @param array $items_list a list of GoogleShipItem classes.
* @param string $reason the reason why the refund is taking place
* @param string $comment a comment about the refund
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendCancelItems($google_order, $items_list=array(), $reason,
$comment='', $send_mail="true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<cancel-items xmlns=\"".
$this->schema_url."\" google-order-number=\"".
$google_order. "\">";
$postargs .= "<item-ids>";
foreach($items_list as $item) {
$postargs .= "<item-id>
<merchant-item-id>" . $item->merchant_item_id . "</merchant-item-id>
</item-id>";
}
$postargs .= "</item-ids>";
$postargs .= "<send-email>". strtolower($send_mail) . "</send-email>
<reason>".
(substr(htmlentities(strip_tags($reason)),0,GOOGLE_REASON_LENGTH)) .
"</reason>
<comment>".
(substr(htmlentities(strip_tags($comment)),0,GOOGLE_REASON_LENGTH)) .
"</comment>
</cancel-items>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <return-items> command to the Google Checkout
*
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html#tag_return-items}
*
* @param string $google_order the google id of the order
* @param array $items_list a list of GoogleShipItem classes.
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendReturnItems($google_order, $items_list=array(), $send_mail="true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<return-items xmlns=\"".
$this->schema_url."\" google-order-number=\"".
$google_order. "\">";
$postargs .= "<item-ids>";
foreach($items_list as $item) {
$postargs .= "<item-id>
<merchant-item-id>" . $item->merchant_item_id . "</merchant-item-id>
</item-id>";
}
$postargs .= "</item-ids>";
$postargs .= "<send-email>". strtolower($send_mail) . "</send-email>
</return-items>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* Send a <reset-items-shipping-information> command to the Google Checkout
*
* info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Line_Item_Shipping.html#tag_reset-items-shipping-information}
*
* @param string $google_order the google id of the order
* @param array $items_list a list of GoogleShipItem classes.
* @param string $send_email whether Google should send an email to
* the buyer, use "true" or"false",
* defaults to "true"
*
* @return array the status code and body of the response
*/
function SendResetItemsShippingInformation($google_order, $items_list=array(), $send_mail="true") {
$postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<reset-items-shipping-information xmlns=\"".
$this->schema_url."\" google-order-number=\"".
$google_order. "\">";
$postargs .= "<item-ids>";
foreach($items_list as $item) {
$postargs .= "<item-id>
<merchant-item-id>" . $item->merchant_item_id . "</merchant-item-id>
</item-id>";
}
$postargs .= "</item-ids>";
$postargs .= "<send-email>". strtolower($send_mail) . "</send-email>
</reset-items-shipping-information>";
return $this->SendReq($this->request_url,
$this->GetAuthenticationHeaders(), $postargs);
}
/**
* @access private
*/
function GetAuthenticationHeaders() {
$headers = array();
$headers[] = "Authorization: Basic ".base64_encode(
$this->merchant_id.':'.$this->merchant_key);
$headers[] = "Content-Type: application/xml; charset=UTF-8";
$headers[] = "Accept: application/xml; charset=UTF-8";
$headers[] = "User-Agent: GC-PHP-Sample_code (" . PHP_SAMPLE_CODE_VERSION . "/ropu)";
return $headers;
}
/**
* Set the proxy to be used by the connections to the outside
*
* @param array $proxy Array('host' => 'proxy-host', 'port' => 'proxy-port')
*
*/
function SetProxy($proxy=array()) {
if(is_array($proxy) && count($proxy)) {
$this->proxy['host'] = $proxy['host'];
$this->proxy['port'] = $proxy['port'];
}
}
/**
* @access private
*/
function SendReq($url, $header_arr, $postargs, $timeout=false) {
// Get the curl session object
$session = curl_init($url);
$this->log->LogRequest($postargs);
// Set the POST options.
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HTTPHEADER, $header_arr);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if(!empty($this->certPath) && file_exists($this->certPath)) {
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($session, CURLOPT_CAINFO, $this->certPath);
}
else {
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
}
if(is_array($this->proxy) && count($this->proxy)) {
curl_setopt($session, CURLOPT_PROXY,
$this->proxy['host'] . ":" . $this->proxy['port']);
}
if($timeout != false){
curl_setopt($session, CURLOPT_TIMEOUT, $timeout);
}
// Do the POST and then close the session
$response = curl_exec($session);
if (curl_errno($session)) {
$this->log->LogError(curl_error($session));
return array("CURL_ERR", curl_error($session));
} else {
curl_close($session);
}
$heads = $this->parse_headers($response);
$body = $this->get_body_x($response);
// // Get HTTP Status code from the response
$status_code = array();
preg_match('/\d\d\d/', $heads[0], $status_code);
// Check for errors
switch( $status_code[0] ) {
case 200:
// Success
$this->log->LogResponse($response);
return array(200, $body);
break;
case 503:
$this->log->LogError($response);
return array(503, htmlentities($body));
break;
case 403:
$this->log->LogError($response);
return array(403, htmlentities($body));
break;
case 400:
$this->log->LogError($response);
return array(400, htmlentities($body));
break;
default:
$this->log->LogError($response);
return array("ERR", htmlentities($body));
break;
}
}
// Private functions
// Function to get HTTP headers,
// will also work with HTTP 200 status added by some proxy servers
/**
* @access private
*/
function parse_headers($message) {
$head_end = strpos($message, DOUBLE_ENTER);
$headers = $this->get_headers_x(substr($message,0,
$head_end + strlen(DOUBLE_ENTER)));
if(!is_array($headers) || empty($headers)){
return null;
}
if(!preg_match('%[HTTP/\d\.\d] (\d\d\d)%', $headers[0], $status_code)) {
return null;
}
switch( $status_code[1] ) {
case '200':
$parsed = $this->parse_headers(substr($message,
$head_end + strlen(DOUBLE_ENTER)));
return is_null($parsed)?$headers:$parsed;
break;
default:
return $headers;
break;
}
}
/**
* @access private
*/
function get_headers_x($heads, $format=0) {
$fp = explode(ENTER, $heads);
foreach($fp as $header){
if($header == "") {
$eoheader = true;
break;
} else {
$header = trim($header);
}
if($format == 1) {
$key = array_shift(explode(':',$header));
if($key == $header) {
$headers[] = $header;
} else {
$headers[$key]=substr($header,strlen($key)+2);
}
unset($key);
} else {
$headers[] = $header;
}
}
return $headers;
}
/**
* @access private
*/
function get_body_x($heads){
$fp = explode(DOUBLE_ENTER, $heads, 2);
return $fp[1];
}
}
class GoogleShipItem {
var $merchant_item_id;
var $tracking_data_list;
var $tracking_no;
function GoogleShipItem($merchant_item_id, $tracking_data_list=array()) {
$this->merchant_item_id = $merchant_item_id;
$this->tracking_data_list = $tracking_data_list;
}
function AddTrackingData($carrier, $tracking_no) {
if($carrier != "" && $tracking_no != "") {
$this->tracking_data_list[] = array('carrier' => $carrier,
'tracking-number' => $tracking_no);
}
}
}
@@ -1,221 +0,0 @@
<?php
/*
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* This class is instantiated everytime any notification or
* order processing commands are received.
*
* Refer demo/responsehandlerdemo.php for different use case scenarios
* for this code
*/
/**
* Handles the response to notifications sent by the Google Checkout server.
*/
class GoogleResponse {
var $merchant_id;
var $merchant_key;
var $schema_url;
var $log;
var $response;
var $root='';
var $data=array();
var $xml_parser;
/**
* @param string $id the merchant id
* @param string $key the merchant key
*/
function GoogleResponse($id=null, $key=null) {
$this->merchant_id = $id;
$this->merchant_key = $key;
$this->schema_url = "http://checkout.google.com/schema/2";
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'.');
require_once('googlelog.php');
$this->log = new GoogleLog('', '', L_OFF);
}
/**
* @param string $id the merchant id
* @param string $key the merchant key
*/
function SetMerchantAuthentication($id, $key){
$this->merchant_id = $id;
$this->merchant_key = $key;
}
function SetLogFiles($errorLogFile, $messageLogFile, $logLevel=L_ERR_RQST) {
$this->log = new GoogleLog($errorLogFile, $messageLogFile, $logLevel);
}
/**
* Verifies that the authentication sent by Google Checkout matches the
* merchant id and key
*
* @param string $headers the headers from the request
*/
function HttpAuthentication($headers=null, $die=true) {
if(!is_null($headers)) {
$_SERVER = $headers;
}
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$compare_mer_id = $_SERVER['PHP_AUTH_USER'];
$compare_mer_key = $_SERVER['PHP_AUTH_PW'];
}
// IIS Note:: For HTTP Authentication to work with IIS,
// the PHP directive cgi.rfc2616_headers must be set to 0 (the default value).
else if(isset($_SERVER['HTTP_AUTHORIZATION'])){
list($compare_mer_id, $compare_mer_key) = explode(':',
base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'],
strpos($_SERVER['HTTP_AUTHORIZATION'], " ") + 1)));
} else if(isset($_SERVER['Authorization'])) {
list($compare_mer_id, $compare_mer_key) = explode(':',
base64_decode(substr($_SERVER['Authorization'],
strpos($_SERVER['Authorization'], " ") + 1)));
} else {
$this->SendFailAuthenticationStatus(
"Failed to Get Basic Authentication Headers",$die);
return false;
}
if($compare_mer_id != $this->merchant_id
|| $compare_mer_key != $this->merchant_key) {
$this->SendFailAuthenticationStatus("Invalid Merchant Id/Key Pair",$die);
return false;
}
return true;
}
function ProcessMerchantCalculations($merchant_calc) {
$this->SendOKStatus();
$result = $merchant_calc->GetXML();
echo $result;
}
// Notification API
function ProcessNewOrderNotification() {
$this->SendAck();
}
function ProcessRiskInformationNotification() {
$this->SendAck();
}
function ProcessOrderStateChangeNotification() {
$this->SendAck();
}
// Amount Notifications
function ProcessChargeAmountNotification() {
$this->SendAck();
}
function ProcessRefundAmountNotification() {
$this->SendAck();
}
function ProcessChargebackAmountNotification() {
$this->SendAck();
}
function ProcessAuthorizationAmountNotification() {
$this->SendAck();
}
function SendOKStatus() {
header('HTTP/1.0 200 OK');
}
/**
* Set the response header indicating an erroneous authentication from
* Google Checkout
*
* @param string $msg the message to log
*/
function SendFailAuthenticationStatus($msg="401 Unauthorized Access",
$die=true) {
$this->log->logError($msg);
header('WWW-Authenticate: Basic realm="GoogleCheckout PHPSample Code"');
header('HTTP/1.0 401 Unauthorized');
if($die) {
die($msg);
} else {
echo $msg;
}
}
/**
* Set the response header indicating a malformed request from Google
* Checkout
*
* @param string $msg the message to log
*/
function SendBadRequestStatus($msg="400 Bad Request", $die=true) {
$this->log->logError($msg);
header('HTTP/1.0 400 Bad Request');
if($die) {
die($msg);
} else {
echo $msg;
}
}
/**
* Set the response header indicating that an internal error ocurred and
* the notification sent by Google Checkout can't be processed right now
*
* @param string $msg the message to log
*/
function SendServerErrorStatus($msg="500 Internal Server Error",
$die=true) {
$this->log->logError($msg);
header('HTTP/1.0 500 Internal Server Error');
if($die) {
die($msg);
} else {
echo $msg;
}
}
/**
* Send an acknowledgement in response to Google Checkout's request
*/
function SendAck($die=true) {
$this->SendOKStatus();
$acknowledgment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<notification-acknowledgment xmlns=\"" .
$this->schema_url . "\"/>";
$this->log->LogResponse($acknowledgment);
if($die) {
die($acknowledgment);
} else {
echo $acknowledgment;
}
}
/**
* @access private
*/
function GetParsedXML($request=null){
if(!is_null($request)) {
$this->log->LogRequest($request);
$this->response = $request;
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'.');
require_once('xml-processing/gc_xmlparser.php');
$this->xml_parser = new gc_xmlparser($request);
$this->root = $this->xml_parser->GetRoot();
$this->data = $this->xml_parser->GetData();
}
return array($this->root, $this->data);
}
}
-105
View File
@@ -1,105 +0,0 @@
<?php
/*
* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Used to create a Google Checkout result as a response to a
* merchant-calculations feedback structure, i.e shipping, tax, coupons and
* gift certificates.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_result <result>}
*/
// refer to demo/responsehandlerdemo.php for usage of this code
class GoogleResult {
var $shipping_name;
var $address_id;
var $shippable;
var $ship_price;
var $tax_amount;
var $coupon_arr = array();
var $giftcert_arr = array();
/**
* @param integer $address_id the id of the anonymous address sent by
* Google Checkout.
*/
function GoogleResult($address_id) {
$this->address_id = $address_id;
}
function SetShippingDetails($name, $price, $shippable = "true") {
$this->shipping_name = $name;
$this->ship_price = $price;
$this->shippable = $shippable;
}
function SetTaxDetails($amount) {
$this->tax_amount = $amount;
}
function AddCoupons($coupon) {
$this->coupon_arr[] = $coupon;
}
function AddGiftCertificates($gift) {
$this->giftcert_arr[] = $gift;
}
}
/**
* This is a class used to return the results of coupons the buyer supplied in
* the order page.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_coupon-result <coupon-result>}
*/
class GoogleCoupons {
var $coupon_valid;
var $coupon_code;
var $coupon_amount;
var $coupon_message;
function googlecoupons($valid, $code, $amount, $message) {
$this->coupon_valid = $valid;
$this->coupon_code = $code;
$this->coupon_amount = $amount;
$this->coupon_message = $message;
}
}
/**
* This is a class used to return the results of gift certificates
* supplied by the buyer on the place order page
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_gift-certificate-result} <gift-certificate-result>
*/
class GoogleGiftcerts {
var $gift_valid;
var $gift_code;
var $gift_amount;
var $gift_message;
function googlegiftcerts($valid, $code, $amount, $message) {
$this->gift_valid = $valid;
$this->gift_code = $code;
$this->gift_amount = $amount;
$this->gift_message = $message;
}
}
@@ -1,532 +0,0 @@
<?php
/*
* Copyright (C) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Classes used to represent shipping types
* @version $Id: googleshipping.php 1234 2007-09-25 14:58:57Z ropu $
*/
/**
* Class that represents flat rate shipping
*
* info:
* {@link http://code.google.com/apis/checkout/developer/index.html#tag_flat-rate-shipping}
* {@link http://code.google.com/apis/checkout/developer/index.html#shipping_xsd}
*
*/
class GoogleFlatRateShipping {
var $price;
var $name;
var $type = "flat-rate-shipping";
var $shipping_restrictions;
/**
* @param string $name a name for the shipping
* @param double $price the price for this shipping
*/
function GoogleFlatRateShipping($name, $price) {
$this->name = $name;
$this->price = $price;
}
/**
* Adds a restriction to this shipping.
*
* @param GoogleShippingFilters $restrictions the shipping restrictions
*/
function AddShippingRestrictions($restrictions) {
$this->shipping_restrictions = $restrictions;
}
}
/**
* Represents a merchant calculated shipping
*
* info:
* {@link http://code.google.com/apis/checkout/developer/index.html#shipping_xsd}
* {@link http://code.google.com/apis/checkout/developer/index.html#merchant_calculations_specifying}
*/
class GoogleMerchantCalculatedShipping {
var $price;
var $name;
var $type = "merchant-calculated-shipping";
var $shipping_restrictions;
var $address_filters;
/**
* @param string $name a name for the shipping
* @param double $price the default price for this shipping, used if the
* calculation can't be made for some reason.
*/
function GoogleMerchantCalculatedShipping($name, $price) {
$this->price = $price;
$this->name = $name;
}
/**
* Adds a restriction to this shipping.
*
* @param GoogleShippingFilters $restrictions the shipping restrictions
*/
function AddShippingRestrictions($restrictions) {
$this->shipping_restrictions = $restrictions;
}
/**
* Adds an address filter to this shipping.
*
* @param GoogleShippingFilters $filters the address filters
*/
function AddAddressFilters($filters) {
$this->address_filters = $filters;
}
}
/**
* Represents carrier calculated shipping
*/
class GoogleCarrierCalculatedShipping {
var $name;
var $type = "carrier-calculated-shipping";
var $CarrierCalculatedShippingOptions = array();
// var $ShippingPackages = array();
var $ShippingPackage;
/**
* @param string $name the name of this shipping
*/
function GoogleCarrierCalculatedShipping($name) {
$this->name = $name;
}
/**
* @param GoogleCarrierCalculatedShippingOption $option the option to be
* added to the carrier calculated shipping
*/
function addCarrierCalculatedShippingOptions($option){
$this->CarrierCalculatedShippingOptions[] = $option;
}
/**
* @param GoogleShippingPackage $package
*/
function addShippingPackage($package){
// $this->ShippingPackages[] = $package;
$this->ShippingPackage = $package;
}
}
/**
* Represents a shipping method for which Google Checkout will obtain
* shipping costs for the order.
*/
class GoogleCarrierCalculatedShippingOption {
var $price;
var $shipping_company;
var $shipping_type;
var $carrier_pickup;
var $additional_fixed_charge;
var $additional_variable_charge_percent;
// var $shipping_restrictions;
// var $address_filters;
/**
* @param double $price the default shipping cost to be used if Google is
* unable to obtain the shipping_company's shipping rate for
* the option
* @param string $shipping_company the name of the shipping_company
* @param string $shipping_type the shipping option, valid values are here:
* http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Carrier_Calculated_Shipping.html#tag_shipping-type
* @param double $additional_fixed_charge a handling charge that will be
* added to the total cost of the order if this shipping option is selected.
* defaults to 0
* @param double $additional_variable_charge_percent A percentage by which
* the shipping rate will be adjusted. The value may be positive or
* negative. defaults to 0.
* @param string $carrier_pickup Specifies how the package will be
* transfered from the merchand to the shipper. Valid values are
* "REGULAR_PICKUP", "SPECIAL_PICKUP", "DROP_OFF". Defaults to "DROP_OFF".
*
*/
function GoogleCarrierCalculatedShippingOption($price, $shipping_company,
$shipping_type, $additional_fixed_charge=0,
$additional_variable_charge_percent=0, $carrier_pickup='DROP_OFF') {
$this->price = (double)$price;
$this->shipping_company = $shipping_company;
$this->shipping_type = trim($shipping_type);
switch(strtoupper($carrier_pickup)){
case 'DROP_OFF':
case 'REGULAR_PICKUP':
case 'SPECIAL_PICKUP':
$this->carrier_pickup = $carrier_pickup;
break;
default:
$this->carrier_pickup = 'DROP_OFF';
}
if($additional_fixed_charge){
$this->additional_fixed_charge = (double)$additional_fixed_charge;
}
if($additional_variable_charge_percent){
$this->additional_variable_charge_percent = (double)$additional_variable_charge_percent;
}
}
// function AddShippingRestrictions($restrictions) {
// $this->shipping_restrictions = $restrictions;
// }
//
// function AddAddressFilters($filters) {
// $this->address_filters = $filters;
// }
}
/**
* Represents an individual package that will be shipped to the buyer.
*/
class GoogleShippingPackage {
var $width;
var $length;
var $height;
var $unit;
var $ship_from;
var $delivery_address_category;
/**
* @param GoogleShipFrom $ship_from where the package ships from
* @param double $width the width of the package
* @param double $length the length of the package
* @param double $height the height of the package
* @param string $unit the unit used to measure the width/length/height
* of the package, valid values "IN", "CM"
* @param string $delivery_address_category indicates whether the shipping
* method should be applied to a residential or commercial address, valid
* values are "RESIDENTIAL", "COMMERCIAL"
*/
function GoogleShippingPackage($ship_from, $width, $length, $height, $unit,
$delivery_address_category='RESIDENTIAL') {
$this->width = (double)$width;
$this->length = (double)$length;
$this->height = (double)$height;
switch(strtoupper($unit)){
case 'CM':
$this->unit = strtoupper($unit);
break;
case 'IN':
default:
$this->unit = 'IN';
}
$this->ship_from = $ship_from;
switch(strtoupper($delivery_address_category)){
case 'COMMERCIAL':
$this->delivery_address_category = strtoupper($delivery_address_category);
break;
case 'RESIDENTIAL':
default:
$this->delivery_address_category = 'RESIDENTIAL';
}
}
}
/**
* Represents the location from where packages will be shipped from.
* Used with {@link GoogleShippingPackage}.
*/
class GoogleShipFrom {
var $id;
var $city;
var $country_code;
var $postal_code;
var $region;
/**
* @param string $id an id for this address
* @param string $city the city
* @param string $country_code a 2-letter iso country code
* @param string $postal_code the zip
* @param string $region the region
*/
function GoogleShipFrom($id, $city, $country_code,
$postal_code, $region) {
$this->id = $id;
$this->city = $city;
$this->country_code = $country_code;
$this->postal_code = $postal_code;
$this->region = $region;
}
}
/**
*
* Shipping restrictions contain information about particular areas where
* items can (or cannot) be shipped.
*
* More info:
* {@link http://code.google.com/apis/checkout/developer/index.html#tag_shipping-restrictions}
*
* Address filters identify areas where a particular merchant-calculated
* shipping method is available or unavailable. Address filters are applied
* before Google Checkout sends a <merchant-calculation-callback> to the
* merchant. Google Checkout will not ask you to calculate the cost of a
* particular shipping method for an address if the address filters in the
* Checkout API request indicate that the method is not available for the
* address.
*
* More info:
* {@link http://code.google.com/apis/checkout/developer/index.html#tag_address-filters}
*/
class GoogleShippingFilters {
var $allow_us_po_box = true;
var $allowed_restrictions = false;
var $excluded_restrictions = false;
var $allowed_world_area = false;
var $allowed_country_codes_arr;
var $allowed_postal_patterns_arr;
var $allowed_country_area;
var $allowed_state_areas_arr;
var $allowed_zip_patterns_arr;
var $excluded_country_codes_arr;
var $excluded_postal_patterns_arr;
var $excluded_country_area;
var $excluded_state_areas_arr;
var $excluded_zip_patterns_arr;
function GoogleShippingFilters() {
$this->allowed_country_codes_arr = array();
$this->allowed_postal_patterns_arr = array();
$this->allowed_state_areas_arr = array();
$this->allowed_zip_patterns_arr = array();
$this->excluded_country_codes_arr = array();
$this->excluded_postal_patterns_arr = array();
$this->excluded_state_areas_arr = array();
$this->excluded_zip_patterns_arr = array();
}
/**
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_allow-us-po-box <allow-us-po-box>}
*
* @param bool $allow_us_po_box whether to allow delivery to PO boxes in US,
* defaults to true
*/
function SetAllowUsPoBox($allow_us_po_box = true) {
$this->allow_us_po_box = $allow_us_po_box;
}
/**
* Set the world as allowed delivery area.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_world-area <world-area>}
*
* @param bool $world_area Set worldwide allowed shipping, defaults to true
*/
function SetAllowedWorldArea($world_area = true) {
$this->allowed_restrictions = true;
$this->allowed_world_area = $world_area;
}
// Allows
/**
* Add a postal area to be allowed for delivery.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_postal-area <postal-area>}
*
* @param string $country_code 2-letter iso country code
* @param string $postal_pattern Pattern that matches the postal areas to
* be allowed, as defined in {@link http://code.google.com/apis/checkout/developer/index.html#tag_postal-code-pattern}
*/
function AddAllowedPostalArea($country_code, $postal_pattern = "") {
$this->allowed_restrictions = true;
$this->allowed_country_codes_arr[] = $country_code;
$this->allowed_postal_patterns_arr[]= $postal_pattern;
}
/**
* Add a us country area to be allowed for delivery.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_us-country-area <us-country-area>}
*
* @param string $country_area the area to allow, one of "CONTINENTAL",
* "FULL_50_STATES" or "ALL"
*
*/
function SetAllowedCountryArea($country_area) {
switch ($country_area) {
case "CONTINENTAL_48":
case "FULL_50_STATES":
case "ALL":
$this->allowed_country_area = $country_area;
$this->allowed_restrictions = true;
break;
default:
$this->allowed_country_area = "";
break;
}
}
/**
* Allow shipping to areas specified by state.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_us-state-area <us-state-area>}
*
* @param array $areas Areas to be allowed
*/
function SetAllowedStateAreas($areas) {
$this->allowed_restrictions = true;
$this->allowed_state_areas_arr = $areas;
}
/**
* Allow shipping to areas specified by state.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_us-state-area <us-state-area>}
*
* @param string $area Area to be allowed
*/
function AddAllowedStateArea($area) {
$this->allowed_restrictions = true;
$this->allowed_state_areas_arr[] = $area;
}
/**
* Allow shipping to areas specified by zip patterns.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_us-zip-area <us-zip-area>}
*
* @param array $zips
*/
function SetAllowedZipPatterns($zips) {
$this->allowed_restrictions = true;
$this->allowed_zip_patterns_arr = $zips;
}
/**
* Allow shipping to area specified by zip pattern.
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_us-zip-area <us-zip-area>}
*
* @param string
*/
function AddAllowedZipPattern($zip) {
$this->allowed_restrictions = true;
$this->allowed_zip_patterns_arr[] = $zip;
}
/**
* Exclude postal areas from shipping.
*
* @see AddAllowedPostalArea
*/
function AddExcludedPostalArea($country_code, $postal_pattern = "") {
$this->excluded_restrictions = true;
$this->excluded_country_codes_arr[] = $country_code;
$this->excluded_postal_patterns_arr[]= $postal_pattern;
}
/**
* Exclude state areas from shipping.
*
* @see SetAllowedStateAreas
*/
function SetExcludedStateAreas($areas) {
$this->excluded_restrictions = true;
$this->excluded_state_areas_arr = $areas;
}
/**
* Exclude state area from shipping.
*
* @see AddAllowedStateArea
*/
function AddExcludedStateArea($area) {
$this->excluded_restrictions = true;
$this->excluded_state_areas_arr[] = $area;
}
/**
* Exclude shipping to area specified by zip pattern.
*
* @see SetAllowedZipPatterns
*/
function SetExcludedZipPatternsStateAreas($zips) {
$this->excluded_restrictions = true;
$this->excluded_zip_patterns_arr = $zips;
}
/**
* Exclude shipping to area specified by zip pattern.
*
* @see AddExcludedZipPattern
*/
function SetAllowedZipPatternsStateArea($zip) {
$this->excluded_restrictions = true;
$this->excluded_zip_patterns_arr[] = $zip;
}
/**
* Exclude shipping to country area
*
* @see SetAllowedCountryArea
*/
function SetExcludedCountryArea($country_area) {
switch ($country_area) {
case "CONTINENTAL_48":
case "FULL_50_STATES":
case "ALL":
$this->excluded_country_area = $country_area;
$this->excluded_restrictions = true;
break;
default:
$this->excluded_country_area = "";
break;
}
}
}
/**
* Used as a shipping option in which neither a carrier nor a ship-to
* address is specified
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_pickup} <pickup>
*/
class GooglePickUp {
var $price;
var $name;
var $type = "pickup";
/**
* @param string $name the name of this shipping option
* @param double $price the handling cost (if there is one)
*/
function GooglePickUp($name, $price) {
$this->price = $price;
$this->name = $name;
}
}
-146
View File
@@ -1,146 +0,0 @@
<?php
/*
* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Classes used to handle tax rules and tables
*/
/**
* Represents a tax rule
*
* @see GoogleDefaultTaxRule
* @see GoogleAlternateTaxRule
*
* @abstract
*/
class GoogleTaxRule {
var $tax_rate;
var $world_area = false;
var $country_codes_arr;
var $postal_patterns_arr;
var $state_areas_arr;
var $zip_patterns_arr;
var $country_area;
function GoogleTaxRule() {
}
function SetWorldArea($world_area = true) {
$this->world_area = $world_area;
}
function AddPostalArea($country_code, $postal_pattern = "") {
$this->country_codes_arr[] = $country_code;
$this->postal_patterns_arr[]= $postal_pattern;
}
function SetStateAreas($areas) {
if(is_array($areas))
$this->state_areas_arr = $areas;
else
$this->state_areas_arr = array($areas);
}
function SetZipPatterns($zips) {
if(is_array($zips))
$this->zip_patterns_arr = $zips;
else
$this->zip_patterns_arr = array($zips);
}
function SetCountryArea($country_area) {
switch ($country_area) {
case "CONTINENTAL_48":
case "FULL_50_STATES":
case "ALL":
$this->country_area = $country_area;
break;
default:
$this->country_area = "";
break;
}
}
}
/**
* Represents a default tax rule
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_default-tax-rule <default-tax-rule>}
*/
class GoogleDefaultTaxRule extends GoogleTaxRule {
var $shipping_taxed = false;
function GoogleDefaultTaxRule($tax_rate, $shipping_taxed = "false") {
$this->tax_rate = $tax_rate;
$this->shipping_taxed= $shipping_taxed;
$this->country_codes_arr = array();
$this->postal_patterns_arr = array();
$this->state_areas_arr = array();
$this->zip_patterns_arr = array();
}
}
/**
* Represents an alternate tax rule
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_alternate-tax-rule <alternate-tax-rule>}
*/
class GoogleAlternateTaxRule extends GoogleTaxRule {
function GoogleAlternateTaxRule($tax_rate) {
$this->tax_rate = $tax_rate;
$this->country_codes_arr = array();
$this->postal_patterns_arr = array();
$this->state_areas_arr = array();
$this->zip_patterns_arr = array();
}
}
/**
* Represents an alternate tax table
*
* GC tag: {@link http://code.google.com/apis/checkout/developer/index.html#tag_alternate-tax-table <alternate-tax-table>}
*/
class GoogleAlternateTaxTable {
var $name;
var $tax_rules_arr;
var $standalone;
function GoogleAlternateTaxTable($name = "", $standalone = "false") {
if($name != "") {
$this->name = $name;
$this->tax_rules_arr = array();
$this->standalone = $standalone;
}
}
function AddAlternateTaxRules($rules) {
$this->tax_rules_arr[] = $rules;
}
}
@@ -1,94 +0,0 @@
<?php
/*
Copyright (C) 2006 Google Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* Classes used to generate XML data
* Based on sample code available at http://simon.incutio.com/code/php/XmlWriter.class.php.txt
*/
/**
* Generates xml data
*/
class gc_XmlBuilder {
var $xml;
var $indent;
var $stack = array();
function gc_XmlBuilder($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
//Used when an element has sub-elements
// This function adds an open tag to the output
function Push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
//Used when an element has no subelements.
//Data within the open and close tags are provided with the
//contents variable
function Element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= '>'.htmlentities($content).'</'.$element.'>'."\n";
}
function EmptyElement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= " />\n";
}
//Used to close an open tag
function Pop($pop_element) {
$element = array_pop($this->stack);
$this->_indent();
if($element !== $pop_element)
die('XML Error: Tag Mismatch when trying to close "'. $pop_element. '"');
else
$this->xml .= "</$element>\n";
}
function GetXML() {
if(count($this->stack) != 0)
die ('XML Error: No matching closing tag found for " '. array_pop($this->stack). '"');
else
return $this->xml;
}
}
@@ -1,202 +0,0 @@
<?php
/**
* Classes used to parse xml data
*/
/*
Copyright (C) 2007 Google Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
For more info: http://code.google.com/p/google-checkout-php-sample-code/
Upgrades (05/23/2007) ropu:
Remove UpdateRecursive()
Support for empty tags (like <world-area/>)
Accept multiple options in a second parameter
*
**/
/* This uses SAX parser to convert XML data into PHP associative arrays
* When invoking the constructor with the input data, strip out the first XML line
*
* Member field Description:
* $params: This stores the XML data. The attributes and contents of XML tags
* can be accessed as follows
*
* <addresses>
* <anonymous-address id="123"> <test>data 1 </test>
* </anonymous-address>
* <anonymous-address id="456"> <test>data 2 </test>
* </anonymous-address>
* </addresses>
*
* print_r($this->params) will return
Array
(
[addresses] => Array
(
[anonymous-address] => Array
(
[0] => Array
(
[id] => 123
[test] => Array
(
[VALUE] => data 1
)
)
[1] => Array
(
[id] => 456
[test] => Array
(
[VALUE] => data 2
)
)
)
)
)
* gc_xmlparser returns an empty params array if it encounters
* any error during parsing
*/
// XML to Array
class gc_xmlparser {
var $params = array(); //Stores the object representation of XML data
var $root = NULL;
var $global_index = -1;
var $fold = false;
/* Constructor for the class
* Takes in XML data as input( do not include the <xml> tag
*/
function gc_xmlparser($input, $xmlParams=array(XML_OPTION_CASE_FOLDING => 0)) {
$xmlp = xml_parser_create();
foreach($xmlParams as $opt => $optVal) {
switch( $opt ) {
case XML_OPTION_CASE_FOLDING:
$this->fold = $optVal;
break;
default:
break;
}
xml_parser_set_option($xmlp, $opt, $optVal);
}
if(xml_parse_into_struct($xmlp, $input, $vals, $index)) {
$this->root = $this->_foldCase($vals[0]['tag']);
$this->params = $this->xml2ary($vals);
}
xml_parser_free($xmlp);
}
function _foldCase($arg) {
return( $this->fold ? strtoupper($arg) : $arg);
}
/*
* Credits for the structure of this function
* http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html
*
* Adapted by Ropu - 05/23/2007
*
*/
function xml2ary($vals) {
$mnary=array();
$ary=&$mnary;
foreach ($vals as $r) {
$t=$r['tag'];
if ($r['type']=='open') {
if (isset($ary[$t]) && !empty($ary[$t])) {
if (isset($ary[$t][0])){
$ary[$t][]=array();
}
else {
$ary[$t]=array($ary[$t], array());
}
$cv=&$ary[$t][count($ary[$t])-1];
}
else {
$cv=&$ary[$t];
}
$cv=array();
if (isset($r['attributes'])) {
foreach ($r['attributes'] as $k=>$v) {
$cv[$k]=$v;
}
}
$cv['_p']=&$ary;
$ary=&$cv;
} else if ($r['type']=='complete') {
if (isset($ary[$t]) && !empty($ary[$t])) { // same as open
if (isset($ary[$t][0])) {
$ary[$t][]=array();
}
else {
$ary[$t]=array($ary[$t], array());
}
$cv=&$ary[$t][count($ary[$t])-1];
}
else {
$cv=&$ary[$t];
}
if (isset($r['attributes'])) {
foreach ($r['attributes'] as $k=>$v) {
$cv[$k]=$v;
}
}
$cv['VALUE'] = (isset($r['value']) ? $r['value'] : '');
} elseif ($r['type']=='close') {
$ary=&$ary['_p'];
}
}
$this->_del_p($mnary);
return $mnary;
}
// _Internal: Remove recursion in result array
function _del_p(&$ary) {
foreach ($ary as $k=>$v) {
if ($k==='_p') {
unset($ary[$k]);
}
else if(is_array($ary[$k])) {
$this->_del_p($ary[$k]);
}
}
}
/* Returns the root of the XML data */
function GetRoot() {
return $this->root;
}
/* Returns the array representing the XML data */
function GetData() {
return $this->params;
}
}