Retrieving Localized Store Pricing

Overview

Allows localized prices to be retrieved for products in your store, using a server side language such as PHP.  The prices are based on the user's IP address information, or optionally a specific country.  This will only work on non-USD currency values which are explicitly defined on the product, and will not return any estimated conversions to other currencies.

Full Example URL

http://sites.fastspring.com/storename/api/price?product_1_path=/myproductpath&user_remote_addr=x&user_x_forwarded_for=y&user_accept_language=z

Product Parameters

product_1_path = /uniqueStoreProductPath such as /myproductpath

Optionally specify a product_2_path, product_3_path, etc, to retrieve price information for multiple products with a single call.

Optionally specify a product_1_quantity=X, to retrieve a unit price for a specific quantity.  This is only applicable if your product's pricing uses volume / quantity based pricing.

Optional Parameters

coupon = Coupon code to use when determining pricing information.  If a coupon activates a discount, then the discounted price is returned.  This is not implemented for subscriptions.

source = Link source key / identifier to use when determining pricing information.

Rate Limiting

When accessing information for multiple products it is important to use product_2_path, product_3_path, etc, as mentioned in the "Product Parameters" section.  This combines all of the product requests into a single API call for a more efficient operation, and ensures that your rate of access is not limited.  

Location Parameters

The following 3 parameters in the example identify where the user is and what their preferred language is.  They must be filled in from the particular language environment, as every language gets these values differently:

user_remote_addr = IP address from user's request

user_x_forwarded_for = "X-Forwarded-For" HTTP header from user's request

user_accept_language = "Accept-Language" HTTP header from user's request

For testing, or to explicitly define user location information, you may send:

user_country = ISO country code (uppercase)

user_language = ISO language code (lowercase)

However for most cases it is recommended you send user_remote_addr, user_x_forwarded_for, and user_accept_language to take advantage of auto-detection.

Output

The resulting output from the server call is a plain text file.  Example:

user_country=NL
user_language=en
user_currency=EUR
product_1_path=/myproductpath
product_1_quantity=1
product_1_unit_value=29.95
product_1_unit_currency=EUR
product_1_unit_display=€29.95
product_1_unit_html=€29.95
product_1_unit_vat_display=€34.47
product_1_unit_vat_html=€34.47
product_1_unit_vat_value=34.47

It is recommended that in the result the value in the line named "product_X_unit_html" be used to display the price to the user.  The value in this line automatically takes into account and emits special HTML characters such as €

PHP Example

<?php 	
  // define FastSpring paths
  $store_path = "storename/";
  $product_path = "/myproductpath";
		
  // get arguments from user
  $my_user_remote_addr = $_SERVER["REMOTE_ADDR"];
  $my_user_x_forwarded_for = $_SERVER["HTTP_X_FORWARDED_FOR"];
  $my_user_accept_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
		
  // build the URI
  $request_uri =  "http://sites.fastspring.com/" . $store_path . "api/price?" . "product_1_path=" . $product_path . "&user_remote_addr=" .$my_user_remote_addr ."&user_x_forwarded_for=" . $my_user_x_forwarded_for . "&user_accept_language=" . $my_user_accept_language;
		
  // get the response from FastSpring
  $response = file_get_contents($request_uri);
		
  // get the displayable html value of the price
  $unit_value_flag = "product_1_unit_html=";
  $unit_value_arg_start = (strpos($response, $unit_value_flag) + strlen($unit_value_flag)); // string start
  $unit_value_arg_end = strpos($response, "\n", $unit_value_arg_start); // string end
  $unit_value_extract = substr($response, $unit_value_arg_start, ($unit_value_arg_end - $unit_value_arg_start));
		
  echo $unit_value_extract; /* print the price where needed in the resulting page */		
?>
Have more questions? Submit a request

Comments

Powered by Zendesk