<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Design &#38; Development Talk &#187; Paypal</title>
	<atom:link href="http://www.web-design-talk.co.uk/category/paypal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-design-talk.co.uk</link>
	<description>Web Design &#38; Development Blog</description>
	<lastBuildDate>Thu, 29 Dec 2011 15:34:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Storing Ecommerce Order Information Correctly</title>
		<link>http://www.web-design-talk.co.uk/323/storing-ecommerce-order-details/</link>
		<comments>http://www.web-design-talk.co.uk/323/storing-ecommerce-order-details/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 19:23:28 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Paypal]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=323</guid>
		<description><![CDATA[Yesterday I was doing a tiny bit of web realted freelancing for a friend &#8211; simply involving doing a bulk, conditional update of his entire stock for his ecommerce website. The site itself was simple in design and used PayPal with a sprinkle of IPN. So, after a bit of MySQL magic, I updated all [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was doing a tiny bit of web realted freelancing for a friend &#8211; simply involving doing a bulk, conditional update of his entire stock for his ecommerce website. The site itself was simple in design and used PayPal with a sprinkle of IPN. So, after a bit of MySQL magic, I updated all of his prices, for all ~700 products in one fell swoop &#8211; all good so far, easy money.</p>
<p>However, after an hour or so of emailing the store owner I got a very worried phone call. In short, the bulk price update to had caused all archived order invoices to become incorrect. Why &#8211; due to bad database design by the original developer, let me explain.</p>
<p><span id="more-323"></span>The <strong>web developer</strong> had stored the order as you would expect &#8211; an order header table, coupled with a order lines table (one record for each order item). All good so far. Where the previous web developer had fallen short is not storing the price at the time of the order, instead simply storing the product id within the order lines table and looking order details via the way of an <a title="Inner Join on Wikipedia" href="http://en.wikipedia.org/wiki/Join_%28SQL%29#Inner_join" target="_blank">INNER JOIN</a> &#8211; bad move unfortunately. Obviously, in any sort of product price update (as above) all of his historical order information would become null and void. The latter was especially bad in this case, as the store owner pretty much used the list of store orders as base for financial and year end reporting, as the business was pretty small (no Sage then). Explaining the latter to a none technical client is even harder, believe me <img src='http://www.web-design-talk.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To avoid such nightmares <em>never</em>, <em>ever </em>store such information in this manner &#8211; always store product details at the time of ordering. Storing products details at this stage will ensure that an order made in 2008 will be correct when viewed even 10 years later when prices will have been updated. So, in the order lines table, as an absolute minimum store the product name, price and any attributes that will affect price &#8211; meaning an INNER JOIN with the order header table is not required.</p>
<p>Depending upon your business rules and frequency by which your product information changes, you could also store the product at time of ording, within a product archive table &#8211; that stores basic product info. This way, there is the benefit of saving the description the customer saw at time of ordering.</p>
<p>What is descriobed above is basically bog standard when making any ecommerce solution, or even using something bigger like Opencart, but when it is not present, the amount of issues it causes is huge.</p>
<p>Luckily for me (and the store owner) I created a quick backup of the entire store&#8217;s database schema and data before making the bulk update, so was able to restore this for the time being. All I have to do now is amened the database design accordingly and alter the way the site stores order information.</p>
<p>So, never ever rely upon relational data, to view and store data that needs to be achived.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/323/storing-ecommerce-order-details/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Process Custom eCommerce data using Paypal IPN</title>
		<link>http://www.web-design-talk.co.uk/141/process-custom-ecommerce-data-using-paypal-ipn/</link>
		<comments>http://www.web-design-talk.co.uk/141/process-custom-ecommerce-data-using-paypal-ipn/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 21:52:08 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Paypal]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=141</guid>
		<description><![CDATA[More often than not it&#8217;s hard to visualise how you can send custom information to Paypal during checkout. The list of available hidden field variables initially seems very specific and restrictive at best. Granted, you can easily send over simple things such as your shipping amountm and tax rate. However, during order processing (done in [...]]]></description>
			<content:encoded><![CDATA[<p>More often than not it&#8217;s hard to visualise how you can send custom information to <a href="http://www.paypal.com/" target="_blank">Paypal</a> during checkout. The list of available <a title="IPN variable list" href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables" target="_blank">hidden field variables</a> initially seems very specific and restrictive at best. Granted, you can easily send over simple things such as your shipping amountm and tax rate. However, during order processing (done in you IPN script that Paypal sends the transaction&#8217;s IPN post data to) you often want to record more information when creating and storingn order information.</p>
<p>For example, let&#8217;s say the user can enter a specific coupon code during checkout. You would want to make sure the Paypal transaction has been successful before making the voucher as used, to do this you would need to know what code was entered during checkout. In the following simple example we&#8217;ll use the &#8216;custom&#8217; field variable  &#8211; this is an optional field, whereby the the data is never presented to the shopper and can be 256 character long. Whatever is placed in this field before clicking your checkout button will be invisibly sent ot Paypal and posted back to your IPN script (assuming you have youre &#8216;rm&#8217; or return method set to 2, or &#8216;POST&#8217;). The HTML for the hidden field is very simple:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;input type=&quot;hidden&quot; name=&quot;custom&quot; value=&quot;YOUR CUSTOM INFORMATION HERE&quot;&gt;
</pre>
<p>Now, let&#8217;s say when you&#8217;re recording all the order information you weant to record the exact coupon code, delivery method id, the method by which the customer found your site (E.g. another id) and referrer id number. For convenience and for the sake of the example, I&#8217;ll assume you&#8217;ve done all the necessary processing to get your four pieces of information. The code to create our hidden field data is as follows:</p>
<pre class="brush: php; title: ; notranslate">
/* ...logic to get below variables here! */

$shipping_method_id = '33';
$coupon_code = '45895';
$found_out_method = '9';
$referrer_id = '200';

$custom_info =
                       array(
			'shipping_method_id' =&gt; 33,
			'coupon_code'=&gt; 45895 ,
			'found_out_method' =&gt; 20 ,
			'referrer_id' =&gt; 9
			);

/* Initiase field data and looping variable */
$field_data = NULL;
$i = 0;

/* Loop through info array to build data string */
foreach ($custom_info as $key =&gt; $field) {

	$field_data .= $field;
	$i++;

	if ( $i !== count($custom_info)) {
	      $field_data .= '-';
	}

}

/* create the hidden field
generated HTML is &lt;input type=&quot;hidden&quot; name=&quot;custom&quot; value=&quot;33-45895-20-9&quot;&gt; */
echo '&lt;input type=&quot;hidden&quot; name=&quot;custom&quot; value=&quot;'.$field_data.'&quot;&gt;' . &quot;\n&quot;;
</pre>
<p>Printing the value of $field data will give you the string &#8217;33-45895-20-9&#8242;. This translates to shipping method id 33, coupon code 45895, found out id 20 and referrer id 9. The dash symbol has been used to delimit values for convenience, as we need to split this string up later on.</p>
<p>To process these variables in your IPN script (see the <a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt" target="_blank">Paypal PHP sample script</a>) you simply use PHP&#8217;s explode method to split the data into an array: </p>
<pre class="brush: php; title: ; notranslate">
/* $_POST['custom'] contains the custom information we initially sent to Paypal */
$data = explode('-',$_POST['custom']);

/* Convert $data array into variables for further processing */
$shipping_method_id = $data[0];
$coupon_code = $data[1];
$found_out_method = $data[2];
$referrer_id = $data[3];
</pre>
<p>So you&#8217;ve now posted a string of custom information to Paypal and got this custom data back via IPN during the transaction processing. Now you have assigned each piece iof the array to a variable, you can easily continue to create your order header and save it to a database. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/141/process-custom-ecommerce-data-using-paypal-ipn/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

