When Zencart uses Paypal for payment, there will be missed orders, that is, Paypal has received the customer's payment, but there is no order from the customer in the website backend. The main reason for missing orders in Paypal is that when the customer jumps to the Paypal website and completes the payment, he directly closes the window, or the network is unstable and does not jump to the website normally.
There are several solutions to solve the problem of missed orders in Paypal:
1. Turn on the Detailed Line Items in Cart option.
Principle: Open the Detailed Line Items in Cart option in the zencart backend Module --> Payment --> PayPal Website Payments Standard - IPN. This option will transfer all your order item information to PayPal. When the customer's payment is successful but the backend fails to successfully generate the order, you can also see which items the customer purchased through the PayPal account transaction information.
2. Use the Paypal Sessions Viewer plug-in to retrieve orders missed by Paypal.
Principle: If the items in the zencart shopping cart are paid through paypal, all records of the payment will be saved in the paypal_session table. If the payment is successful and the order is jumped from the paypal website to the shopping website and an order is generated, the zencart system will Automatically delete this paypal_session record. If you do not successfully jump to the shopping website and do not successfully generate an order, then this payment record data will always be saved in the database. When you use the Paypal Session Viewer plug-in, you can view all the data of this record. , including customer information, shopping time, and product information. If you are sure that payment has been received, you can transfer this paypal_session information to the order and generate an order.
Plug-in download address: http://www.zen-cart.cn/english-version-modules/admin-tools/paypal-sessions-viewer
3. Modify the payment process, first place the order and then pay.
Principle: Anyone who has used zen-cart knows that the ordering steps in zen-cart are as follows (the expressions in [] are not necessary):
1. Shopping cart
2 . [delivery method]
3. payment method
4. order confirmation (confirmation)
5. [third-party website payment]
6. order processing (checkout process)—— This step is important, because the information in the shopping cart will be written into the order here
7. Order successful (checkout success)
There is no problem with this process under normal circumstances. However, in the process from step 5 to step 6, the user may think that the payment is successful and close the web page directly, or the user may not be able to jump to the checkout_process page normally due to network reasons. The consequences of this are very serious, because the order Cannot be created normally. Based on the above analysis, we hope to change the process slightly, that is, the order has been created before payment, so that even if the payment cannot be jumped back from the third-party payment website, we will not have the user pay successfully but there will be no error in the background. Order status.
I followed Mr. Dongguo’s tutorial on modifying the zen-cart ordering and payment process to prevent missed orders. Because this tutorial is relatively old and not very comprehensive, I modified it based on my actual needs. He made it more perfect and detailed.
The modified blueprint is basically as follows:
1. After confirming the order on the checkour_confirmation page, you will directly proccess and enter the account_history_info page, where you can enter the payment page. As shown in the picture below:
2. If the customer fails to pay at that time, they can also enter their own backend to pay for historical orders. As shown in the picture below:
3. For unpaid orders, you can modify the price in the background. Just like Taobao, after taking a photo of the product, the store owner will modify the price for you before paying. As shown in the figure below:
Let’s formally modify the code. First, I list all the files to be modified:
1. includes/classes/payment.php
2. includes/modules/payment/paypal. php
3. includes/classes/order.php
4. includes/modules/pages/checkout_process/header_php.php
5. includes/modules/pages/account_history_info/header_php.php
6. includes/templates/ Your template directory/templates/tpl_account_history_info_default.php
7. includes/templates/Your template directory/templates/tpl_account_history_default.php
8. ipn_main_handler.php
9. admin (backend directory)/orders.php
Because you create an order first and then pay, the payment step will be one more step than before. In order to simplify the payment process, I installed the Fast And Easy Checkout For Zencart (fast payment) plug-in. Before installing this plug-in, you need to install another plug-in Css Js Loader For Zencart, which is a dependent plug-in of the fast payment plug-in. There is no causal relationship between quick payment and payment after placing an order, so you can ignore it if you don’t want to install it.
Follow the steps to modify the files listed above:
1. First we need to transform the existing payment module. You need to add a field paynow_action_url to the payment method class to represent the page url for payment. In addition, you need to add a function, paynow_button($order_id), to obtain the parameter hidden field code of the payment form.
To add the paynow_action_url variable, please add the following code at the end of the constructor of the payment class:
<span>if</span> ( (zen_not_null(<span>$module</span>)) && (<span>in_array</span>(<span>$module</span>.'.php', <span>$this</span>->modules)) && (<span>isset</span>(<span>$GLOBALS</span>[<span>$module</span>]-><span>paynow_action_url)) ) { </span><span>$this</span>->paynow_action_url = <span>$GLOBALS</span>[<span>$module</span>]-><span>paynow_action_url; }</span>
To add the paynow_button ($order_id) function, please add the following code after the last function of the payment class :
<span>function</span> paynow_button(<span>$order_id</span><span>){ </span><span>if</span> (<span>is_array</span>(<span>$this</span>-><span>modules)) { </span><span>if</span> (<span>is_object</span>(<span>$GLOBALS</span>[<span>$this</span>-><span>selected_module])) { </span><span>return</span><span>$GLOBALS</span>[<span>$this</span>->selected_module]->paynow_button(<span>$order_id</span><span>); } } }</span>
2. Take the paypal payment method as an example to explain how to implement it. Modify the paypal.php file directly here, be sure to back up this file. The code is as shown below. You can see that the specification of form_action_url is removed here and paynow_action_url is given. Because we hope that the user will directly enter the checkout_process after clicking "Confirm Order", so if form_action_url is not specified, then the form to confirm the order will be It is submitted directly to the checkout_process page, and paynow_action_url is the value of the previous form_action_url. The implementation of the paynow_button function is also very simple. Here we just cut the contents of the original process_button() function, but instead of using the global $order variable, we use $order = new order($order_id) to re- An object constructed in preparation for displaying the pay now button in historical orders. The modified file of paypal.php is as follows:
<span> 1</span> <?<span>php </span><span> 2</span><span>/*</span><span>* </span><span> 3</span><span> * paypal.php payment module class for PayPal Website Payments Standard (IPN) method </span><span> 4</span><span> * </span><span> 5</span><span> * @package paymentMethod </span><span> 6</span><span> * @copyright Copyright 2003-2010 Zen Cart Development Team </span><span> 7</span><span> * @copyright Portions Copyright 2003 osCommerce </span><span> 8</span><span> * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 </span><span> 9</span><span> * @version $Id: paypal.php 15735 2010-03-29 07:13:53Z drbyte $ </span><span> 10</span><span>*/</span><span> 11</span><span> 12</span><span>define</span>('MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE', 'true'<span>); </span><span> 13</span><span> 14</span><span>/*</span><span>* </span><span> 15</span><span> * ensure dependencies are loaded </span><span> 16</span><span>*/</span><span> 17</span><span>include_once</span>((IS_ADMIN_FLAG === <span>true</span> ? DIR_FS_CATALOG_MODULES : DIR_WS_MODULES) . 'payment/paypal/paypal_functions.php'<span>); </span><span> 18</span><span> 19</span><span>/*</span><span>* </span><span> 20</span><span> * paypal.php payment module class for PayPal Website Payments Standard (IPN) method </span><span> 21</span><span> * </span><span> 22</span><span>*/</span><span> 23</span><span>class</span> paypal <span>extends</span><span> base { </span><span> 24</span><span>/*</span><span>* </span><span> 25</span><span> * string representing the payment method </span><span> 26</span><span> * </span><span> 27</span><span> * @var string </span><span> 28</span><span>*/</span><span> 29</span><span>var</span><span>$code</span><span>; </span><span> 30</span><span>/*</span><span>* </span><span> 31</span><span> * $title is the displayed name for this payment method </span><span> 32</span><span> * </span><span> 33</span><span> * @var string </span><span> 34</span><span>*/</span><span> 35</span><span>var</span><span>$title</span><span>; </span><span> 36</span><span>/*</span><span>* </span><span> 37</span><span> * $description is a soft name for this payment method </span><span> 38</span><span> * </span><span> 39</span><span> * @var string </span><span> 40</span><span>*/</span><span> 41</span><span>var</span><span>$description</span><span>; </span><span> 42</span><span>/*</span><span>* </span><span> 43</span><span> * $enabled determines whether this module shows or not... in catalog. </span><span> 44</span><span> * </span><span> 45</span><span> * @var boolean </span><span> 46</span><span>*/</span><span> 47</span><span>var</span><span>$enabled</span><span>; </span><span> 48</span><span>/*</span><span>* </span><span> 49</span><span> * constructor </span><span> 50</span><span> * </span><span> 51</span><span> * @param int $paypal_ipn_id </span><span> 52</span><span> * @return paypal </span><span> 53</span><span>*/</span><span> 54</span><span>function</span> paypal(<span>$paypal_ipn_id</span> = ''<span>) { </span><span> 55</span><span>global</span><span>$order</span>, <span>$messageStack</span><span>; </span><span> 56</span><span>$this</span>->code = 'paypal'<span>; </span><span> 57</span><span>$this</span>->codeVersion = '1.3.9'<span>; </span><span> 58</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span><span>) { </span><span> 59</span><span>$this</span>->title = MODULE_PAYMENT_PAYPAL_TEXT_ADMIN_TITLE; <span>//</span><span> Payment Module title in Admin</span><span> 60</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span> && <span>defined</span>('MODULE_PAYMENT_PAYPAL_IPN_DEBUG') && MODULE_PAYMENT_PAYPAL_IPN_DEBUG != 'Off') <span>$this</span>->title .= '<span> (debug mode active)</span>'<span>; </span><span> 61</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span> && MODULE_PAYMENT_PAYPAL_TESTING == 'Test') <span>$this</span>->title .= '<span> (dev/test mode active)</span>'<span>; </span><span> 62</span> } <span>else</span><span> { </span><span> 63</span><span>$this</span>->title = MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_TITLE; <span>//</span><span> Payment Module title in Catalog</span><span> 64</span><span> }</span><span> 65</span><span>$this</span>->description =<span> MODULE_PAYMENT_PAYPAL_TEXT_DESCRIPTION; </span><span> 66</span><span>$this</span>->sort_order =<span> MODULE_PAYMENT_PAYPAL_SORT_ORDER; </span><span> 67</span><span>$this</span>->enabled = ((MODULE_PAYMENT_PAYPAL_STATUS == 'True') ? <span>true</span> : <span>false</span><span>); </span><span> 68</span><span>if</span> ((int)MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID > 0<span>) { </span><span> 69</span><span>$this</span>->order_status =<span> MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; </span><span> 70</span><span> } </span><span> 71</span><span>if</span> (<span>is_object</span>(<span>$order</span>)) <span>$this</span>-><span>update_status(); </span><span> 72</span><span>$this</span>->paynow_action_url = 'https://' .<span> MODULE_PAYMENT_PAYPAL_HANDLER; </span><span> 73</span><span> 74</span><span>if</span> (PROJECT_VERSION_MAJOR != '1' && <span>substr</span>(PROJECT_VERSION_MINOR, 0, 3) != '3.9') <span>$this</span>->enabled = <span>false</span><span>; </span><span> 75</span><span> 76</span><span>//</span><span> verify table structure</span><span> 77</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span>) <span>$this</span>-><span>tableCheckup(); </span><span> 78</span><span> } </span><span> 79</span><span>/*</span><span>* </span><span> 80</span><span> * calculate zone matches and flag settings to determine whether this module should display to customers or not </span><span> 81</span><span> * </span><span> 82</span><span>*/</span><span> 83</span><span>function</span><span> update_status() { </span><span> 84</span><span>global</span><span>$order</span>, <span>$db</span><span>; </span><span> 85</span><span> 86</span><span>if</span> ( (<span>$this</span>->enabled == <span>true</span>) && ((int)MODULE_PAYMENT_PAYPAL_ZONE > 0<span>) ) { </span><span> 87</span><span>$check_flag</span> = <span>false</span><span>; </span><span> 88</span><span>$check_query</span> = <span>$db</span>->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_ZONE . "' and zone_country_id = '" . <span>$order</span>->billing['country']['id'] . "' order by zone_id"<span>); </span><span> 89</span><span>while</span> (!<span>$check_query</span>-><span>EOF) { </span><span> 90</span><span>if</span> (<span>$check_query</span>->fields['zone_id'] < 1<span>) { </span><span> 91</span><span>$check_flag</span> = <span>true</span><span>; </span><span> 92</span><span>break</span><span>; </span><span> 93</span> } <span>elseif</span> (<span>$check_query</span>->fields['zone_id'] == <span>$order</span>->billing['zone_id'<span>]) { </span><span> 94</span><span>$check_flag</span> = <span>true</span><span>; </span><span> 95</span><span>break</span><span>; </span><span> 96</span><span> } </span><span> 97</span><span>$check_query</span>-><span>MoveNext(); </span><span> 98</span><span> } </span><span> 99</span><span>100</span><span>if</span> (<span>$check_flag</span> == <span>false</span><span>) { </span><span>101</span><span>$this</span>->enabled = <span>false</span><span>; </span><span>102</span><span> } </span><span>103</span><span> } </span><span>104</span><span> } </span><span>105</span><span>/*</span><span>* </span><span>106</span><span> * JS validation which does error-checking of data-entry if this module is selected for use </span><span>107</span><span> * (Number, Owner, and CVV Lengths) </span><span>108</span><span> * </span><span>109</span><span> * @return string </span><span>110</span><span>*/</span><span>111</span><span>function</span><span> javascript_validation() { </span><span>112</span><span>return</span><span>false</span><span>; </span><span>113</span><span> } </span><span>114</span><span>/*</span><span>* </span><span>115</span><span> * Displays payment method name along with Credit Card Information Submission Fields (if any) on the Checkout Payment Page </span><span>116</span><span> * </span><span>117</span><span> * @return array </span><span>118</span><span>*/</span><span>119</span><span>function</span><span> selection() { </span><span>120</span><span>return</span><span>array</span>('id' => <span>$this</span>->code, <span>121</span> 'module' => MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_LOGO, <span>122</span> 'icon' =><span> MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_LOGO </span><span>123</span><span> ); </span><span>124</span><span> }</span><span>125</span><span>/*</span><span>* </span><span>126</span><span> * Normally evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date </span><span>127</span><span> * Since paypal module is not collecting info, it simply skips this step. </span><span>128</span><span> * </span><span>129</span><span> * @return boolean </span><span>130</span><span>*/</span><span>131</span><span>function</span><span> pre_confirmation_check() { </span><span>132</span><span>return</span><span>false</span><span>; </span><span>133</span><span> } </span><span>134</span><span>/*</span><span>* </span><span>135</span><span> * Display Credit Card Information on the Checkout Confirmation Page </span><span>136</span><span> * Since none is collected for paypal before forwarding to paypal site, this is skipped </span><span>137</span><span> * </span><span>138</span><span> * @return boolean </span><span>139</span><span>*/</span><span>140</span><span>function</span><span> confirmation() { </span><span>141</span><span>return</span><span>false</span><span>; </span><span>142</span><span> } </span><span>143</span><span>/*</span><span>* </span><span>144</span><span> * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen. </span><span>145</span><span> * This sends the data to the payment gateway for processing. </span><span>146</span><span> * (These are hidden fields on the checkout confirmation page) </span><span>147</span><span> * </span><span>148</span><span> * @return string </span><span>149</span><span>*/</span><span>150</span><span>function</span><span> process_button() { </span><span>151</span><span>return</span><span>false</span><span>; </span><span>152</span><span> } </span><span>153</span><span>/*</span><span>* </span><span>154</span><span> * Determine the language to use when visiting the PayPal site </span><span>155</span><span>*/</span><span>156</span><span>function</span><span> getLanguageCode() { </span><span>157</span><span>global</span><span>$order</span><span>; </span><span>158</span><span>$lang_code</span> = ''<span>; </span><span>159</span><span>$orderISO</span> = zen_get_countries(<span>$order</span>->customer['country']['id'], <span>true</span><span>); </span><span>160</span><span>$storeISO</span> = zen_get_countries(STORE_COUNTRY, <span>true</span><span>); </span><span>161</span><span>if</span> (<span>in_array</span>(<span>strtoupper</span>(<span>$orderISO</span>['countries_iso_code_2']), <span>array</span>('US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'<span>))) { </span><span>162</span><span>$lang_code</span> = <span>strtoupper</span>(<span>$orderISO</span>['countries_iso_code_2'<span>]); </span><span>163</span> } <span>elseif</span> (<span>in_array</span>(<span>strtoupper</span>(<span>$storeISO</span>['countries_iso_code_2']), <span>array</span>('US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'<span>))) { </span><span>164</span><span>$lang_code</span> = <span>strtoupper</span>(<span>$storeISO</span>['countries_iso_code_2'<span>]); </span><span>165</span> } <span>elseif</span> (<span>in_array</span>(<span>strtoupper</span>(<span>$_SESSION</span>['languages_code']), <span>array</span>('EN', 'US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'<span>))) { </span><span>166</span><span>$lang_code</span> = <span>$_SESSION</span>['languages_code'<span>]; </span><span>167</span><span>if</span> (<span>strtoupper</span>(<span>$lang_code</span>) == 'EN') <span>$lang_code</span> = 'US'<span>; </span><span>168</span><span> } </span><span>169</span><span>//</span><span>return $orderISO['countries_iso_code_2'];</span><span>170</span><span>return</span><span>strtoupper</span>(<span>$lang_code</span><span>); </span><span>171</span><span> } </span><span>172</span><span>/*</span><span>* </span><span>173</span><span> * Store transaction info to the order and process any results that come back from the payment gateway </span><span>174</span><span>*/</span><span>175</span><span>function</span><span> before_process() { </span><span>176</span><span>return</span><span>false</span><span>; </span><span>177</span><span> } </span><span>178</span><span>/*</span><span>* </span><span>179</span><span> * Checks referrer </span><span>180</span><span> * </span><span>181</span><span> * @param string $zf_domain </span><span>182</span><span> * @return boolean </span><span>183</span><span>*/</span><span>184</span><span>function</span> check_referrer(<span>$zf_domain</span><span>) { </span><span>185</span><span>return</span><span>true</span><span>; </span><span>186</span><span> }</span><span>187</span><span>/*</span><span>* </span><span>188</span><span> * Build admin-page components </span><span>189</span><span> * </span><span>190</span><span> * @param int $zf_order_id </span><span>191</span><span> * @return string </span><span>192</span><span>*/</span><span>193</span><span>function</span> admin_notification(<span>$zf_order_id</span><span>) { </span><span>194</span><span>global</span><span>$db</span><span>; </span><span>195</span><span>$output</span> = ''<span>; </span><span>196</span><span>$sql</span> = "select * from " . TABLE_PAYPAL . " where order_id = '" . (int)<span>$zf_order_id</span> . "' order by paypal_ipn_id DESC LIMIT 1"<span>; </span><span>197</span><span>$ipn</span> = <span>$db</span>->Execute(<span>$sql</span><span>); </span><span>198</span><span>if</span> (<span>$ipn</span>->RecordCount() > 0 && <span>file_exists</span>(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_admin_notification.php')) <span>require</span>(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_admin_notification.php'<span>); </span><span>199</span><span>return</span><span>$output</span><span>; </span><span>200</span><span> } </span><span>201</span><span>/*</span><span>* </span><span>202</span><span> * Post-processing activities </span><span>203</span><span> * When the order returns from the processor, if PDT was successful, this stores the results in order-status-history and logs data for subsequent reference </span><span>204</span><span> * </span><span>205</span><span> * @return boolean </span><span>206</span><span>*/</span><span>207</span><span>function</span><span> after_process() { </span><span>208</span><span>return</span><span>false</span><span>; </span><span>209</span><span> } </span><span>210</span><span>/*</span><span>* </span><span>211</span><span> * Used to display error message details </span><span>212</span><span> * </span><span>213</span><span> * @return boolean </span><span>214</span><span>*/</span><span>215</span><span>function</span><span> output_error() { </span><span>216</span><span>return</span><span>false</span><span>; </span><span>217</span><span> } </span><span>218</span><span>/*</span><span>* </span><span>219</span><span> * Check to see whether module is installed </span><span>220</span><span> * </span><span>221</span><span> * @return boolean </span><span>222</span><span>*/</span><span>223</span><span>function</span><span> check() { </span><span>224</span><span>global</span><span>$db</span><span>; </span><span>225</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span><span>) { </span><span>226</span><span>global</span><span>$sniffer</span><span>; </span><span>227</span><span>if</span> (<span>$sniffer</span>->field_exists(TABLE_PAYPAL, 'zen_order_id')) <span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE COLUMN zen_order_id order_id int(11) NOT NULL default '0'"<span>); </span><span>228</span><span> } </span><span>229</span><span>if</span> (!<span>isset</span>(<span>$this</span>-><span>_check)) { </span><span>230</span><span>$check_query</span> = <span>$db</span>->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'"<span>); </span><span>231</span><span>$this</span>->_check = <span>$check_query</span>-><span>RecordCount(); </span><span>232</span><span> } </span><span>233</span><span>return</span><span>$this</span>-><span>_check; </span><span>234</span><span> } </span><span>235</span><span>/*</span><span>* </span><span>236</span><span> * Install the payment module and its configuration settings </span><span>237</span><span> * </span><span>238</span><span>*/</span><span>239</span><span>function</span><span> install() { </span><span>240</span><span>global</span><span>$db</span>, <span>$messageStack</span><span>; </span><span>241</span><span>if</span> (<span>defined</span>('MODULE_PAYMENT_PAYPAL_STATUS'<span>)) { </span><span>242</span><span>$messageStack</span>->add_session('PayPal Website Payments Standard module already installed.', 'error'<span>); </span><span>243</span> zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypal', 'NONSSL'<span>)); </span><span>244</span><span>return</span> 'failed'<span>; </span><span>245</span><span> } </span><span>246</span><span>if</span> (<span>defined</span>('MODULE_PAYMENT_PAYPALWPP_STATUS'<span>)) { </span><span>247</span><span>$messageStack</span>->add_session('NOTE: PayPal Express Checkout module already installed. You don't need Standard if you have Express installed.', 'error'<span>); </span><span>248</span> zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'<span>)); </span><span>249</span><span>return</span> 'failed'<span>; </span><span>250</span><span> }</span><span>251</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable PayPal Module', 'MODULE_PAYMENT_PAYPAL_STATUS', 'True', 'Do you want to accept PayPal payments?', '6', '0', 'zen_cfg_select_option(array('True', 'False'), ', now())"<span>); </span><span>252</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Business ID', 'MODULE_PAYMENT_PAYPAL_BUSINESS_ID','".STORE_OWNER_EMAIL_ADDRESS."', 'Primary email address for your PayPal account.<br />NOTE: This must match <strong>EXACTLY </strong>the primary email address on your PayPal account settings. It <strong>IS case-sensitive</strong>, so please check your PayPal profile preferences at paypal.com and be sure to enter the EXACT same primary email address here.', '6', '2', now())"<span>); </span><span>253</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_PAYPAL_CURRENCY', 'Selected Currency', 'Which currency should the order be sent to PayPal as? <br />NOTE: if an unsupported currency is sent to PayPal, it will be auto-converted to USD.', '6', '3', 'zen_cfg_select_option(array('Selected Currency', 'Only USD', 'Only AUD', 'Only CAD', 'Only EUR', 'Only GBP', 'Only CHF', 'Only CZK', 'Only DKK', 'Only HKD', 'Only HUF', 'Only JPY', 'Only NOK', 'Only NZD', 'Only PLN', 'Only SEK', 'Only SGD', 'Only THB', 'Only MXN', 'Only ILS', 'Only PHP', 'Only TWD', 'Only BRL', 'Only MYR'), ', now())"<span>); </span><span>254</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_PAYPAL_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '4', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())"<span>); </span><span>255</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Pending Notification Status', 'MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID', '" . DEFAULT_ORDERS_STATUS_ID . "', 'Set the status of orders made with this payment module that are not yet completed to this value<br />('Pending' recommended)', '6', '5', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"<span>); </span><span>256</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID', '2', 'Set the status of orders made with this payment module that have completed payment to this value<br />('Processing' recommended)', '6', '6', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"<span>); </span><span>257</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Refund Order Status', 'MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID', '1', 'Set the status of orders that have been refunded made with this payment module to this value<br />('Pending' recommended)', '6', '7', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"<span>); </span><span>258</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PAYPAL_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '8', now())"<span>); </span><span>259</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Address Override', 'MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE', '1', 'If set to 1, the customer shipping address selected in Zen Cart will override the customer PayPal-stored address book. The customer will see their address from Zen Cart, but will NOT be able to edit it at PayPal.<br />(An invalid address will be treated by PayPal as not-supplied, or override=0)<br />0=No Override<br />1=ZC address overrides PayPal address choices', '6', '18', 'zen_cfg_select_option(array('0','1'), ', now())"<span>); </span><span>260</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Address Requirements?', 'MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED', '2', 'The buyers shipping address. If set to 0 your customer will be prompted to include a shipping address. If set to 1 your customer will not be asked for a shipping address. If set to 2 your customer will be required to provide a shipping address.<br />0=Prompt<br />1=Not Asked<br />2=Required<br /><br /><strong>NOTE: If you allow your customers to enter their own shipping address, then MAKE SURE you PERSONALLY manually verify the PayPal confirmation details to verify the proper address when filling orders. When using Website Payments Standard (IPN), Zen Cart does not know if they choose an alternate shipping address at PayPal vs the one entered when placing an order.</strong>', '6', '20', 'zen_cfg_select_option(array('0','1','2'), ', now())"<span>); </span><span>261</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Detailed Line Items in Cart', 'MODULE_PAYMENT_PAYPAL_DETAILED_CART', 'No', 'Do you want to give line-item details to PayPal? If set to True, line-item details will be shared with PayPal if no discounts apply and if tax and shipping are simple. Otherwise an Aggregate cart summary will be sent.', '6', '22', 'zen_cfg_select_option(array('No','Yes'), ', now())"<span>); </span><span>262</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Page Style', 'MODULE_PAYMENT_PAYPAL_PAGE_STYLE', 'Primary', 'Sets the Custom Payment Page Style for payment pages. The value of page_style is the same as the Page Style Name you chose when adding or editing the page style. You can add and edit Custom Payment Page Styles from the Profile subtab of the My Account tab on the PayPal site. If you would like to always reference your Primary style, set this to "primary." If you would like to reference the default PayPal page style, set this to "paypal".', '6', '25', now())"<span>); </span><span>263</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Mode for PayPal web services<br /><br />Default:<br /><code>www.paypal.com/cgi-bin/webscr</code><br />or<br /><code>www.paypal.com/us/cgi-bin/webscr</code><br />or for the UK,<br /><code>www.paypal.com/uk/cgi-bin/webscr</code>', 'MODULE_PAYMENT_PAYPAL_HANDLER', 'www.paypal.com/cgi-bin/webscr', 'Choose the URL for PayPal live processing', '6', '73', '', now())"<span>); </span><span>264</span><span>//</span><span> sandbox: www.sandbox.paypal.com/cgi-bin/webscr</span><span>265</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('PDT Token (Payment Data Transfer)', 'MODULE_PAYMENT_PAYPAL_PDTTOKEN', '', 'Enter your PDT Token value here in order to activate transactions immediately after processing (if they pass validation).', '6', '25', now(), 'zen_cfg_password_display')"<span>); </span><span>266</span><span>//</span><span> Paypal testing options here</span><span>267</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_PAYMENT_PAYPAL_IPN_DEBUG', 'Off', 'Enable debug logging? <br />NOTE: This can REALLY clutter your email inbox!<br />Logging goes to the /includes/modules/payment/paypal/logs folder<br />Email goes to the store-owner address.<br />Email option NOT recommended.<br /><strong>Leave OFF for normal operation.</strong>', '6', '71', 'zen_cfg_select_option(array('Off','Log File','Log and Email'), ', now())"<span>); </span><span>268</span><span>$db</span>->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Debug Email Address', 'MODULE_PAYMENT_PAYPAL_DEBUG_EMAIL_ADDRESS','".STORE_OWNER_EMAIL_ADDRESS."', 'The email address to use for PayPal debugging', '6', '72', now())"<span>); </span><span>269</span><span>270</span><span>$this</span>->notify('NOTIFY_PAYMENT_PAYPAL_INSTALLED'<span>); </span><span>271</span><span> } </span><span>272</span><span>/*</span><span>* </span><span>273</span><span> * Remove the module and all its settings </span><span>274</span><span> * </span><span>275</span><span>*/</span><span>276</span><span>function</span><span> remove() { </span><span>277</span><span>global</span><span>$db</span><span>; </span><span>278</span><span>$db</span>->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE_PAYMENT_PAYPAL_%'"<span>); </span><span>279</span><span>$this</span>->notify('NOTIFY_PAYMENT_PAYPAL_UNINSTALLED'<span>); </span><span>280</span><span> } </span><span>281</span><span>/*</span><span>* </span><span>282</span><span> * Internal list of configuration keys used for configuration of the module </span><span>283</span><span> * </span><span>284</span><span> * @return array </span><span>285</span><span>*/</span><span>286</span><span>function</span><span> keys() { </span><span>287</span><span>$keys_list</span> = <span>array</span><span>( </span><span>288</span> 'MODULE_PAYMENT_PAYPAL_STATUS', <span>289</span> 'MODULE_PAYMENT_PAYPAL_BUSINESS_ID', <span>290</span> 'MODULE_PAYMENT_PAYPAL_PDTTOKEN', <span>291</span> 'MODULE_PAYMENT_PAYPAL_CURRENCY', <span>292</span> 'MODULE_PAYMENT_PAYPAL_ZONE', <span>293</span> 'MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID', <span>294</span> 'MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID', <span>295</span> 'MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID', <span>296</span> 'MODULE_PAYMENT_PAYPAL_SORT_ORDER', <span>297</span> 'MODULE_PAYMENT_PAYPAL_DETAILED_CART', <span>298</span> 'MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE' , <span>299</span> 'MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED' , <span>300</span> 'MODULE_PAYMENT_PAYPAL_PAGE_STYLE' , <span>301</span> 'MODULE_PAYMENT_PAYPAL_HANDLER', <span>302</span> 'MODULE_PAYMENT_PAYPAL_IPN_DEBUG', <span>303</span><span> ); </span><span>304</span><span>305</span><span>//</span><span> Paypal testing/debug options go here:</span><span>306</span><span>if</span> (IS_ADMIN_FLAG === <span>true</span><span>) { </span><span>307</span><span>if</span> (<span>isset</span>(<span>$_GET</span>['debug']) && <span>$_GET</span>['debug']=='on'<span>) { </span><span>308</span><span>$keys_list</span>[]='MODULE_PAYMENT_PAYPAL_DEBUG_EMAIL_ADDRESS'; <span>/*</span><span> this defaults to store-owner-email-address </span><span>*/</span><span>309</span><span> } </span><span>310</span><span> } </span><span>311</span><span>return</span><span>$keys_list</span><span>; </span><span>312</span><span> }</span><span>313</span><span>314</span><span>function</span> _getPDTresults(<span>$orderAmount</span>, <span>$my_currency</span>, <span>$pdtTX</span><span>) { </span><span>315</span><span>global</span><span>$db</span><span>; </span><span>316</span><span>$ipnData</span> = ipn_postback('PDT', <span>$pdtTX</span><span>); </span><span>317</span><span>$respdata</span> = <span>$ipnData</span>['info'<span>]; </span><span>318</span><span>319</span><span>//</span><span> parse the data</span><span>320</span><span>$lines</span> = <span>explode</span>("n", <span>$respdata</span><span>); </span><span>321</span><span>$this</span>->pdtData = <span>array</span><span>(); </span><span>322</span><span>for</span> (<span>$i</span>=1; <span>$i</span><<span>count</span>(<span>$lines</span>);<span>$i</span>++<span>){ </span><span>323</span><span>if</span> (!<span>strstr</span>(<span>$lines</span>[<span>$i</span>], "=")) <span>continue</span><span>; </span><span>324</span><span>list</span>(<span>$key</span>,<span>$val</span>) = <span>explode</span>("=", <span>$lines</span>[<span>$i</span><span>]); </span><span>325</span><span>$this</span>->pdtData[<span>urldecode</span>(<span>$key</span>)] = <span>urldecode</span>(<span>$val</span><span>); </span><span>326</span><span> } </span><span>327</span><span>328</span><span>if</span> (<span>$this</span>->pdtData['txn_id'] == '' || <span>$this</span>->pdtData['payment_status'] == ''<span>) { </span><span>329</span> ipn_debug_email('PDT Returned INVALID Data. Must wait for IPN to process instead. ' . "n" . <span>print_r</span>(<span>$this</span>->pdtData, <span>true</span><span>)); </span><span>330</span><span>return</span><span>FALSE</span><span>; </span><span>331</span> } <span>else</span><span> { </span><span>332</span> ipn_debug_email('PDT Returned Data ' . <span>print_r</span>(<span>$this</span>->pdtData, <span>true</span><span>)); </span><span>333</span><span> } </span><span>334</span><span>335</span><span>$_POST</span>['mc_gross'] = <span>$this</span>->pdtData['mc_gross'<span>]; </span><span>336</span><span>$_POST</span>['mc_currency'] = <span>$this</span>->pdtData['mc_currency'<span>]; </span><span>337</span><span>$_POST</span>['business'] = <span>$this</span>->pdtData['business'<span>]; </span><span>338</span><span>$_POST</span>['receiver_email'] = <span>$this</span>->pdtData['receiver_email'<span>]; </span><span>339</span><span>340</span><span>$PDTstatus</span> = (ipn_validate_transaction(<span>$respdata</span>, <span>$this</span>->pdtData, 'PDT') && valid_payment(<span>$orderAmount</span>, <span>$my_currency</span>, 'PDT') && <span>$this</span>->pdtData['payment_status'] == 'Completed'<span>); </span><span>341</span><span>if</span> (<span>$this</span>->pdtData['payment_status'] != '' && <span>$this</span>->pdtData['payment_status'] != 'Completed'<span>) { </span><span>342</span> ipn_debug_email('PDT WARNING :: Order not marked as "Completed". Check for Pending reasons or wait for IPN to complete.' . "n" . '[payment_status] => ' . <span>$this</span>->pdtData['payment_status'] . "n" . '[pending_reason] => ' . <span>$this</span>->pdtData['pending_reason'<span>]); </span><span>343</span><span> } </span><span>344</span><span>345</span><span>$sql</span> = "<span>SELECT order_id, paypal_ipn_id, payment_status, txn_type, pending_reason </span><span>346</span> FROM " . TABLE_PAYPAL . " <span>347</span><span> WHERE txn_id = :transactionID OR parent_txn_id = :transactionID </span><span>348</span> ORDER BY order_id DESC "<span>; </span><span>349</span><span>$sql</span> = <span>$db</span>->bindVars(<span>$sql</span>, ':transactionID', <span>$this</span>->pdtData['txn_id'], 'string'<span>); </span><span>350</span><span>$ipn_id</span> = <span>$db</span>->Execute(<span>$sql</span><span>); </span><span>351</span><span>if</span> (<span>$ipn_id</span>->RecordCount() != 0<span>) { </span><span>352</span> ipn_debug_email('PDT WARNING :: Transaction already exists. Perhaps IPN already added it. PDT processing ended.'<span>); </span><span>353</span><span>$pdtTXN_is_unique</span> = <span>false</span><span>; </span><span>354</span> } <span>else</span><span> { </span><span>355</span><span>$pdtTXN_is_unique</span> = <span>true</span><span>; </span><span>356</span><span> } </span><span>357</span><span>358</span><span>$PDTstatus</span> = (<span>$pdtTXN_is_unique</span> && <span>$PDTstatus</span><span>); </span><span>359</span><span>360</span><span>return</span><span>$PDTstatus</span><span>; </span><span>361</span><span> }</span><span>362</span><span>363</span><span>364</span><span>function</span><span> tableCheckup() { </span><span>365</span><span>global</span><span>$db</span>, <span>$sniffer</span><span>; </span><span>366</span><span>$fieldOkay1</span> = (<span>method_exists</span>(<span>$sniffer</span>, 'field_type')) ? <span>$sniffer</span>->field_type(TABLE_PAYPAL, 'txn_id', 'varchar(20)', <span>true</span>) : -1<span>; </span><span>367</span><span>$fieldOkay2</span> = (<span>$sniffer</span>->field_exists(TABLE_PAYPAL, 'module_name')) ? <span>true</span> : -1<span>; </span><span>368</span><span>$fieldOkay3</span> = (<span>$sniffer</span>->field_exists(TABLE_PAYPAL, 'order_id')) ? <span>true</span> : -1<span>; </span><span>369</span><span>370</span><span>if</span> (<span>$fieldOkay1</span> == -1<span>) { </span><span>371</span><span>$sql</span> = "show fields from " .<span> TABLE_PAYPAL; </span><span>372</span><span>$result</span> = <span>$db</span>->Execute(<span>$sql</span><span>); </span><span>373</span><span>while</span> (!<span>$result</span>-><span>EOF) { </span><span>374</span><span>if</span> (<span>$result</span>->fields['Field'] == 'txn_id'<span>) { </span><span>375</span><span>if</span> (<span>$result</span>->fields['Type'] == 'varchar(20)'<span>) { </span><span>376</span><span>$fieldOkay1</span> = <span>true</span>; <span>//</span><span> exists and matches required type, so skip to other checkup</span><span>377</span> } <span>else</span><span> { </span><span>378</span><span>$fieldOkay1</span> = <span>$result</span>->fields['Type']; <span>//</span><span> doesn't match, so return what it "is"</span><span>379</span><span>break</span><span>; </span><span>380</span><span> } </span><span>381</span><span> } </span><span>382</span><span>$result</span>-><span>MoveNext(); </span><span>383</span><span> } </span><span>384</span><span> } </span><span>385</span><span>386</span><span>if</span> (<span>$fieldOkay1</span> !== <span>true</span><span>) { </span><span>387</span><span>//</span><span> temporary fix to table structure for v1.3.7.x -- may remove in later release</span><span>388</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payment_type payment_type varchar(40) NOT NULL default ''"<span>); </span><span>389</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE txn_type txn_type varchar(40) NOT NULL default ''"<span>); </span><span>390</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payment_status payment_status varchar(32) NOT NULL default ''"<span>); </span><span>391</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE reason_code reason_code varchar(40) default NULL"<span>); </span><span>392</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE pending_reason pending_reason varchar(32) default NULL"<span>); </span><span>393</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE invoice invoice varchar(128) default NULL"<span>); </span><span>394</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payer_business_name payer_business_name varchar(128) default NULL"<span>); </span><span>395</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_name address_name varchar(64) default NULL"<span>); </span><span>396</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_street address_street varchar(254) default NULL"<span>); </span><span>397</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_city address_city varchar(120) default NULL"<span>); </span><span>398</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_state address_state varchar(120) default NULL"<span>); </span><span>399</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payer_email payer_email varchar(128) NOT NULL default ''"<span>); </span><span>400</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE business business varchar(128) NOT NULL default ''"<span>); </span><span>401</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE receiver_email receiver_email varchar(128) NOT NULL default ''"<span>); </span><span>402</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE txn_id txn_id varchar(20) NOT NULL default ''"<span>); </span><span>403</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE parent_txn_id parent_txn_id varchar(20) default NULL"<span>); </span><span>404</span><span> }</span><span>405</span><span>if</span> (<span>$fieldOkay2</span> !== <span>true</span><span>) { </span><span>406</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " ADD COLUMN module_name varchar(40) NOT NULL default '' after txn_type"<span>); </span><span>407</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " ADD COLUMN module_mode varchar(40) NOT NULL default '' after module_name"<span>); </span><span>408</span><span> } </span><span>409</span><span>if</span> (<span>$fieldOkay3</span> !== <span>true</span><span>) { </span><span>410</span><span>$db</span>->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE zen_order_id order_id int(11) NOT NULL default '0'"<span>); </span><span>411</span><span> } </span><span>412</span><span> } </span><span>413</span><span>414</span><span>function</span> paynow_button(<span>$order_id</span><span>) { </span><span>415</span><span>global</span><span>$db</span>, <span>$order</span>, <span>$currencies</span>, <span>$currency</span><span>; </span><span>416</span><span>require_once</span>(DIR_WS_CLASSES . 'order.php'<span>); </span><span>417</span><span>$order</span> = <span>new</span> order(<span>$order_id</span><span>); </span><span>418</span><span>$options</span> = <span>array</span><span>(); </span><span>419</span><span>$optionsCore</span> = <span>array</span><span>(); </span><span>420</span><span>$optionsPhone</span> = <span>array</span><span>(); </span><span>421</span><span>$optionsShip</span> = <span>array</span><span>(); </span><span>422</span><span>$optionsLineItems</span> = <span>array</span><span>(); </span><span>423</span><span>$optionsAggregate</span> = <span>array</span><span>(); </span><span>424</span><span>$optionsTrans</span> = <span>array</span><span>(); </span><span>425</span><span>$buttonArray</span> = <span>array</span><span>(); </span><span>426</span><span>427</span><span>$this</span>->totalsum = <span>$order</span>->info['total'<span>]; </span><span>428</span><span>429</span><span>//</span><span> save the session stuff permanently in case paypal loses the session</span><span>430</span><span>$_SESSION</span>['ppipn_key_to_remove'] = <span>session_id</span><span>(); </span><span>431</span><span>$db</span>->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input(<span>$_SESSION</span>['ppipn_key_to_remove']) . "'"<span>); </span><span>432</span><span>433</span><span>$sql</span> = "insert into " . TABLE_PAYPAL_SESSION . "<span> (session_id, saved_session, expiry) values ( </span><span>434</span> '" . zen_db_input(<span>$_SESSION</span>['ppipn_key_to_remove']) . "<span>', </span><span>435</span> '" . <span>base64_encode</span>(<span>serialize</span>(<span>$_SESSION</span>)) . "<span>', </span><span>436</span> '" . (<span>time</span>() + (1*60*60*24*2)) . "')"<span>; </span><span>437</span><span>438</span><span>$db</span>->Execute(<span>$sql</span><span>); </span><span>439</span><span>440</span><span>$my_currency</span> =<span> select_pp_currency(); </span><span>441</span><span>if</span>(!<span>empty</span>(<span>$order</span>->info['currency'<span>])){ </span><span>442</span><span>$my_currency</span>=<span>$order</span>->info['currency'<span>]; </span><span>443</span><span> } </span><span>444</span><span>$this</span>->transaction_currency = <span>$my_currency</span><span>; </span><span>445</span><span>446</span><span>$this</span>->transaction_amount = (<span>$this</span>->totalsum * <span>$currencies</span>->get_value(<span>$my_currency</span><span>)); </span><span>447</span><span>448</span><span>$telephone</span> = <span>preg_replace</span>('/D/', '', <span>$order</span>->customer['telephone'<span>]); </span><span>449</span><span>if</span> (<span>$telephone</span> != ''<span>) { </span><span>450</span><span>$optionsPhone</span>['H_PhoneNumber'] = <span>$telephone</span><span>; </span><span>451</span><span>if</span> (<span>in_array</span>(<span>$order</span>->customer['country']['iso_code_2'], <span>array</span>('US','CA'<span>))) { </span><span>452</span><span>$optionsPhone</span>['night_phone_a'] = <span>substr</span>(<span>$telephone</span>,0,3<span>); </span><span>453</span><span>$optionsPhone</span>['night_phone_b'] = <span>substr</span>(<span>$telephone</span>,3,3<span>); </span><span>454</span><span>$optionsPhone</span>['night_phone_c'] = <span>substr</span>(<span>$telephone</span>,6,4<span>); </span><span>455</span><span>$optionsPhone</span>['day_phone_a'] = <span>substr</span>(<span>$telephone</span>,0,3<span>); </span><span>456</span><span>$optionsPhone</span>['day_phone_b'] = <span>substr</span>(<span>$telephone</span>,3,3<span>); </span><span>457</span><span>$optionsPhone</span>['day_phone_c'] = <span>substr</span>(<span>$telephone</span>,6,4<span>); </span><span>458</span> }<span>else</span><span> { </span><span>459</span><span>$optionsPhone</span>['night_phone_b'] = <span>$telephone</span><span>; </span><span>460</span><span>$optionsPhone</span>['day_phone_b'] = <span>$telephone</span><span>; </span><span>461</span><span> } </span><span>462</span><span> }</span><span>463</span><span>464</span><span>$optionsCore</span> = <span>array</span><span>( </span><span>465</span> 'lc' => US, <span>466</span><span>//</span><span>'lc' => $order->customer['country']['iso_code_2'],</span><span>467</span> 'charset' => CHARSET, <span>468</span> 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, <span>469</span> 'custom' => zen_session_name() . '=' . zen_session_id(), <span>470</span> 'invoice' => <span>$order</span>->info['num'], <span>471</span> 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, <span>472</span> 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), <span>473</span> 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), <span>474</span> 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), <span>475</span> 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL',<span>false</span>,<span>false</span>,<span>true</span>), <span>476</span> 'redirect_cmd' => '_xclick','rm' => 2,'bn' => 'zencart','mrb' => 'R-6C7952342H795591R','pal' => '9E82WJBKKGPLQ', <span>477</span><span> ); </span><span>478</span><span>$optionsCust</span> = <span>array</span><span>( </span><span>479</span> 'first_name' => replace_accents(<span>$order</span>->customer['firstname']), <span>480</span> 'last_name' => replace_accents(<span>$order</span>->customer['lastname']), <span>481</span> 'address1' => replace_accents(<span>$order</span>->customer['street_address']), <span>482</span> 'city' => replace_accents(<span>$order</span>->customer['city']), <span>483</span> 'state' => zen_get_zone_code(<span>$order</span>->customer['country']['id'], <span>$order</span>->customer['zone_id'], <span>$order</span>->customer['state']), <span>484</span> 'zip' => <span>$order</span>->customer['postcode'], <span>485</span> 'country' => <span>$order</span>->customer['country']['iso_code_2'], <span>486</span> 'email' => <span>$order</span>->customer['email_address'], <span>487</span><span> ); </span><span>488</span><span>//</span><span> address line 2 is optional</span><span>489</span><span>if</span> (<span>$order</span>->customer['suburb'] != '') <span>$optionsCust</span>['address2'] = <span>$order</span>->customer['suburb'<span>]; </span><span>490</span><span>//</span><span> different format for Japanese address layout:</span><span>491</span><span>if</span> (<span>$order</span>->customer['country']['iso_code_2'] == 'JP') <span>$optionsCust</span>['zip'] = <span>substr</span>(<span>$order</span>->customer['postcode'], 0, 3) . '-' . <span>substr</span>(<span>$order</span>->customer['postcode'], 3<span>); </span><span>492</span><span>if</span> (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2<span>) { </span><span>493</span><span>$optionsCust</span> = <span>array</span><span>( </span><span>494</span> 'first_name' => replace_accents(<span>$order</span>->delivery['firstname'] != '' ? <span>$order</span>->delivery['firstname'] : <span>$order</span>->billing['firstname']), <span>495</span> 'last_name' => replace_accents(<span>$order</span>->delivery['lastname'] != '' ? <span>$order</span>->delivery['lastname'] : <span>$order</span>->billing['lastname']), <span>496</span> 'address1' => replace_accents(<span>$order</span>->delivery['street_address'] != '' ? <span>$order</span>->delivery['street_address'] : <span>$order</span>->billing['street_address']), <span>497</span> 'city' => replace_accents(<span>$order</span>->delivery['city'] != '' ? <span>$order</span>->delivery['city'] : <span>$order</span>->billing['city']), <span>498</span> 'state' => (<span>$order</span>->delivery['country']['id'] != '' ? zen_get_zone_code(<span>$order</span>->delivery['country']['id'], <span>$order</span>->delivery['zone_id'], <span>$order</span>->delivery['state']) : zen_get_zone_code(<span>$order</span>->billing['country']['id'], <span>$order</span>->billing['zone_id'], <span>$order</span>->billing['state'])), <span>499</span> 'zip' => (<span>$order</span>->delivery['postcode'] != '' ? <span>$order</span>->delivery['postcode'] : <span>$order</span>->billing['postcode']), <span>500</span> 'country' => (<span>$order</span>->delivery['country']['title'] != '' ? <span>$order</span>->delivery['country']['title'] : <span>$order</span>->billing['country']['title']), <span>501</span> 'country_code' => (<span>$order</span>->delivery['country']['iso_code_2'] != '' ? <span>$order</span>->delivery['country']['iso_code_2'] : <span>$order</span>->billing['country']['iso_code_2']), <span>502</span> 'email' => <span>$order</span>->customer['email_address'], <span>503</span><span> ); </span><span>504</span><span>if</span> (<span>$order</span>->delivery['suburb'] != '') <span>$optionsCust</span>['address2'] = <span>$order</span>->delivery['suburb'<span>]; </span><span>505</span><span>if</span> (<span>$order</span>->delivery['country']['iso_code_2'] == 'JP') <span>$optionsCust</span>['zip'] = <span>substr</span>(<span>$order</span>->delivery['postcode'], 0, 3) . '-' . <span>substr</span>(<span>$order</span>->delivery['postcode'], 3<span>); </span><span>506</span><span> } </span><span>507</span><span>$optionsShip</span>['no_shipping'] =<span> MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED; </span><span>508</span><span>if</span> (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') <span>$optionsShip</span>['address_override'] =<span> MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE; </span><span>509</span><span>//</span><span> prepare cart contents details where possible</span><span>510</span><span>if</span> (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') <span>$optionsLineItems</span> =<span> ipn_getLineItemDetails(); </span><span>511</span><span>if</span> (<span>sizeof</span>(<span>$optionsLineItems</span>) > 0<span>) { </span><span>512</span><span>$optionsLineItems</span>['cmd'] = '_cart'<span>; </span><span>513</span><span>//</span><span> $optionsLineItems['num_cart_items'] = sizeof($order->products);</span><span>514</span><span>if</span> (<span>isset</span>(<span>$optionsLineItems</span>['shipping'<span>])) { </span><span>515</span><span>$optionsLineItems</span>['shipping_1'] = <span>$optionsLineItems</span>['shipping'<span>]; </span><span>516</span><span>unset</span>(<span>$optionsLineItems</span>['shipping'<span>]); </span><span>517</span><span> } </span><span>518</span><span>unset</span>(<span>$optionsLineItems</span>['subtotal'<span>]); </span><span>519</span><span>//</span><span> if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode</span><span>520</span><span>if</span> (!<span>isset</span>(<span>$optionsLineItems</span>['item_name_1']) || <span>$optionsLineItems</span>['creditsExist'] == <span>TRUE</span>) <span>$optionsLineItems</span> = <span>array</span><span>(); </span><span>521</span><span>//</span><span>if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array(); </span><span>522</span><span> // debug: </span><span>523</span><span> //ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch or credits applied, and thus bypassed): ' . "n" . print_r($optionsLineItems, true));</span><span>524</span><span>unset</span>(<span>$optionsLineItems</span>['creditsExist'<span>]); </span><span>525</span><span> }</span><span>526</span><span>$optionsAggregate</span> = <span>array</span><span>( </span><span>527</span> 'cmd' => '_ext-enter', <span>528</span> 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE, <span>529</span> 'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM, <span>530</span><span>//</span><span>'num_cart_items' => sizeof($order->products),</span><span>531</span> 'amount' => <span>number_format</span>(<span>$this</span>->transaction_amount, <span>$currencies</span>->get_decimal_places(<span>$my_currency</span>)), <span>532</span> 'shipping' => '0.00', <span>533</span><span> ); </span><span>534</span><span>if</span> (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') <span>$optionsAggregate</span>['tax'] = '0.00'<span>; </span><span>535</span><span>if</span> (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') <span>$optionsAggregate</span>['tax_cart'] = '0.00'<span>; </span><span>536</span><span>$optionsTrans</span> = <span>array</span><span>( </span><span>537</span> 'upload' => (int)(<span>sizeof</span>(<span>$order</span>->products) > 0), <span>538</span> 'currency_code' => <span>$my_currency</span>, <span>539</span><span>//</span><span>'paypal_order_id' => $paypal_order_id, </span><span>540</span><span> //'no_note' => '1', </span><span>541</span><span> //'invoice' => '',</span><span>542</span><span> ); </span><span>543</span><span>544</span><span>//</span><span> if line-item info is invalid, use aggregate:</span><span>545</span><span>if</span> (<span>sizeof</span>(<span>$optionsLineItems</span>) > 0) <span>$optionsAggregate</span> = <span>$optionsLineItems</span><span>; </span><span>546</span><span>547</span><span>//</span><span> prepare submission</span><span>548</span><span>$options</span> = <span>array_merge</span>(<span>$optionsCore</span>, <span>$optionsCust</span>, <span>$optionsPhone</span>, <span>$optionsShip</span>, <span>$optionsTrans</span>, <span>$optionsAggregate</span><span>); </span><span>549</span><span>//</span><span>ipn_debug_email('Keys for submission: ' . print_r($options, true)); </span><span>550</span><span>551</span><span> // build the button fields</span><span>552</span><span>foreach</span> (<span>$options</span><span>as</span><span>$name</span> => <span>$value</span><span>) { </span><span>553</span><span>//</span><span> remove quotation marks</span><span>554</span><span>$value</span> = <span>str_replace</span>('"', '', <span>$value</span><span>); </span><span>555</span><span>//</span><span> check for invalid chars</span><span>556</span><span>if</span> (<span>preg_match</span>('/[^a-zA-Z_0-9]/', <span>$name</span><span>)) { </span><span>557</span> ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . <span>$name</span> . ' (' . <span>$value</span> . ')'<span>); </span><span>558</span><span>break</span><span>; </span><span>559</span><span> } </span><span>560</span><span>//</span><span> do we need special handling for & and = symbols? </span><span>561</span><span> //if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);</span><span>562</span><span>563</span><span>$bu</span>