Bonjour,


Configuration WordPress / woocommerce
- Version de WordPress : 3.5
- Thème utilisé : Wootique
- Extensions : woocommerce 2.0
- Extensions : wc-paybox-gateway
- Hebergeur : 1&1 / linux


Je souhaite installer une solution de paiement avec PayBox.
J'ai trouvé un plugin woocommerce/wordPress à cette adresse : https://github.com/swoelffel/woocommerce-paybox-gateway

J'ai adapté l'ensemble à mon site et cela fonctionne mode test (envoie vers paybox - paiement - retour).

Mais :

- Au retour le panier n'est pas vidé / la commande reste en attente

De ce que je comprends (je ne suis pas une pro du php... Dommage!) c'est la fonction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
function check_response()
qui n'est pas prise en compte et le hook
Code : Sélectionner tout - Visualiser dans une fenêtre à part
(  add_filter('woocommerce_payment_gateways', 'add_paybox_commerce_gateway')
n'ont plus...

Ça fait une semaine que je cherche une solution sans résultat à ce jour.
Si vous avez une solution?

De même, si l'un de vous a déjà installé PayBox sur woocommerce et que tout fonctionne, je suis curieuse de connaitre votre méthode.

Une autre info qui peut être liée à ce pb : Dans le panneau de config woocommerce >> passerelle de paiement, lorsque je souhaite modifier les paramètres de la PayBox (par exemple son nom), le système m'affiche bien "Vos paramètres ont été enregistrés." mais aucune modification n'est enregistré ( j'ai tout inscrit en dur dans le code..)

Le code :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
/**
* Plugin Name: WooCommerce Paybox Payment Gateway
* Plugin URI: <a href="http://www.castelis.com/woocommerce/" target="_blank">http://www.castelis.com/woocommerce/</a>
* Description: Gateway e-commerce pour Paybox.
* Version: 0.1.0
* Author: Castelis
* Author URI: <a href="http://www.castelis.com/" target="_blank">http://www.castelis.com/</a>
* License: GPL version 2 or later - <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" target="_blank">http://www.gnu.org/licenses/old-licenses/gpl-2.0.html</a>
*
* @package WordPress
* @author Castelis
* @since 0.1.0
*/
add_action('plugins_loaded', 'woocommerce_paybox_init', 0);
function woocommerce_paybox_init() {
 
    if (!class_exists('WC_Payment_Gateway')) {
        return;
    };
 
    DEFINE('PLUGIN_DIR', plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)) . '/');
 
    /*
* Inspire Commerce Gateway Class
*/
 
    class WC_Paybox extends WC_Payment_Gateway {
 
        function __construct() {
            $this->id = 'paybox';
            $this->icon = PLUGIN_DIR . 'images/paybox.png';
            $this->has_fields = false;
            $this->method_title = __('PayBox', 'woocommerce');
            // Load the settings.
            $this->init_form_fields();
            $this->init_settings();
            // Get setting values
            foreach ($this->settings as $key => $val)
                $this->$key = $val;
            // Logs
            if ($this->debug == 'yes')
                $this->log = $woocommerce->logger();
            // Ajout des Hooks
            add_action('init', array(&$this, 'check_response'));
//add_action('woocommerce_api_callback', array(&$this, 'check_response'));
            // !!!!!!!!!!!
            add_action('woocommerce_update_options_payment_gateways_', array(&$this, 'process_admin_options'));
            add_action('woocommerce_thankyou_paybox', array(&$this, 'thankyou_page'));
        }
 
        /**
* Reponse Paybox (Pour le serveur Paybox)
*
* @access public
* @return void
*/
        function check_response() {
 
/*
//////////////////////////////////////////////////////////
$wp_root_path = str_replace('/wp-content/themes', '', dirname(__FILE__));
$filename = $wp_root_path.'/autoresponse.txt';
$date = new DateTime();
$somecontent = "\n".$date->format(DateTime::W3C);
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'a+')) {
         exit;
    }
    if (fwrite($handle, $somecontent) === FALSE) {
        exit;
    }
    fclose($handle);
}
//////////////////////////////////////////////////////////
*/
 
            $order = new WC_Order((int) $_GET['order']); // On récupère la commande
            if ($order) {
                $pos_qs = strpos($_SERVER['REQUEST_URI'], '?');
                $pos_sign = strpos($_SERVER['REQUEST_URI'], '&sign=');
                $return_url = substr($_SERVER['REQUEST_URI'], 1, $pos_qs - 1);
                $data = substr($_SERVER['REQUEST_URI'], $pos_qs + 1, $pos_sign - $pos_qs - 1);
                $sign = substr($_SERVER['REQUEST_URI'], $pos_sign + 6);
                // Est-on en réception d'un retour PayBox
                if (str_replace('//', '/', '/' . $return_url) == str_replace('//', '/', $this->return_url)) {
                    $std_msg = 'Paybox Return IP:' . WC_Paybox::getRealIpAddr() . '<br/>' . $data . '<br/><div style="word-wrap:break-word;">PBX Sign : ' . $sign . '<div>';
                    @ob_clean();
                    // Traitement du retour PayBox
                    // PBX_RETOUR=order:R;erreur:E;carte:C;numauto:A;numtrans:S;numabo:B;montantbanque:M;sign:K
                    // paybox_log($_GET);
                    switch ($_GET['erreur']) {
                        case '00000':
                            // OK Pad de pb
                            // On vérifie la clef
                            // recuperation de la cle publique
                            $fp = $filedata = $key = FALSE;
                            $fsize = filesize(dirname(__FILE__) . '/lib/pubkey.pem');
                            $fp = fopen(dirname(__FILE__) . '/lib/pubkey.pem', 'r');
                            $filedata = fread($fp, $fsize);
                            fclose($fp);
                            $key = openssl_pkey_get_public($filedata);
                            $decoded_sign = base64_decode(urldecode($sign));
                            $verif_sign = openssl_verify($data, $decoded_sign, $key);
                            if ($verif_sign == 1) { // La commande est bien signé par PayBox
                                // Si montant ok
                                if ((int) (100 * $order->get_total()) == (int) $_GET['montantbanque']) {
                                    $order->add_order_note('<b>Paybox Return OK</b><br/>' . $std_msg);
                                    $order->payment_complete();
                                    header('HTTP/1.1 200 OK');
                                    wp_die('OK');
                                } else {
                                    $order->add_order_note('<p style="color:red"><b>ERROR</b></p> Order Amount<br/>' . $std_msg);
                                    header('HTTP/1.1 406');
                                    wp_die('KO Amount modified : ' . $_GET['montantbanque'] . ' / ' . (100 * $order->get_total()));
                                }
                            } else {
                                $order->add_order_note('<p style="color:red"><b>ERROR</b></p> Signature Rejected<br/>' . $std_msg);
                                header('HTTP/1.1 406');
                                wp_die('KO Signature');
                            }
                            break;
                        default:
                            $order->add_order_note('<p style="color:red"><b>PBX ERROR ' . $_GET['erreur'] . '</b> ' . WC_Paybox::getErreurMsg($_GET['erreur']) . '</p><br/>' . $std_msg);
                            header('HTTP/1.1 200 OK');
                            wp_die('OK received');
                            break;
                    }
                }
            } else {
                header('HTTP/1.1 200 OK');
                wp_die('KO Unknown order : ' . $_GET['order']);
            }
        }
 
        /**
* Retour Paybox
*
* @access public
* @param array $posted
* @return void
*/
        function thankyou_page($posted) {
            global $woocommerce;
            //error_log('thankyou_page');
            // Pour le moment on ne fait rien
        }
 
        /*
* Initialize Gateway Settings Form Fields.
*/
 
        function init_form_fields() {
 
            $this->form_fields = array(
                'enabled' => array(
                    'title' => __('Enable/Disable', 'woocommerce'),
                    'type' => 'checkbox',
                    'label' => __('Enable Paybox Payment', 'woocommerce'),
                    'default' => 'yes'
                ),
                'title' => array(
                    'title' => __('Title', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Cela contrôle le titre que l'utilisateur voit lors de sa commande.', 'woocommerce'),
                    'default' => __('Carte bancaire', 'woocommerce')
                ),
                'description' => array(
                    'title' => __('Customer Message', 'woocommerce'),
                    'type' => 'textarea',
                    'description' => __('Let the customer know the payee and where they should be sending the Paybox to and that their order won\'t be shipping until you receive it.', 'woocommerce'),
                    'default' => __('Les cartes acceptées sont la Visa, la Mastercard, la Carte Bleue ou Eurocard. Dès que vous cliquez sur le bouton "Payer" disponible sur votre bon de commande, vous serez automatiquement dirigé vers l'espace de paiement sécurisé de notre partenaire financier.', 'woocommerce')
                ),
                'paybox_site_id' => array(
                    'title' => __('Site ID Paybox', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter you ID Site provided by PayBox.', 'woocommerce'),
                    'default' => '1234567'
                ),
                'paybox_identifiant' => array(
                    'title' => __('Paybox ID', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter you Paybox ID provided by PayBox.', 'woocommerce'),
                    'default' => '123456789'
                ),
                'paybox_rang' => array(
                    'title' => __('Paybox Rank', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter Paybox Rank provided by PayBox.', 'woocommerce'),
                    'default' => '01'
                ),
                'paybox_key' => array(
                    'title' => __('Paybox Key', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter Paybox Key provided by PayBox.', 'woocommerce'),
                    'default' => 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDe+hkicNP7ROHUssGNtHwiT2EwHFrSk/qwrcq8v5metRtTTFPE/nmzSkRnTs3GMpi57rBdxBBJW5W9cpNyGUh0jNXcVrOSClpD5Ri2hER/GcNrxVRP7RlWOqB1C03q4QYmwjHZ+zlM4OUhCCAtSWflB4wCKa1g88CjFwRw/PB9kwIDAQAB'
                ),
                'return_url' => array(
                    'title' => __('Paybox return URL', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter the autoreponse URL for PayBox.', 'woocommerce'),
                    /*'default' => '/paybox-autoresponse/'*/
                    //'default' => '/?wc-api=WC_Paybox'
                     'default' => '/information-paiement-accepte/'
                ),
                'back_url' => array(
                    'title' => __('Return Link', 'woocommerce'),
                    'type' => 'text',
                    'description' => __('Please enter back link from PayBox (where you need to put the [im4woo_thankyou] shortcode).', 'woocommerce'),
                    'default' => '/information-paiement-accepte/'
                ),
                'prepost_message' => array(
                    'title' => __('Customer Message', 'woocommerce'),
                    'type' => 'textarea',
                    'description' => __('Message to the user before redirecting to PayBox.', 'woocommerce'),
                    'default' => __('Vous allez être redirigé vers le paiement sécurisé Paybox dans quelques secondes. ...Merci de patienter.', 'woocommerce')
                ),
                /*
'os' => array(
'title' => __('Choose your OS', 'woocommerce'),
'type' => 'select',
'label' => __('Choose your OS', 'woothemes'),
'description' => __(''),
'options' => array(
'win' => 'Windows',
'lin' => 'Linux',
'lin64' => 'Linux 64bits',
'unix' => 'Unix',
'deb64' => 'Debian 64bits',
'fed64' => 'Fedora 64bits',
'sunsolaris' => 'Sun solaris',
'linuxcentos' => 'Linux centos',
'freebsd' => 'Free bsd',
'macos' => 'Mac OS',
'ubuntu' => 'Ubuntu',
)
), */
                'paybox_exe' => array(
                    'title' => __('Complete path to PayBox CGI', 'woocommerce'),
                    'type' => 'textarea',
                    'description' => __('Location for Paybox executable (<a href="http://www1.paybox.com/telechargement_focus.aspx?cat=3" target="_blank">http://www1.paybox.com/telechargement_focus.aspx?cat=3</a>).', 'woocommerce'),
                    'default' => __('adressePhysique/cgi-bin/modulev2.cgi', 'woocommerce')
                )
            );
        }
 
        /**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
        function process_payment($order_id) {
            //error_log('Call : process_payment');
            $order = new WC_Order($order_id);
            $paybox_form = $this->getParamPaybox($order);
            //error_log($paybox_form);
            $retour = '<p>' . $this->prepost_message . '</p>' . $paybox_form . "\r\n" . '
<script>
function launchPaybox() {
document.PAYBOX.submit();
}
t=setTimeout("launchPaybox()",5000);
</script>
';
            wp_die($retour);
        }
        function getParamPaybox(WC_Order $order) {
            $param = '';
            $param .= 'PBX_MODE=4'; //envoi en ligne de commande
            $param .= ' PBX_OUTPUT=B';
 
            $param .= ' PBX_SITE=' . $this->paybox_site_id;
            $param .= ' PBX_IDENTIFIANT=' . $this->paybox_identifiant;
            $param .= ' PBX_RANG=' . $this->paybox_rang;
            $param .= ' PBX_TOTAL=' . 100 * $order->get_total();
            $param .= ' PBX_CMD=' . $order->id;
            //$param .= ' PBX_CLE=' . $this->paybox_key;
            $param .= ' PBX_REPONDRE_A=http://' . str_replace('//', '/', $_SERVER['HTTP_HOST'] . '/' . $this->return_url);
            $param .= ' PBX_EFFECTUE=http://' . str_replace('//', '/', $_SERVER['HTTP_HOST'] . '/' . $this->back_url);
            $param .= ' PBX_REFUSE=http://' . str_replace('//', '/', $_SERVER['HTTP_HOST'] . '/' . $this->back_url);
            $param .= ' PBX_ANNULE=http://' . str_replace('//', '/', $_SERVER['HTTP_HOST'] . '/' . $this->back_url);
            $param .= ' PBX_DEVISE=978'; // Euro (à paramétriser)
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $param .= ' PBX_RETOUR=order:R;erreur:E;carte:C;numauto:A;numtrans:S;numabo:B;montantbanque:M;sign:K';
            } else { //pour linux
                $param .= ' PBX_RETOUR=order:R\\;erreur:E\\;carte:C\\;numauto:A\\;numtrans:S\\;numabo:B\\;montantbanque:M\\;sign:K';
            }
            $email_address = $order->billing_email;
            if (empty($email_address) || !is_email($email_address)) {
                $ids = $wpdb->get_result("SELECT wp_users.ID FROM wp_users WHERE (SELECT wp_usermeta.meta_value FROM wp_usermeta WHERE wp_usermeta.user_id = wp_users.ID AND wp_usermeta.meta_key = 'wp_capabilities') LIKE '%administrator%'");
                if ($ids) {
                    $current_user = get_user_by('id', $ids[0]);
                    $email_address = $current_user->user_mail;
                }
            }
            $param .= ' PBX_PORTEUR=' . $email_address; //. $order->customer_user;
            $exe = $this->paybox_exe;
            if (file_exists($exe)) {
                error_log($exe . ' ' . $param);
                $retour = shell_exec($exe . ' ' . $param);
                if ($retour != '') {
                    return $retour;
                } else {
                    return _('Permissions are not correctly set for file ' . $exe);
                }
            } else {
                return _('Paybox CGI module can not be found');
            }
        }
 
        static function getRealIpAddr() {
            if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet
                $ip = $_SERVER['HTTP_CLIENT_IP'];
            } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy
                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } else {
                $ip = $_SERVER['REMOTE_ADDR'];
            }
            return $ip;
        }
 
        static function getErreurMsg($code_erreur) {
            $ErreurMsg = _('No Message');
            if ($code_erreur == '00000')
                $ErreurMsg = 'Opération réussie.';
            if ($code_erreur == '00011')
                $ErreurMsg = 'Montant incorrect.';
            if ($code_erreur == '00001')
                $ErreurMsg = 'La connexion au centre d\'autorisation a échoué. Vous pouvez dans ce cas là effectuer les redirections des internautes vers le FQDN tpeweb1.paybox.com.';
            if ($code_erreur == '00015')
                $ErreurMsg = 'Paiement déjà effectué.';
            if ($code_erreur == '001')
                $ErreurMsg = 'Paiement refusé par le centre d\'autorisation. En cas d\'autorisation de la transaction par le centre d\'autorisation de la banque, le code erreur \'00100\' sera en fait remplacé directement par \'00000\'.';
            if ($code_erreur == '00016')
                $ErreurMsg = 'Abonné déjà existant (inscription nouvel abonné). Valeur \'U\' de la variable PBX_RETOUR.';
            if ($code_erreur == '00003')
                $ErreurMsg = 'Erreur Paybox.';
            if ($code_erreur == '00021')
                $ErreurMsg = 'Carte non autorisée.';
            if ($code_erreur == '00004')
                $ErreurMsg = 'Numéro de porteur ou cryptogramme visuel invalide.';
            if ($code_erreur == '00029')
                $ErreurMsg = 'Carte non conforme. Code erreur renvoyé lors de la documentation de la variable « PBX_EMPREINTE ».';
            if ($code_erreur == '00006')
                $ErreurMsg = 'Accès refusé ou site/rang/identifiant incorrect.';
            if ($code_erreur == '00030')
                $ErreurMsg = 'Temps d\'attente > 15 mn par l\'internaute/acheteur au niveau de la page de paiements.';
            if ($code_erreur == '00008')
                $ErreurMsg = 'Date de fin de validité incorrecte.';
            if ($code_erreur == '00031')
                $ErreurMsg = 'Réservé';
            if ($code_erreur == '00009')
                $ErreurMsg = 'Erreur de création d\'un abonnement.';
            if ($code_erreur == '00032')
                $ErreurMsg = 'Réservé';
            if ($code_erreur == '00010')
                $ErreurMsg = 'Devise inconnue.';
            if ($code_erreur == '00033')
                $ErreurMsg = 'Code pays de l\'adresse IP du navigateur de l\'acheteur non autorisé.';
            return $ErreurMsg;
        }
 
    }
 
    // Fin de la classe
 
    /*
* Ajout de la "gateway" Paybox à woocommerce
*/
 
    function add_paybox_commerce_gateway($methods) {
        echo 'pop';
        $methods[] = 'WC_Paybox';
        return $methods;
    }
 
    include_once('shortcode-im4woo-thankyou.php');
    add_shortcode('im4woo_thankyou', 'get_im4woo_thankyou');
 
    add_filter('woocommerce_payment_gateways', 'add_paybox_commerce_gateway');
 
    //add_action('woocommerce_api_callback', 'callback_handler');
} 
?>