{"id":444,"date":"2012-02-13T14:52:41","date_gmt":"2012-02-13T12:52:41","guid":{"rendered":"http:\/\/wpcb.fr\/?p=444"},"modified":"2012-02-13T14:52:41","modified_gmt":"2012-02-13T12:52:41","slug":"paypal-pour-wordpress","status":"publish","type":"post","link":"https:\/\/rationalk.ch\/blog\/paypal-pour-wordpress\/","title":{"rendered":"Paypal pour WordPress avec un formulaire personalis\u00e9"},"content":{"rendered":"<p>Bonjour,<br \/>\nCi dessous un petit guide pour transformer votre site wordpress en e-boutique sans utiliser le plugin wp-e-commerce.<br \/>\nEn plus de cr\u00e9er un boutton paypal, cela vous cr\u00e9e un formulaire pour demander plus d&rsquo;informations \u00e0 l&rsquo;acheteur comme la taille, la couleur du produits, son signe astrologique, etc.<\/p>\n<p>Fonctionnement g\u00e9n\u00e9ral :<\/p>\n<p>Vous placer un shortcode sur les pages de votre site ou vous voulez faire apparaitre un bouton paypal. Exemple, je vends une guitare en plastique \u00e0 8.35\u20ac, cela donne : [PaypalBuyNowButton item_name=\u00a0\u00bbGuitare en plastique\u00a0\u00bb amount=\u00a0\u00bb8.35&Prime;]<\/p>\n<p>Le code suivant est \u00e0 placer dans le fichier functions.php :<\/p>\n<pre>function my_scripts_method() {\n\u00a0\u00a0\u00a0 wp_deregister_script( 'joinFields' );\n\u00a0\u00a0\u00a0 wp_register_script( 'joinFields', '<span style=\"color: #3366ff;\">http:\/\/www.votre-site.fr<\/span>\/wp-content\/themes\/<span style=\"color: #3366ff;\">votre-theme<\/span>\/joinFields.js');\n\u00a0\u00a0\u00a0 wp_enqueue_script( 'joinFields' );\n}\u00a0\u00a0 \u00a0\nadd_action('wp_enqueue_scripts', 'my_scripts_method');\n\nfunction PaypalBuyNowButton($atts){\n\u00a0 global $wpdb, $post;\n\u00a0 extract( shortcode_atts( array('item_name' =&gt; 'Prevision astrale','amount' =&gt; '0.10'), $atts));\n\u00a0 \/\/$Output.='&lt;a href=\"#\" onclick=\"joinFields()\"&gt;joinFields&lt;\/a&gt;';\n\u00a0 \/\/print_r($atts);\n\u00a0 $Output.='&lt;form action=\"https:\/\/www.paypal.com\/cgi-bin\/webscr\" method=\"post\" name=\"fmBuy\" id=\"fmBuy\" onSubmit=\"joinFields()\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"cmd\" value=\"_xclick\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"business\" value=\"votreemailebay@hotmail.com\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"lc\" value=\"FR\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"item_name\" value=\"'.$item_name.'\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"amount\" value=\"'.$amount.'\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"currency_code\" value=\"EUR\"&gt;\n\u00a0 &lt;INPUT TYPE=\"hidden\" name=\"charset\" value=\"utf-8\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"button_subtype\" value=\"services\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"no_note\" value=\"1\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"no_shipping\" value=\"1\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"rm\" value=\"1\"&gt;\n\u00a0 &lt;p&gt;Votre nom&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"nom\" name=\"nom\" value=\"'.$keyarray['last_name'].'\" size=\"40\" \/&gt;&lt;\/span&gt; &lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre pr\u00e9nom&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"prenom\" name=\"prenom\" value=\"'.$keyarray['first_name'].'\" size=\"40\" \/&gt;&lt;\/span&gt; &lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre date de naissance&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"datedenaissance\" name=\"datedenaissance\" value=\"\" size=\"40\" \/&gt;&lt;\/span&gt; &lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre heure de naissance&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"heuredenaissance\" name=\"heuredenaissance\" value=\"\" size=\"40\" \/&gt;&lt;\/span&gt; &lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre lieu de naissance&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"lieudenaissance\" name=\"lieudenaissance\" value=\"\" size=\"40\" \/&gt;&lt;\/span&gt; &lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre email&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"email\" name=\"email\" value=\"'.$keyarray['payer_email'].'\" size=\"40\" \/&gt;&lt;\/span&gt;&lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre num\u00e9ro de t\u00e9l\u00e9phone&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"telephone\" name=\"telephone\" value=\"\" size=\"40\" \/&gt;&lt;\/span&gt;&lt;\/p&gt;\n\u00a0 &lt;p&gt;Votre adresse postale compl\u00e8te&lt;br \/&gt;\n\u00a0 &lt;input type=\"text\" id=\"adresse\" name=\"adresse\" value=\"\" size=\"100\" \/&gt;&lt;\/span&gt;&lt;\/p&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"custom\" id=\"custom\" value=\"\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"return\" value=\"<span style=\"color: #3366ff;\">http:\/\/www.votre-site.fr<\/span>\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"cancel_return\" value=\"<span style=\"color: #3366ff;\">http:\/\/www.votre-site.fr<\/span>\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"notify_url\" value=\"http:\/\/www.louisette-astro.fr\/paypal_ipn.php\"&gt;\n\u00a0 &lt;input type=\"hidden\" name=\"bn\" value=\"PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted\"&gt;\n\u00a0 &lt;input type=\"image\" src=\"https:\/\/www.paypalobjects.com\/fr_FR\/FR\/i\/btn\/btn_buynowCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - la solution de paiement en ligne la plus simple et la plus s\u00e9curis\u00e9e !\"&gt;\n\u00a0 &lt;img alt=\"\" border=\"0\" src=\"https:\/\/www.paypalobjects.com\/fr_FR\/i\/scr\/pixel.gif\" width=\"1\" height=\"1\"&gt;\n\u00a0 &lt;\/form&gt;';\n\u00a0 return $Output;\n}\nadd_shortcode( 'PaypalBuyNowButton', 'PaypalBuyNowButton' );<\/pre>\n<p>Ensuite il faut cr\u00e9er le fichier javascript joinFields.js qui va concat\u00e9ner les elements du formulaire :<\/p>\n<pre>function joinFields(){\n\u00a0var nom = document.getElementById('nom').value;\n\u00a0var prenom = document.getElementById('prenom').value;\n\u00a0var datedenaissance = document.getElementById('datedenaissance').value;\n\u00a0var heuredenaissance = document.getElementById('heuredenaissance').value;\n\u00a0var lieudenaissance = document.getElementById('lieudenaissance').value;\n\u00a0var email = document.getElementById('email').value;\n\u00a0var telephone = document.getElementById('telephone').value;\n\u00a0var adresse = document.getElementById('adresse').value;\n\u00a0var req=nom+'&amp;'+prenom+'&amp;'+datedenaissance+'&amp;'+heuredenaissance+'&amp;'+lieudenaissance+'&amp;'+email+'&amp;'+telephone+'&amp;'+adresse;\n\u00a0var custom = document.getElementById('custom');\n\u00a0custom.value=req;\n\u00a0 }<\/pre>\n<p>Le troisi\u00e8me fichier paypal_ipn.php est \u00e0 placer \u00e0 la racine de votre site :<\/p>\n<pre>&lt;?php\n\nerror_reporting(E_ALL ^ E_NOTICE);\n$emailtext = \"\";\n\/\/ Read the post from PayPal and add 'cmd'\n$req = 'cmd=_notify-validate';\nif(function_exists('get_magic_quotes_gpc')){$get_magic_quotes_exits = true;}\nforeach ($_POST as $key =&gt; $value)\n\/\/ Handle escape characters, which depends on setting of magic quotes\n\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0if($get_magic_quotes_exists == true &amp;&amp; get_magic_quotes_gpc() == 1)\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{$value = urlencode(stripslashes($value));}\n\u00a0\u00a0 \u00a0else {$value = urlencode($value);}\n\u00a0\u00a0 \u00a0$req .= \"&amp;$key=$value\";\n\u00a0\u00a0 \u00a0}\n\/\/ Post back to PayPal to validate\n$header .= \"POST \/cgi-bin\/webscr HTTP\/1.0rn\";\n$header .= \"Content-Type: application\/x-www-form-urlencodedrn\";\n$header .= \"Content-Length: \" . strlen($req) . \"rnrn\";\n$fp = fsockopen ('ssl:\/\/www.paypal.com', 443, $errno, $errstr, 30);\n\n\/\/ Process validation from PayPal\nif (!$fp)\n\u00a0\u00a0 \u00a0{ \/\/ HTTP ERROR\n\u00a0\u00a0 \u00a0}\nelse\n\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\/\/ NO HTTP ERROR\n\u00a0\u00a0 \u00a0fputs ($fp, $header . $req);\n\u00a0\u00a0 \u00a0while (!feof($fp))\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$res = fgets ($fp, 1024);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (strcmp ($res, \"VERIFIED\") == 0)\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ Check the payment_status is Completed\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if ($_POST['payment_status']=='Completed')\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Bonjour,'.\"n\".'Nous avons re\u00e7u votre commande '.\"n\".'D\u00e9tails de votre demande :'.\"n\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Type de demande : '.$_POST['item_name'].\"n\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$custom = explode(\"&amp;\",$_POST['custom']);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Nom : '.$custom[0].\"n\".'Pr\u00e9nom : '.$custom[1].\"n\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Date de naissance :'.$custom[2].\"n\".'Heure de naissance :'.$custom[3].\"n\".'Lieu de naissance :'.$custom[4].\"n\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$email=$custom[5];\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Email : '.$email.\"n\".'T\u00e9l\u00e9phone : '.$custom[6].\"n\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$emailtext.='Adresse : '.$custom[7].\"nn\";\n\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0foreach ($_POST as $key =&gt; $value)\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/$emailtext .= $key . \" = \" .$value .\"nn\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\n\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$headers\u00a0 = 'MIME-Version: 1.0' . \"rn\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$headers .= 'Content-type: text\/plain; charset=utf-8' . \"rn\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$headers .= 'From: Vous &lt;nepasrepondre@<span style=\"color: #3366ff;\">votre-site.fr<\/span>&gt;' . \"rn\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$headers .= 'Bcc: <span style=\"color: #3366ff;\">votre-email<\/span>@hotmail.com' . \"rn\";\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mail($email, \"Accus\u00e9 de reception de votre commande\", $emailtext,$headers);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\/\/End if completed\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else if (strcmp ($res, \"INVALID\") == 0)\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0foreach ($_POST as $key =&gt; $value){$emailtext .= $key . \" = \" .$value .\"nn\"; }\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mail('<span style=\"color: #3366ff;\">votre-email<\/span>@hotmail.com', \"Live-INVALID IPN at astro\", $emailtext . \"nn\" . $req);\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0} \u00a0\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0fclose ($fp);\n\u00a0\u00a0 \u00a0}\n?&gt;<\/pre>\n<p>Enfin il est important de bien r\u00e9gler vos options de paypal, notamment pour l&rsquo;ipn :<br \/>\nPaypal -&gt; Pr\u00e9f\u00e9rences -&gt; Plus d&rsquo;options -&gt; Mes outils de vente -&gt; Notifications instantan\u00e9es de paiement<br \/>\n(ou directement : https:\/\/www.paypal.com\/cgi-bin\/customerprofileweb?cmd=_profile-ipn-notify)<\/p>\n<figure id=\"attachment_445\" aria-describedby=\"caption-attachment-445\" style=\"width: 795px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/wpcb.fr\/wp-content\/uploads\/2012\/02\/ipn_paypal.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-445\" title=\"Paypal R\u00e9glage IPN\" src=\"https:\/\/i0.wp.com\/wpcb.fr\/wp-content\/uploads\/2012\/02\/ipn_paypal.png?resize=580%2C414\" alt=\"Paypal R\u00e9glage IPN\" width=\"580\" height=\"414\" \/><\/a><figcaption id=\"caption-attachment-445\" class=\"wp-caption-text\">Paypal R\u00e9glage IPN<\/figcaption><\/figure>\n<p><em>Note : La somme des champs r\u00e9ponses (nom, pr\u00e9noms, &#8230;) ne peut d\u00e9passer 256 caract\u00e8res (limitation de cette technique). Si besoin de plus de caract\u00e8res, utiliser une base de donn\u00e9es ou wpec.<\/em><\/p>\n<p>Todo :<\/p>\n<ul>\n<li>int\u00e9grer dans un plugin.<\/li>\n<li>le lier \u00e0 un plugin type contact form 7 pour ne pas avoir a cr\u00e9er le formulaire en dur<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Bonjour, Ci dessous un petit guide pour transformer votre site wordpress en e-boutique sans utiliser le plugin wp-e-commerce. En plus de cr\u00e9er un boutton paypal, cela vous cr\u00e9e un formulaire pour demander plus d&rsquo;informations \u00e0 l&rsquo;acheteur comme la taille, la couleur du produits, son signe astrologique, etc. Fonctionnement g\u00e9n\u00e9ral : Vous placer un shortcode sur [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","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":[7],"tags":[47,63,86],"class_list":["post-444","post","type-post","status-publish","format-standard","hentry","category-web","tag-ipn","tag-paypal","tag-wordpress"],"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\/444","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=444"}],"version-history":[{"count":0,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"wp:attachment":[{"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rationalk.ch\/blog\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}