{"id":272,"date":"2011-08-27T17:55:42","date_gmt":"2011-08-27T15:55:42","guid":{"rendered":"http:\/\/wpcb.fr\/?p=272"},"modified":"2011-08-27T17:55:42","modified_gmt":"2011-08-27T15:55:42","slug":"correction-coupons-paypal-express-checkout-2-0","status":"publish","type":"post","link":"https:\/\/rationalk.ch\/blog\/correction-coupons-paypal-express-checkout-2-0\/","title":{"rendered":"Correction Coupons + Paypal Express Checkout 2.0"},"content":{"rendered":"<p>Bonjour,<\/p>\n<p>Ceux qui ont tent\u00e9 de faire fonctionner les coupons avec paypal ont du se heurter \u00e0 quelques soucis. Voici une solution :<\/p>\n<p>Remplacer le contenu de \u00a0wpsc-merchants\/paypal-express.merchant.php par :<\/p>\n<pre>&lt;?php\n\/**\n * This is the PayPal Certified 2.0 Gateway. \n * It uses the wpsc_merchant class as a base class which is handy for collating user details and cart contents.\n *\/\n\n \/*\n  * This is the gateway variable $nzshpcrt_gateways, it is used for displaying gateway information on the wp-admin pages and also\n  * for internal operations.\n  *\/\n$nzshpcrt_gateways[$num] = array(\n\t'name' =&gt;  __( 'PayPal Express Checkout 2.0', 'wpsc' ),\n\t'api_version' =&gt; 2.0,\n\t'image' =&gt; WPSC_URL . '\/images\/paypal.gif',\n\t'class_name' =&gt; 'wpsc_merchant_paypal_express',\n\t'has_recurring_billing' =&gt; false,\n\t'wp_admin_cannot_cancel' =&gt; true,\n\t'display_name' =&gt; __( 'PayPal Express', 'wpsc' ),\n\t'requirements' =&gt; array(\n\t\t\/\/\/ so that you can restrict merchant modules to PHP 5, if you use PHP 5 features\n\t\t'php_version' =&gt; 4.3,\n\t\t \/\/\/ for modules that may not be present, like curl\n\t\t'extra_modules' =&gt; array()\n\t),\n\t\n\t\/\/ this may be legacy, not yet decided\n\t'internalname' =&gt; 'wpsc_merchant_paypal_express',\n\n\t\/\/ All array members below here are legacy, and use the code in paypal_multiple.php\n\t'form' =&gt; 'form_paypal_express',\n\t'submit_function' =&gt; 'submit_paypal_express',\n\t'payment_type' =&gt; 'paypal',\n\t'supported_currencies' =&gt; array(\n\t\t'currency_list' =&gt;  array('AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'MYR', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'),\n\t\t'option_name' =&gt; 'paypal_curcode'\n\t)\n);\n\n\n\n\/**\n\t* WP eCommerce PayPal Express Checkout Merchant Class\n\t*\n\t* This is the paypal express checkout merchant class, it extends the base merchant class\n\t*\n\t* @package wp-e-commerce\n\t* @since 3.8\n\t* @subpackage wpsc-merchants\n*\/\nclass wpsc_merchant_paypal_express extends wpsc_merchant {\n  var $name = 'PayPal Express';\n  var $paypal_ipn_values = array();\n\n\t\/**\n\t* construct value array method, converts the data gathered by the base class code to something acceptable to the gateway\n\t* @access public\n\t*\/\n\tfunction construct_value_array() {\n\t\tglobal $PAYPAL_URL;\n\t\t$PROXY_HOST = '127.0.0.1';\n\t\t$PROXY_PORT = '808';\n\t\t$USE_PROXY = false;\n\t\t$version=\"71\";\n\t\n\t\t\/\/ PayPal API Credentials \n\t\t$API_UserName=get_option('paypal_certified_apiuser');\n\t\t$API_Password=get_option('paypal_certified_apipass');\n\t\t$API_Signature=get_option('paypal_certified_apisign');\n\t\n\t\t\/\/ BN Code \tis only applicable for partners\n\t\t$sBNCode = \"PP-ECWizard\";\n\t\t\n\t\tif ('sandbox'  == get_option('paypal_certified_server_type')) {\n\t\t\t$API_Endpoint = \"https:\/\/api-3t.sandbox.paypal.com\/nvp\";\n\t\t\t$PAYPAL_URL = \"https:\/\/www.sandbox.paypal.com\/webscr?cmd=_express-checkout&amp;token=\";\n\t\t}else{\n\t\t\t$API_Endpoint = \"https:\/\/api-3t.paypal.com\/nvp\";\n\t\t\t$PAYPAL_URL = \"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_express-checkout&amp;token=\";\n\t\t}\n\t\n\t\t\/\/$collected_gateway_data\n\t\t$paypal_vars = array();\n\n\t\t\/\/ User settings to be sent to paypal\n\t\t$paypal_vars += array(\n\t\t\t'email' =&gt; $this-&gt;cart_data['email_address'],\n\t\t\t'first_name' =&gt; $this-&gt;cart_data['shipping_address']['first_name'],\n\t\t\t'last_name' =&gt; $this-&gt;cart_data['shipping_address']['last_name'],\n\t\t\t'address1' =&gt; $this-&gt;cart_data['shipping_address']['address'],\n\t\t\t'city' =&gt; $this-&gt;cart_data['shipping_address']['city'],\n\t\t\t'country' =&gt; $this-&gt;cart_data['shipping_address']['country'],\n\t\t\t'zip' =&gt; $this-&gt;cart_data['shipping_address']['post_code']\n\t\t\t);\n\t\tif( ! empty( $this-&gt;cart_data['shipping_address']['state'] ) ) {\n\t\t\t$paypal_vars += array(\n\t\t\t\t'state' =&gt; $this-&gt;cart_data['shipping_address']['state']\n\t\t\t);\n\t\t}\n\n\t\t$this-&gt;collected_gateway_data = $paypal_vars;\n\t}\n\t\n\t\/**\n\t* parse_gateway_notification method, receives data from the payment gateway\n\t* @access private\n\t*\/\n\tfunction parse_gateway_notification() {\n\t\t\/\/\/ PayPal first expects the IPN variables to be returned to it within 30 seconds, so we do this first.\n\t\tif ('sandbox'  == get_option('paypal_certified_server_type')) {\n\t\t\t$paypal_url = \"https:\/\/www.sandbox.paypal.com\/webscr\";\n\t\t}else{\n\t\t\t$API_Endpoint = \"https:\/\/api-3t.paypal.com\/nvp\";\n\t\t\t$paypal_url = \"https:\/\/www.paypal.com\/cgi-bin\/webscr\";\n\t\t}\n\t\t$received_values = array();\n\t\t$received_values['cmd'] = '_notify-validate';\n  \t\t$received_values += $_POST;\n\t\t$options = array(\n\t\t\t'timeout' =&gt; 5,\n\t\t\t'body' =&gt; $received_values,\n\t\t\t'user-agent' =&gt; ('WP e-Commerce\/'.WPSC_PRESENTABLE_VERSION)\n\t\t);\n\t\t\n\n\t\t$response = wp_remote_post($paypal_url, $options);\n\t\t\n\t\tif( 'VERIFIED' == $response['body'] ) {\n\t\t\t$this-&gt;paypal_ipn_values = $received_values;\n\t\t\t$this-&gt;session_id = $received_values['invoice'];\n\t\t\tif ( strtolower( $received_values['payment_status'] ) == 'completed' ) {\n\t\t\t\t$this-&gt;set_purchase_processed_by_sessionid(3);\n\t\t\t\ttransaction_results($this-&gt;session_id,false);\n\t\t\t}\n\t\t\telseif ( strtolower( $received_values['payment_status'] ) == 'denied' ) {\n\t\t\t\t$this-&gt;set_purchase_processed_by_sessionid(6);\n\t\t\t}\n\t\t} else {\n\t\t\texit(\"IPN Request Failure\");\n\t\t}\n\t}\n\t\n\t\/**\n\t* submit method, sends the received data to the payment gateway\n\t* @access public\n\t*\/\n\tfunction submit() {\n\t\t\/\/$_SESSION['paypalExpressMessage']= '&lt;h4&gt;Transaction Canceled&lt;\/h4&gt;';\n\t\t\t\t\/\/ PayPal Express Checkout Module\t\t\n\t\t$paymentAmount = $this-&gt;cart_data['total_price'];\n\n\t\t$_SESSION['paypalAmount'] = $this-&gt;convert( $paymentAmount );\n\t\t$_SESSION['localPaypalAmount'] = $paymentAmount;\n\t\t$_SESSION['paypalexpresssessionid'] = $this-&gt;cart_data['session_id'];\n\t\t$currencyCodeType = $this-&gt;get_paypal_currency_code();\n\t\t$paymentType = \"Sale\";\n\t\t\n\t\tif(get_option('permalink_structure') != '')\n\t\t\t$separator =\"?\";\n\t\telse\n\t\t\t$separator =\"&amp;\";\n\n\t\t$transact_url = get_option('transact_url');\n\t\t$returnURL =  $transact_url.$separator.\"sessionid=\".$this-&gt;cart_data['session_id'].\"&amp;gateway=paypal\";\n\t\t$cancelURL = get_option('shopping_cart_url');\n\t\t$resArray = $this-&gt;CallShortcutExpressCheckout ($_SESSION['paypalAmount'], $currencyCodeType, $paymentType, $returnURL, $cancelURL);\n\t\t$ack = strtoupper($resArray[\"ACK\"]);\n\t\t\n\t\tif($ack==\"SUCCESS\")\t{\n\t\t\t$this-&gt;RedirectToPayPal ( $resArray[\"TOKEN\"] );\n\t\t} else  {\n\t\t\t\/\/Display a user friendly Error on the page using any of the following error information returned by PayPal\n\t\t\t$ErrorCode = urldecode($resArray[\"L_ERRORCODE0\"]);\n\t\t\t$ErrorShortMsg = urldecode($resArray[\"L_SHORTMESSAGE0\"]);\n\t\t\t$ErrorLongMsg = urldecode($resArray[\"L_LONGMESSAGE0\"]);\n\t\t\t$ErrorSeverityCode = urldecode($resArray[\"L_SEVERITYCODE0\"]);\n\t\t\t\n\t\t\techo \"SetExpressCheckout API call failed. \";\n\t\t\techo \"&lt;br \/&gt;Detailed Error Message: \" . $ErrorLongMsg;\n\t\t\techo \"&lt;br \/&gt;Short Error Message: \" . $ErrorShortMsg;\n\t\t\techo \"&lt;br \/&gt;Error Code: \" . $ErrorCode;\n\t\t\techo \"&lt;br \/&gt;Error Severity Code: \" . $ErrorSeverityCode;\n\t\t\t\n\t\t\t\n\t\t\t\/\/ 6WWW\n\t\t\tglobal $wpdb;\n\t\t\techo \"&lt;hr\/&gt;Debug 6WWW&lt;br\/&gt;\";\n\t\t\techo \"Coupons_name -&gt;\".$_SESSION['wpsc_cart']-&gt;coupons_name.'&lt;br\/&gt;';\n\t\t\techo \"Coupons_amount -&gt;\".$_SESSION['wpsc_cart']-&gt;coupons_amount.'&lt;br\/&gt;';\n\t\t\techo \"base_shipping\". $this-&gt;cart_data['base_shipping'].'&lt;br\/&gt;';\n\t\t\t$ispercentage = $wpdb-&gt;get_row(\"SELECT * FROM iaac_wpsc_coupon_codes WHERE coupon_code='karuk'\",ARRAY_A);\n\t\t\techo $ispercentage['is-percentage'].'&lt;br\/&gt;';\n\t\t\techo \"&lt;br\/&gt;SESSION[wpsc_cart] -&gt;&lt;br\/&gt;\";\n\t\t\tprint_r($_SESSION['wpsc_cart']);\n\t\t\techo '&lt;hr\/&gt;';\n\t\t}\n\t    exit();\n\n\t}\n\t\n\tfunction format_price( $price ) {\n\t\t$paypal_currency_code = get_option('paypal_curcode', 'US');\n\n\t\tswitch($paypal_currency_code) {\n\t\t    case \"JPY\":\n\t\t    $decimal_places = 0;\n\t\t    break;\n\n\t\t    case \"HUF\":\n\t\t    $decimal_places = 0;\n\t\t    break;\n\n\t\t    default:\n\t\t    $decimal_places = 2;\n\t\t    break;\n\t\t}\n\t\treturn number_format(sprintf(\"%01.2f\", $price),$decimal_places,'.','');\n\t}\n\t\n\tfunction CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) {\n\t\tglobal $wpdb;\n\t\n\t\t$nvpstr = '';\n\t\t$nvpstr = $nvpstr . \"&amp;PAYMENTREQUEST_0_PAYMENTACTION=\" . $paymentType;\n\t\t$nvpstr = $nvpstr . \"&amp;RETURNURL=\" . $returnURL;\n\t\t$nvpstr = $nvpstr . \"&amp;CANCELURL=\" . $cancelURL;\n\t\t$nvpstr = $nvpstr . \"&amp;PAYMENTREQUEST_0_CURRENCYCODE=\" . $currencyCodeType;\n\t\t$data = array();\n\t\tif(!isset($this-&gt;cart_data['shipping_address']['first_name']) &amp;&amp; !isset($this-&gt;cart_data['shipping_address']['last_name'])){\n\t\t\t$this-&gt;cart_data['shipping_address']['first_name'] =$this-&gt;cart_data['billing_address']['first_name'];\n\t\t\t$this-&gt;cart_data['shipping_address']['last_name'] = $this-&gt;cart_data['billing_address']['last_name'];\n\t\t\t\n\t\t}\n\t\t\t\t\n\t\tif ( $this-&gt;cart_data['shipping_address']['country'] == 'UK' )\n\t\t\t$this-&gt;cart_data['shipping_address']['country'] = 'GB';\n\t\t\n\t\t$data += array(\n\t\t\t'PAYMENTREQUEST_0_SHIPTONAME'\t\t=&gt; $this-&gt;cart_data['shipping_address']['first_name'].' '.$this-&gt;cart_data['shipping_address']['last_name'],\n\t\t\t'PAYMENTREQUEST_0_SHIPTOSTREET' \t\t=&gt; $this-&gt;cart_data['shipping_address']['address'],\n\t\t\t'PAYMENTREQUEST_0_SHIPTOCITY'\t\t=&gt; $this-&gt;cart_data['shipping_address']['city'],\n\t\t\t'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' =&gt; $this-&gt;cart_data['shipping_address']['country'],\n\t\t\t'PAYMENTREQUEST_0_SHIPTOZIP'\t\t\t=&gt; $this-&gt;cart_data['shipping_address']['post_code'],\n\t\t);\n\n\t\tif( ! empty( $this-&gt;cart_data['shipping_address']['state'] ) ){\n\t\t\t$data += array(\n\t\t\t\t'PAYMENTREQUEST_0_SHIPTOSTATE' =&gt; $this-&gt;cart_data['shipping_address']['state']\n\t\t\t\t);\n\t\t}\n\n\t\t$i = 0;\n\t\t$item_total = 0;\n\t\t$tax_total = 0;\n\t\t$shipping_total = 0;\n\t\t\n\t\t\/\/ Check if we have a free shipping coupon :\n\t\t\/\/6WWW et si ce coupons n'est pas un coupon de livraison gratuite !\n\t\t$coupons_name=$_SESSION['wpsc_cart']-&gt;coupons_name;\n\t\t$ispercentage = $wpdb-&gt;get_row(\"SELECT * FROM iaac_wpsc_coupon_codes WHERE coupon_code='\".$coupons_name.\"'\",ARRAY_A);\n\t\tif ($ispercentage['is-percentage']==2){$freeshipping=1;}else{$freeshipping=0;}\n\t\t\n\t\t\n\t\tforeach ( $this-&gt;cart_items as $cart_item ) {\n\t\t\t$data[\"L_PAYMENTREQUEST_0_NAME{$i}\"] = $cart_item['name'];\n\t\t\t$data[\"L_PAYMENTREQUEST_0_AMT{$i}\"] = $this-&gt;convert( $cart_item['price'] );\n\t\t\t$data[\"L_PAYMENTREQUEST_0_NUMBER{$i}\"] = $i;\n\t\t\t$data[\"L_PAYMENTREQUEST_0_QTY{$i}\"] = $cart_item['quantity'];\n\t\t\t$item_total += $this-&gt;convert( $cart_item['price'] ) * $cart_item['quantity'];\n\t\t\t$shipping_total += $cart_item['shipping'];\n\t\t\t$i ++;\n\t\t}\n\t\t\/\/if we have a discount then include a negative amount with that discount\n\t\t\n\t\tif ( (!$freeshipping) &amp;&amp; ($this-&gt;cart_data['cart_discount_value'] )){\n\t\t\t$discount_value = $this-&gt;convert( $this-&gt;cart_data['cart_discount_value']);\n\t\t\n\t\t\t\/\/ if item total &lt; discount amount, leave at least 0.01 unit in item total, then subtract\n\t\t\t\/\/ 0.01 from shipping as well\n\t\t\tif ( $discount_value &gt;= $item_total ) {\n\t\t\t\t$discount_value = $item_total - 0.01;\n\t\t\t\t$shipping_total -= 0.01;\n\t\t\t}\n\t\t\n\t\t\t$data[\"L_PAYMENTREQUEST_0_NAME{$i}\"] = \"Discount \/ Coupon\";\n\t\t\t$data[\"L_PAYMENTREQUEST_0_AMT{$i}\"] = -$discount_value;\n\t\t\t$data[\"L_PAYMENTREQUEST_0_NUMBER{$i}\"] = $i;\n\t\t\t$data[\"L_PAYMENTREQUEST_0_QTY{$i}\"] = 1;\n\t\t\t$item_total -= $discount_value;\n\t\t}\n\t\t\n\t\t\n\t\t$data[\"PAYMENTREQUEST_0_ITEMAMT\"] = $this-&gt;format_price( $item_total ) ;\n\t\t\n\t\t\/\/6WWW\n\t\tif ($freeshipping){$data[\"PAYMENTREQUEST_0_SHIPPINGAMT\"] =0;}\n\t\telse {$data[\"PAYMENTREQUEST_0_SHIPPINGAMT\"] = $this-&gt;convert( $this-&gt;cart_data['base_shipping'] + $shipping_total );}\n\n\t\t$total = $data[\"PAYMENTREQUEST_0_ITEMAMT\"] + $data[\"PAYMENTREQUEST_0_SHIPPINGAMT\"];\n\t\t\n\t\tif ( ! wpsc_tax_isincluded() ) {\n\t\t\t$data[\"PAYMENTREQUEST_0_TAXAMT\"] = $this-&gt;convert( $this-&gt;cart_data['cart_tax'] );\n\t\t\t$total += $data[\"PAYMENTREQUEST_0_TAXAMT\"];\n\t\t}\n\t\t\n\t\t\/\/ adjust total amount in case we had to round up after converting currency\n\t\tif ( $this-&gt;rate !== 1 &amp;&amp; $total != $paymentAmount )\n\t\t\t$paymentAmount = $total;\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t$data[\"PAYMENTREQUEST_0_AMT\"] = $paymentAmount;\n\n\t\tif(count($data) &gt;= 4) {\n\t\t\t$temp_data = array();\n\t\t\tforeach($data as $key =&gt; $value)\n\t\t\t\t$temp_data[] = $key.\"=\".$value;\n\t\n\t\t\t$nvpstr = $nvpstr . \"&amp;\".implode(\"&amp;\",$temp_data);\n\t\t}\n\t\t$_SESSION[\"currencyCodeType\"] = $currencyCodeType;\t  \n\t\t$_SESSION[\"PaymentType\"] = $paymentType;\n\n\t    $resArray= paypal_hash_call(\"SetExpressCheckout\", $nvpstr);\n\t\t$ack = strtoupper($resArray[\"ACK\"]);\n\t\tif($ack==\"SUCCESS\")\t{\n\t\t\t$token = urldecode($resArray[\"TOKEN\"]);\n\t\t\t$_SESSION['token']=$token;\n\t\t}\n\t\t   \n\t    return $resArray;\n\t}\n\n\tfunction RedirectToPayPal ( $token ){\n\t\tglobal $PAYPAL_URL;\n\t\t\/\/ Redirect to paypal.com here\n\t\t$payPalURL = $PAYPAL_URL . $token;\n\/\/\t\techo 'REDIRECT:'.$payPalURL;\n\t\twp_redirect($payPalURL);\n\/\/\t\texit();\n\t}\n\n\tfunction convert( $amt ){\n\t\tif ( empty( $this-&gt;rate ) ) {\n\t\t\t$this-&gt;rate = 1;\n\t\t\t$paypal_currency_code = $this-&gt;get_paypal_currency_code();\n\t\t\t$local_currency_code = $this-&gt;get_local_currency_code();\n\t\t\tif( $local_currency_code != $paypal_currency_code ) {\n\t\t\t\t$curr=new CURRENCYCONVERTER();\n\t\t\t\t$this-&gt;rate = $curr-&gt;convert( 1, $paypal_currency_code, $local_currency_code );\n\t\t\t}\n\t\t}\n\n\t\treturn $this-&gt;format_price( $amt \/ $this-&gt;rate );\n\t}\n\t\n\tfunction get_local_currency_code() {\n\t\tif ( empty( $this-&gt;local_currency_code ) ) {\n\t\t\tglobal $wpdb;\n\t\t\t$this-&gt;local_currency_code = $wpdb-&gt;get_var(\"SELECT `code` FROM `\".WPSC_TABLE_CURRENCY_LIST.\"` WHERE `id`='\".get_option('currency_type').\"' LIMIT 1\");\n\t\t}\n\t\t\n\t\treturn $this-&gt;local_currency_code;\n\t}\n\t\n\tfunction get_paypal_currency_code() {\n\t\tif ( empty( $this-&gt;paypal_currency_code ) ) {\n\t\t\tglobal $wpsc_gateways;\n\t\t\t$this-&gt;paypal_currency_code = $this-&gt;get_local_currency_code();\n\t\t\t\n\t\t\tif ( ! in_array( $this-&gt;paypal_currency_code, $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'] ) )\n\t\t\t\t$this-&gt;paypal_currency_code = get_option( 'paypal_curcode', 'USD' );\n\t\t}\n\t\t\n\t\treturn $this-&gt;paypal_currency_code;\n\t}\n\t\n} \/\/ end of class\n\n\/\/ terrible code duplication just to hot fix the \"missing Description in email receipt\" bug\n\/\/ see paypal_processingfunctions() for more details\nfunction wpsc_paypal_express_convert( $amt ) {\n\tglobal $wpdb;\n\t\n\tstatic $rate;\n\tstatic $paypal_currency_code;\n\tstatic $local_currency_code;\n\t\n\tif ( empty( $rate ) ) {\n\t\t$rate = 1;\n\t\tif ( empty( $local_currency_code ) ) {\n\t\t\t$local_currency_code = $wpdb-&gt;get_var(\"SELECT `code` FROM `\".WPSC_TABLE_CURRENCY_LIST.\"` WHERE `id`='\".get_option('currency_type').\"' LIMIT 1\");\n\t\t}\n\t\tif ( empty( $paypal_currency_code ) ) {\n\t\t\tglobal $wpsc_gateways;\n\t\t\t$paypal_currency_code = $local_currency_code;\n\t\t\tif ( ! in_array( $paypal_currency_code, $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'] ) )\n\t\t\t\t$paypal_currency_code = get_option( 'paypal_curcode', 'USD' );\n\t\t}\n\t\t\n\t\tif ( $local_currency_code != $paypal_currency_code ) {\n\t\t\t$curr = new CURRENCYCONVERTER();\n\t\t\t$rate = $curr-&gt;convert( 1, $paypal_currency_code, $local_currency_code );\n\t\t}\n\t}\n\t\n\treturn wpsc_paypal_express_format( $amt \/ $rate );\n}\n\nfunction wpsc_paypal_express_format( $price ) {\n\t$paypal_currency_code = get_option('paypal_curcode', 'US');\n\n\tswitch($paypal_currency_code) {\n\t    case \"JPY\":\n\t    $decimal_places = 0;\n\t    break;\n\n\t    case \"HUF\":\n\t    $decimal_places = 0;\n\t    break;\n\n\t    default:\n\t    $decimal_places = 2;\n\t    break;\n\t}\n\treturn number_format(sprintf(\"%01.2f\", $price),$decimal_places,'.','');\n}\n\n\/**\n * Saving of PayPal Express Settings\n * @access public\n *\n * @since 3.8\n *\/\nfunction submit_paypal_express() {  \n\tif(isset($_POST['paypal_certified_apiuser']))\n\t\tupdate_option('paypal_certified_apiuser', $_POST['paypal_certified_apiuser']);\n\t\n\tif(isset($_POST['paypal_certified_apipass']))\n\t\tupdate_option('paypal_certified_apipass', $_POST['paypal_certified_apipass']);\n\t\n\tif(isset($_POST['paypal_curcode']))\n\t\tupdate_option('paypal_curcode', $_POST['paypal_curcode']);\n\t\n\tif(isset($_POST['paypal_certified_apisign']))\n\t\tupdate_option('paypal_certified_apisign', $_POST['paypal_certified_apisign']);\n\t\n\tif(isset($_POST['paypal_certified_server_type']))\n\t\tupdate_option('paypal_certified_server_type', $_POST['paypal_certified_server_type']);\n\t\n\tif(isset($_POST['paypal_ipn'])) {\n\t\tupdate_option('paypal_ipn', (int)$_POST['paypal_ipn']);\n\t}\n\t\n\treturn true;\n}\n\n\/**\n * Form Express Returns the Settings Form Fields\n * @access public\n *\n * @since 3.8\n * @return $output string containing Form Fields\n *\/\nfunction form_paypal_express() {\n\tglobal $wpdb, $wpsc_gateways;\n\t\n\t$serverType1 = '';\n\t$serverType2 = '';\n\t$select_currency[get_option('paypal_curcode')] = \"selected='selected'\";\n\t\n  \tif (get_option('paypal_certified_server_type') == 'sandbox')\n\t\t$serverType1=\"checked='checked'\";\n\telseif(get_option('paypal_certified_server_type') == 'production')\n\t\t$serverType2 =\"checked='checked'\";\n\t$paypal_ipn = get_option( 'paypal_ipn' );\n\t$output = \"\n\t\t&lt;tr&gt;\n\t\t  &lt;td&gt;\" . __('API Username', 'wpsc' ) . \"\n\t\t  &lt;\/td&gt;\n\t\t  &lt;td&gt;\n\t\t  &lt;input type='text' size='40' value='\".get_option('paypal_certified_apiuser').\"' name='paypal_certified_apiuser' \/&gt;\n\t\t  &lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t&lt;tr&gt;\n\t\t  &lt;td&gt;\" . __('API Password', 'wpsc' ) . \"\n\t\t  &lt;\/td&gt;\n\t\t  &lt;td&gt;\n\t\t  &lt;input type='text' size='40' value='\".get_option('paypal_certified_apipass').\"' name='paypal_certified_apipass' \/&gt;\n\t\t  &lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t&lt;tr&gt;\n\t\t &lt;td&gt;\" . __('API Signature', 'wpsc' ) . \"\n\t\t &lt;\/td&gt;\n\t\t &lt;td&gt;\n\t\t &lt;input type='text' size='70' value='\".get_option('paypal_certified_apisign').\"' name='paypal_certified_apisign' \/&gt;\n\t\t &lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t&lt;tr&gt;\n\t\t &lt;td&gt;\" . __('Server Type', 'wpsc' ) . \"\n\t\t &lt;\/td&gt;\n\t\t &lt;td&gt;\n\t\t\t&lt;input $serverType1 type='radio' name='paypal_certified_server_type' value='sandbox' \/&gt; \" . __('Sandbox (For testing)', 'wpsc' ) . \"\n\t\t\t&lt;input $serverType2 type='radio' name='paypal_certified_server_type' value='production' \/&gt; \" . __('Production', 'wpsc' ) . \"\n\t\t &lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t&lt;tr&gt;\n\t\t  \t&lt;td colspan='2'&gt;\n\t\t  \t&lt;span  class='wpscsmall description'&gt;\n\t\t  \tOnly use the sandbox server if you have a sandbox account with PayPal you can find out more about this &lt;a href='https:\/\/cms.paypal.com\/us\/cgi-bin\/?cmd=_render-content&amp;content_ID=developer\/howto_testing_sandbox'&gt; here &lt;\/a&gt;&lt;\/span&gt;\n\t\t  \t&lt;\/td&gt;\n  &lt;\/tr&gt;\n\n\t\t&lt;tr&gt;\n\t\t\t&lt;td&gt;\n\t\t\t\t\" . __( 'IPN', 'wpsc' ) . \"\n\t\t\t&lt;\/td&gt;\n\t\t\t&lt;td&gt;\n\t\t\t\t&lt;input type='radio' value='1' name='paypal_ipn' id='paypal_ipn1' \" . checked( $paypal_ipn, 1, false ) . \" \/&gt; &lt;label for='paypal_ipn1'&gt;\".__('Yes', 'wpsc').\"&lt;\/label&gt; &amp;nbsp;\n\t\t\t\t&lt;input type='radio' value='0' name='paypal_ipn' id='paypal_ipn2' \" . checked( $paypal_ipn, 0, false ) . \" \/&gt; &lt;label for='paypal_ipn2'&gt;\".__('No', 'wpsc').\"&lt;\/label&gt;\n\t\t\t&lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t&lt;tr&gt;\n\t\t  \t&lt;td colspan='2'&gt;\n\t\t\t  \t&lt;span  class='wpscsmall description'&gt;\n\t\t\t\t  \tIPN (instant payment notification ) will automatically update your sales logs to 'Accepted payment' when a customers payment is successful. For IPN to work you also need to have IPN turned on in your Paypal settings. If it is not turned on, the sales sill remain as 'Order Pending' status until manually changed. It is highly recommend using IPN, especially if you are selling digital products.\n\t\t\t  \t&lt;\/span&gt;\n\t\t  \t&lt;\/td&gt;\n  &lt;\/tr&gt;\n\n\t\t\";\n\t\t\n\t\t$paypal_ipn = get_option( 'paypal_ipn' );\t\t\n\t\t$store_currency_code = $wpdb-&gt;get_var(\"SELECT `code` FROM `\".WPSC_TABLE_CURRENCY_LIST.\"` WHERE `id` IN ('\".absint(get_option('currency_type')).\"')\");\n\t\t$current_currency = get_option('paypal_curcode');\n\n\t\tif(($current_currency == '') &amp;&amp; in_array($store_currency_code, $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'])) {\n\t\t\tupdate_option('paypal_curcode', $store_currency_code);\n\t\t\t$current_currency = $store_currency_code;\n\t\t}\n\t\tif($current_currency != $store_currency_code) {\n\t\t\t$output .= \"&lt;tr&gt; &lt;td colspan='2'&gt;&lt;strong class='form_group'&gt;\".__('Currency Converter').\"&lt;\/td&gt; &lt;\/tr&gt;\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td colspan='2'&gt;\".__('Your website is using a currency not accepted by PayPal, select an accepted currency using the drop down menu bellow. Buyers on your site will still pay in your local currency however we will convert the currency and send the order through to PayPal using the currency you choose below.', 'wpsc').\"&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;n\";\n\t\t\n\t\t\t$output .= \"&lt;tr&gt;n &lt;td&gt;\" . __('Convert to', 'wpsc' ) . \" &lt;\/td&gt;n \";\n\t\t\t$output .= \"&lt;td&gt;n &lt;select name='paypal_curcode'&gt;n\";\n\t\n\t\t\tif (!isset($wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'])) \n\t\t\t\t$wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'] = array();\n\t\t\t\n\t\t\t$paypal_currency_list = $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'];\n\t\n\t\t\t$currency_list = $wpdb-&gt;get_results(\"SELECT DISTINCT `code`, `currency` FROM `\".WPSC_TABLE_CURRENCY_LIST.\"` WHERE `code` IN ('\".implode(\"','\",$paypal_currency_list).\"')\", ARRAY_A);\n\t\t\tforeach($currency_list as $currency_item) {\n\t\t\t\t$selected_currency = '';\n\t\t\t\tif($current_currency == $currency_item['code']) {\n\t\t\t\t\t$selected_currency = \"selected='selected'\";\n\t\t\t\t}\n\t\t\t\t$output .= \"&lt;option \".$selected_currency.\" value='{$currency_item['code']}'&gt;{$currency_item['currency']}&lt;\/option&gt;\";\n\t\t\t}\n\t\t\t$output .= \"            &lt;\/select&gt; n\";\n\t\t\t$output .= \"          &lt;\/td&gt;n\";\n\t\t\t$output .= \"       &lt;\/tr&gt;n\";\n\t\t}\n \t$output .=\"&lt;tr&gt;\n  \t&lt;td colspan='2'&gt;\n  \t&lt;span  class='wpscsmall description'&gt;\n  \t  For more help configuring Paypal Express, please read our documentation &lt;a href='http:\/\/docs.getshopped.org\/wiki\/documentation\/payments\/paypal-express-checkout'&gt;here &lt;\/a&gt;  \t&lt;\/span&gt;\n  \t&lt;\/td&gt;\n   &lt;\/tr&gt;\";\n   \n  \treturn $output;\n}\n\nfunction wpsc_get_paypal_currency_code() {\n\tglobal $wpdb, $wpsc_gateways;\n\t$paypal_currency_code = $wpdb-&gt;get_var(\"SELECT `code` FROM `\".WPSC_TABLE_CURRENCY_LIST.\"` WHERE `id`='\".get_option('currency_type').\"' LIMIT 1\");\n\tif ( ! in_array( $paypal_currency_code, $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'] ) )\n\t\t$paypal_currency_code = get_option( 'paypal_curcode', 'USD' );\n\t\t\n\treturn $paypal_currency_code;\n}\n\n\/**\n * prcessing functions, this is where the main logic of paypal express lives\n * @access public\n *\n * @since 3.8\n *\/\nfunction paypal_processingfunctions(){\n\tglobal $wpdb, $wpsc_cart;\n\n\t$sessionid = '';\n\tif (isset($_SESSION['paypalexpresssessionid']))\n\t$sessionid = $_SESSION['paypalexpresssessionid'];\n\tif(isset($_REQUEST['act']) &amp;&amp; ($_REQUEST['act']=='error')){\n\t\tsession_start();\n\t\t$resArray=$_SESSION['reshash']; \n\t\t$_SESSION['paypalExpressMessage']= '\n\t\t&lt;center&gt;\n\t\t&lt;table width=\"700\" align=\"left\"&gt;\n\t\t&lt;tr&gt;\n\t\t\t&lt;td colspan=\"2\" class=\"header\"&gt;' . __('The PayPal API has returned an error!', 'wpsc' ) . '&lt;\/td&gt;\n\t\t&lt;\/tr&gt;\n\t\t';\n\t    \/\/it will print if any URL errors \n\t\tif(isset($_SESSION['curl_error_msg'])) { \n\t\t\t$errorMessage=$_SESSION['curl_error_msg'] ;\t\n\t\t\t$response = $_SESSION['response'];\n\t\t\tsession_unset();\t\n\t\t\t\n\t\t\t$_SESSION['paypalExpressMessage'].='\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;response:&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;'.$response.'&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;\n\t\t\t   \n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;Error Message:&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;'.$errorMessage.'&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;';\n\t\t } else {\n\t\n\t\t\t\/* If there is no URL Errors, Construct the HTML page with \n\t\t\t   Response Error parameters.   *\/\n\t\t\t$_SESSION['paypalExpressMessage'] .=\"\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Ack:&lt;\/td&gt;\n\t\t\t\t\t&lt;td&gt;\".$resArray['ACK'].\"&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Correlation ID:&lt;\/td&gt;\n\t\t\t\t\t&lt;td&gt;\".$resArray['CORRELATIONID'].\"&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Version:&lt;\/td&gt;\n\t\t\t\t\t&lt;td&gt;\".$resArray['VERSION'].\"&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\";\n\t\t\t\n\t\t\t$count=0;\n\t\t\twhile (isset($resArray[\"L_SHORTMESSAGE\".$count])) {\t\t\n\t\t\t\t$errorCode    = $resArray[\"L_ERRORCODE\".$count];\n\t\t\t\t$shortMessage = $resArray[\"L_SHORTMESSAGE\".$count];\n\t\t\t\t$longMessage  = $resArray[\"L_LONGMESSAGE\".$count]; \n\t\t\t\t$count=$count+1; \n\t\t\t\t$_SESSION['paypalExpressMessage'] .=\"\n\t\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t\t&lt;td&gt;\" . __('Error Number:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt; $errorCode &lt;\/td&gt;\n\t\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t\t&lt;td&gt;\" . __('Short Message:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt; $shortMessage &lt;\/td&gt;\n\t\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t\t&lt;td&gt;\" . __('Long Message:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt; $longMessage &lt;\/td&gt;\n\t\t\t\t\t&lt;\/tr&gt;\";\n\t\t\t\n\t\t \t}\/\/end while\n\t\t}\/\/ end else\n\t\t$_SESSION['paypalExpressMessage'] .=\"\n\t\t\t&lt;\/center&gt;\n\t\t\t\t&lt;\/table&gt;\";\n\t\n\t}else if(isset($_REQUEST['act']) &amp;&amp; ($_REQUEST['act']=='do')){\n\t\t\/* Gather the information to make the final call to\n\t\t   finalize the PayPal payment.  The variable nvpstr\n\t\t   holds the name value pairs   *\/\n\n\t\t$token =urlencode($_REQUEST['token']);\n\n\t\t$paymentAmount =urlencode ($_SESSION['paypalAmount']);\n\t\t$paymentType = urlencode($_SESSION['PaymentType']);\n\t\t$currCodeType = urlencode(wpsc_get_paypal_currency_code());\n\t\t$payerID = urlencode($_REQUEST['PayerID']);\n\t\t$serverName = urlencode($_SERVER['SERVER_NAME']);\n\t\t$BN='Instinct_e-commerce_wp-shopping-cart_NZ';\t\n\t\t$nvpstr='&amp;TOKEN='.$token.'&amp;PAYERID='.$payerID.'&amp;PAYMENTREQUEST_0_PAYMENTACTION=Sale&amp;PAYMENTREQUEST_0_CURRENCYCODE='.$currCodeType.'&amp;IPADDRESS='.$serverName.\"&amp;BUTTONSOURCE=\".$BN.\"&amp;PAYMENTREQUEST_0_INVNUM=\".urlencode( $sessionid );\n\t\t\/\/ IPN data\n\t\tif (get_option('paypal_ipn') == 1) {\n\t\t\t$notify_url = add_query_arg( 'wpsc_action', 'gateway_notification', (get_option( 'siteurl' ) . \"\/index.php\" ) );\n\t\t\t$notify_url = add_query_arg('gateway', 'wpsc_merchant_paypal_express', $notify_url);\n\t\t\t$notify_url = apply_filters('wpsc_paypal_express_notify_url', $notify_url);\n\t\t\t$nvpstr .= '&amp;PAYMENTREQUEST_0_NOTIFYURL='.urlencode( $notify_url );\n\t\t}\n\t\t\n\t\t\/\/ Horrible code that I had to write to hot fix the issue with missing item detail in email receipts. arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrgh!!!!! @#@$%@#%@##$#$\n\t\t$purchase_log = $wpdb-&gt;get_row( \"SELECT * FROM `\" . WPSC_TABLE_PURCHASE_LOGS . \"` WHERE `sessionid` = {$sessionid}\", ARRAY_A );\n\t\t$cart_data = $original_cart_data = $wpdb-&gt;get_results( \"SELECT * FROM `\" . WPSC_TABLE_CART_CONTENTS . \"` WHERE `purchaseid` = {$purchase_log['id']}\", ARRAY_A );\n\t\t$i = 0;\n\t\t$item_total = 0;\n\t\t$shipping_total = 0;\n\t\tforeach ( $cart_data as $cart_item ) {\n\t\t\t$converted_price = wpsc_paypal_express_convert( $cart_item['price'] );\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_NAME{$i}=\" . urlencode( $cart_item['name'] );\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_AMT{$i}=\" . $converted_price;\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_NUMBER{$i}=\" . $i;\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_QTY{$i}=\" . $cart_item['quantity'];\n\t\t\t$item_total += $converted_price * $cart_item['quantity'];\n\t\t\t$shipping_total += wpsc_paypal_express_convert( $cart_item['pnp'] );\n\t\t\t$i ++;\n\t\t}\n\t\t\/\/if we have a discount then include a negative amount with that discount\n\t\tif ( $purchase_log['discount_value'] ){\n\t\t\t$discount_value = wpsc_paypal_express_convert( $purchase_log['discount_value']);\n\t\t\t\n\t\t\t\/\/ if item total &lt; discount amount, leave at least 0.01 unit in item total, then subtract\n\t\t\t\/\/ 0.01 from shipping as well\n\t\t\tif ( $discount_value &gt;= $item_total ) {\n\t\t\t\t$discount_value = $item_total - 0.01;\n\t\t\t\t$shipping_total -= 0.01;\n\t\t\t}\n\t\t\t\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_NAME{$i}=\" . urlencode( \"Discount \/ Coupon\" );\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_AMT{$i}=-\" . urlencode( $discount_value );\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_NUMBER{$i}={$i}\";\n\t\t\t$nvpstr .= \"&amp;L_PAYMENTREQUEST_0_QTY{$i}=1\";\n\t\t\t$item_total -= $discount_value;\n\t\t}\n\t\t$item_total = wpsc_paypal_express_format( $item_total );\n\t\t$shipping_total = wpsc_paypal_express_convert( $purchase_log['base_shipping'] ) +  $shipping_total;\n\t\t$nvpstr .= '&amp;PAYMENTREQUEST_0_ITEMAMT=' . $item_total;\n\t\t$nvpstr .= '&amp;PAYMENTREQUEST_0_SHIPPINGAMT=' . $shipping_total;\n\n\t\t$total = $item_total + $shipping_total;\n\t\t\n\t\tif ( ! wpsc_tax_isincluded() ) {\n\t\t\t$tax = wpsc_paypal_express_convert( $purchase_log['wpec_taxes_total'] );\n\t\t\t$nvpstr .= '&amp;PAYMENTREQUEST_0_TAXAMT=' . $tax;\n\t\t\t$total += $tax;\n\t\t}\n\t\t\n\t\t\/\/ adjust total amount in case we had to round up after converting currency\n\t\tif ( $total != $paymentAmount )\n\t\t\t$paymentAmount = $total;\n\t\t\t\n\t\t$nvpstr .= \"&amp;PAYMENTREQUEST_0_AMT={$paymentAmount}\";\n\t\t$resArray=paypal_hash_call(\"DoExpressCheckoutPayment\",$nvpstr);\n\n\t\t\/* Display the API response back to the browser.\n\t\t   If the response from PayPal was a success, display the response parameters'\n\t\t   If the response was an error, display the errors received using APIError.php. *\/\n\t\t$ack = strtoupper($resArray[\"ACK\"]);\n\t\t$_SESSION['reshash']=$resArray;\n\n\t\tif($ack!=\"SUCCESS\"){\n\t\t\t$location = get_option('transact_url').\"&amp;act=error\";\n\t\t}else{\n\t\t\t$transaction_id = $wpdb-&gt;escape($resArray['PAYMENTINFO_0_TRANSACTIONID']);\n\t\t\tswitch($resArray['PAYMENTINFO_0_PAYMENTSTATUS']) {\n\t\t\t\tcase 'Processed': \/\/ I think this is mostly equivalent to Completed\n\t\t\t\tcase 'Completed':\n\t\t\t\t$wpdb-&gt;query(\"UPDATE `\".WPSC_TABLE_PURCHASE_LOGS.\"` SET `processed` = '3' WHERE `sessionid` = \".$sessionid.\" LIMIT 1\");\n\t\t\t\ttransaction_results($sessionid, false, $transaction_id);\n\t\t\t\tbreak;\n\t\t\n\t\t\t\tcase 'Pending': \/\/ need to wait for \"Completed\" before processing\n\t\t\t\t$wpdb-&gt;query(\"UPDATE `\".WPSC_TABLE_PURCHASE_LOGS.\"` SET `transactid` = '\".$transaction_id.\"',`processed` = '2', `date` = '\".time().\"'  WHERE `sessionid` = \".$sessionid.\" LIMIT 1\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t$location = add_query_arg('sessionid', $sessionid, get_option('transact_url'));\n\t\t\t\n\t\t\t$_SESSION['paypalExpressMessage'] = null;\n\t\t\twp_redirect($location);\n\t\t\texit();\n\t\t}\n\t\n\t\t@$_SESSION['nzshpcrt_serialized_cart'] = '';\n\t\t$_SESSION['nzshpcrt_cart'] = '';\n\t\t$_SESSION['nzshpcrt_cart'] = Array();\t \n\t\t$wpsc_cart-&gt;empty_cart();\n\t\t\t\t\n\t} else if(isset($_REQUEST['paymentType']) || isset($_REQUEST['token'])){\n\n\t\t$token = $_REQUEST['token'];\n\t\tif(!isset($token)) {\n\t\t   $paymentAmount=$_SESSION['paypalAmount'];\n\t\t   $currencyCodeType=wpsc_get_paypal_currency_code();\n\t\t   $paymentType='Sale';\n\t\t\tif(get_option('permalink_structure') != '')\n\t\t\t\t$separator =\"?\";\n\t\t\telse\n\t\t\t\t$separator =\"&amp;\";\n\t\t\t\n\t\t\t$returnURL =urlencode(get_option('transact_url').$separator.'currencyCodeType='.$currencyCodeType.'&amp;paymentType='.$paymentType.'&amp;paymentAmount='.$paymentAmount);\n\t\t\t$cancelURL =urlencode(get_option('transact_url').$separator.'paymentType=$paymentType' );\n\t\t\n\t\t\t\/* Construct the parameter string that describes the PayPal payment\n\t\t\tthe varialbes were set in the web form, and the resulting string\n\t\t\tis stored in $nvpstr *\/\n\t\t  \n\t\t\t$nvpstr=\"&amp;PAYMENTREQUEST_0_AMT=\".$paymentAmount.\"&amp;PAYMENTREQUEST_0_PAYMENTACTION=\".$paymentType.\"&amp;ReturnUrl=\".$returnURL.\"&amp;CANCELURL=\".$cancelURL .\"&amp;PAYMENTREQUEST_0_CURRENCYCODE=\".$currencyCodeType;\n\t\t \n\t\t\t\/* Make the call to PayPal to set the Express Checkout token\n\t\t\tIf the API call succeded, then redirect the buyer to PayPal\n\t\t\tto begin to authorize payment.  If an error occured, show the\n\t\t\tresulting errors\n\t\t\t*\/\n\t\t   $resArray=paypal_hash_call(\"SetExpressCheckout\",$nvpstr);\n\t\t   $_SESSION['reshash']=$resArray;\n\t\t   $ack = strtoupper($resArray[\"ACK\"]);\n\n\t\t   if($ack==\"SUCCESS\"){\n\t\t\t\t\/\/ Redirect to paypal.com here\n\t\t\t\t$token = urldecode($resArray[\"TOKEN\"]);\n\t\t\t\t$payPalURL = $PAYPAL_URL.$token;\n\t\t\t\twp_redirect($payPalURL);\n\t\t   } else  {\n\t\t\t\t\/\/ Redirecting to APIError.php to display errors. \n\t\t\t\t$location = get_option('transact_url').\"&amp;act=error\";\n\t\t\t\twp_redirect($location);\n\t\t   }\n\t\t   exit();\n\t\t} else {\n\t\t \/* At this point, the buyer has completed in authorizing payment\n\t\t\tat PayPal.  The script will now call PayPal with the details\n\t\t\tof the authorization, incuding any shipping information of the\n\t\t\tbuyer.  Remember, the authorization is not a completed transaction\n\t\t\tat this state - the buyer still needs an additional step to finalize\n\t\t\tthe transaction\n\t\t\t*\/\n\t\t\n\t\t   $token =urlencode( $_REQUEST['token']);\n\t\t\n\t\t \/* Build a second API request to PayPal, using the token as the\n\t\t\tID to get the details on the payment authorization\n\t\t\t*\/\n\t\t   $nvpstr=\"&amp;TOKEN=\".$token;\n\t\n\t\t \/* Make the API call and store the results in an array.  If the\n\t\t\tcall was a success, show the authorization details, and provide\n\t\t\tan action to complete the payment.  If failed, show the error\n\t\t\t*\/\n\t\t   $resArray=paypal_hash_call(\"GetExpressCheckoutDetails\",$nvpstr);\n\n\t\t   $_SESSION['reshash']=$resArray;\n\t\t   $ack = strtoupper($resArray[\"ACK\"]);\n\t\t   if($ack==\"SUCCESS\"){\t\t\t\n\t\t\t\t\n\t\t\t\t\/********************************************************\n\t\t\t\tGetExpressCheckoutDetails.php\n\t\t\t\t\n\t\t\t\tThis functionality is called after the buyer returns from\n\t\t\t\tPayPal and has authorized the payment.\n\t\t\t\t\n\t\t\t\tDisplays the payer details returned by the\n\t\t\t\tGetExpressCheckoutDetails response and calls\n\t\t\t\tDoExpressCheckoutPayment.php to complete the payment\n\t\t\t\tauthorization.\n\t\t\t\t\n\t\t\t\tCalled by ReviewOrder.php.\n\t\t\t\t\n\t\t\t\tCalls DoExpressCheckoutPayment.php and APIError.php.\n\t\t\t\t\n\t\t\t\t********************************************************\/\n\t\t\t\t\n\t\t\t\t\/* Collect the necessary information to complete the\n\t\t\t\tauthorization for the PayPal payment\n\t\t\t\t*\/\n\t\t\t\t\n\t\t\t\t$_SESSION['token']=$_REQUEST['token'];\n\t\t\t\t$_SESSION['payer_id'] = $_REQUEST['PayerID'];\n\t\t\t\t\t\t\n\t\t\t\t$resArray=$_SESSION['reshash'];\n\t\t\t\t\n\t\t\t\tif(get_option('permalink_structure') != '')\n\t\t\t\t\t$separator =\"?\";\n\t\t\t\telse\n\t\t\t\t\t$separator =\"&amp;\";\n\t\t\t\n\t\t\t\t\n\t\t\t\t\/* Display the  API response back to the browser .\n\t\t\t\tIf the response from PayPal was a success, display the response parameters\n\t\t\t\t*\/\n\t\t\t\tif(isset($_REQUEST['TOKEN']) &amp;&amp; !isset($_REQUEST['PAYERID'])){\n\t\t\t\t\t$_SESSION['paypalExpressMessage']= '&lt;h4&gt;TRANSACTION CANCELED&lt;\/h4&gt;';\n\t\t\t\t}else{\n\t\t\t\t\tif ( ! isset( $resArray['SHIPTOSTREET2'] ) )\n\t\t\t\t\t\t$resArray['SHIPTOSTREET2'] = '';\n\t\t\t\t\t$output =\"\n\t\t\t\t       &lt;table width='400' class='paypal_express_form'&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;&lt;b&gt;Order Total:&lt;\/b&gt;&lt;\/td&gt;\n\t\t\t\t            &lt;td align='left'&gt;\" . wpsc_currency_display($_SESSION['localPaypalAmount']) . \"&lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t\t    &lt;td align='left' colspan='2'&gt;&lt;b&gt;\" . __('Shipping Address:', 'wpsc' ) . \" &lt;\/b&gt;&lt;\/td&gt;\n\t\t\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('Street 1:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOSTREET'].\"&lt;\/td&gt;\n\t\t\t\t\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('Street 2:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOSTREET2'].\"\n\t\t\t\t            &lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('City:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOCITY'].\"&lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('State:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOSTATE'].\"&lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('Postal code:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOZIP'].\"&lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td align='left' class='firstcol'&gt;\n\t\t\t\t                \" . __('Country:', 'wpsc' ) . \"&lt;\/td&gt;\n\t\t\t\t            &lt;td align='left'&gt;\".$resArray['SHIPTOCOUNTRYNAME'].\"&lt;\/td&gt;\n\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t        &lt;tr&gt;\n\t\t\t\t            &lt;td colspan='2'&gt;\";\n\t\t\t\t\t\n\t\t\t\t\t$output .= \"&lt;form action=\".get_option('transact_url').\" method='post'&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='totalAmount' value='\".wpsc_cart_total(false).\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='shippingStreet' value='\".$resArray['SHIPTOSTREET'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='shippingStreet2' value='\".$resArray['SHIPTOSTREET2'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='shippingCity' value='\".$resArray['SHIPTOCITY'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='shippingState' value='\".$resArray['SHIPTOSTATE'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='postalCode' value='\".$resArray['SHIPTOZIP'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='country' value='\".$resArray['SHIPTOCOUNTRYNAME'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='token' value='\".$_SESSION['token'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='PayerID' value='\".$_SESSION['payer_id'].\"' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;input type='hidden' name='act' value='do' \/&gt;n\";\n\t\t\t\t\t$output .= \"\t&lt;p&gt;  &lt;input name='usePayPal' type='submit' value='\".__('Confirm Payment','wpsc').\"' \/&gt;&lt;\/p&gt;n\";\n\t\t\t\t\t$output .= \"&lt;\/form&gt;\";\n\t\t\t\t\t$output .=\" &lt;\/td&gt;\n\t\t\t\t\t        &lt;\/tr&gt;\n\t\t\t\t\t    &lt;\/table&gt;\n\t\t\t\t\t&lt;\/center&gt;\n\t\t\t\t\t\";\n\t\t\t\t\t$_SESSION['paypalExpressMessage'] = $output;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\t\n} \n\n\n\nfunction paypal_hash_call($methodName,$nvpStr)\t{\n\t\/\/declaring of variables\n\t$version = 71;\t\t\t\n\tif ( 'sandbox' == get_option('paypal_certified_server_type') ) {\n\t\t$API_Endpoint = \"https:\/\/api-3t.sandbox.paypal.com\/nvp\";\n\t\t$paypal_certified_url  = \"https:\/\/www.sandbox.paypal.com\/webscr?cmd=_express-checkout&amp;useraction=commit&amp;token=\";\n\t} else {\n\t\t$API_Endpoint = \"https:\/\/api-3t.paypal.com\/nvp\";\n\t\t$paypal_certified_url  = \"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_express-checkout&amp;useraction=commit&amp;token=\";\n\t}\n\n\t$USE_PROXY = false;\n\t$API_UserName=get_option('paypal_certified_apiuser');\n\t$API_Password=get_option('paypal_certified_apipass');\n\t$API_Signature=get_option('paypal_certified_apisign');\n\t$sBNCode = \"PP-ECWizard\";\n\t\/\/NVPRequest for submitting to server\n\t$nvpreq=\"METHOD=\" . urlencode($methodName) . \"&amp;VERSION=\" . urlencode($version) . \"&amp;PWD=\" . urlencode($API_Password) . \"&amp;USER=\" . urlencode($API_UserName) . \"&amp;SIGNATURE=\" . urlencode($API_Signature) . $nvpStr . \"&amp;BUTTONSOURCE=\" . urlencode($sBNCode);\n\n\t\/\/ Configure WP_HTTP\n\tif($USE_PROXY) {\n\t\tif (!defined('WP_PROXY_HOST') &amp;&amp; !defined('WP_PROXY_PORT')) {\n\t\t\tdefine('WP_PROXY_HOST', $PROXY_HOST);\n\t\t\tdefine('WP_PROXY_PORT', $PROXY_PORT);\n\t\t}\n\t}\n\tadd_filter('http_api_curl', 'wpsc_curl_ssl');\n\t\n\t$options = array(\n\t\t'timeout' =&gt; 5,\n\t\t'body' =&gt; $nvpreq,\n\t\t'sslverify' =&gt; false,\n\t);\n\t\n\t$nvpReqArray=paypal_deformatNVP($nvpreq);\n\t$_SESSION['nvpReqArray']=$nvpReqArray;\n\t$res = wp_remote_post($API_Endpoint, $options);\n\n\tif ( is_wp_error($res) ) {\n\t\t$_SESSION['curl_error_msg'] = 'WP HTTP Error: ' . $res-&gt;get_error_message();\n\t\t$nvpResArray=paypal_deformatNVP('');\n\t} else {\n\t\t$nvpResArray=paypal_deformatNVP($res['body']);\n\t}\n\n\treturn $nvpResArray;\n}\n\nfunction paypal_deformatNVP($nvpstr) {\n\t$intial=0;\n\t$nvpArray = array();\n\n\twhile(strlen($nvpstr)) {\n\t\t\/\/postion of Key\n\t\t$keypos= strpos($nvpstr,'=');\n\t\t\/\/position of value\n\t\t$valuepos = strpos($nvpstr,'&amp;') ? strpos($nvpstr,'&amp;'): strlen($nvpstr);\n\n\t\t\/*getting the Key and Value values and storing in a Associative Array*\/\n\t\t$keyval=substr($nvpstr,$intial,$keypos);\n\t\t$valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);\n\t\t\/\/decoding the respose\n\t\t$nvpArray[urldecode($keyval)] =urldecode( $valval);\n\t\t$nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));\n\t}\n\treturn $nvpArray;\n}\nadd_action('init', 'paypal_processingfunctions');\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Bonjour, Ceux qui ont tent\u00e9 de faire fonctionner les coupons avec paypal ont du se heurter \u00e0 quelques soucis. Voici une solution : Remplacer le contenu de \u00a0wpsc-merchants\/paypal-express.merchant.php par : &lt;?php \/** * This is the PayPal Certified 2.0 Gateway. * It uses the wpsc_merchant class as a base class which is handy for collating [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[8],"tags":[21,35,63,87],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-wpcb","tag-coupon","tag-express-checkout","tag-paypal","tag-wpec"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":0,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"wp:attachment":[{"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}