3f40979170b7d8eb239d18f01992c0adca78a44a
[platal.git] / modules / payment / money / bplccyberplus.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 /*
23 Numéros de cartes de test :
24 Commerçant non enrôlé 3D-Secure
25 4970 1000 0000 0003 Paiement accepté (autorisation accordée)
26 Commerçant enrôlé 3D-Secure
27 4970 1000 0000 0000 Paiement accepté avec authentification internaute
28 4970 1000 0000 0001 Paiement accepté sans authentification internaute (Internaute non enrôlé 3D-Secure)
29 4970 1000 0000 0002 contacter l'émetteur de carte (Transaction à forcer). Authentification réalisée avec succès.
30 4970 1000 0000 0006 Problème technique lors du calcul de la garantie de paiement
31 4970 1000 0000 0007 Problème technique lors de l’authentification porteur
32 4970 1000 0000 0097 Paiement refusé pour cause d’authentification 3D-Secure échouée (l'internaute n'est pas parvenu à s'authentifier)
33 4970 1000 0000 0098 Paiement refusé (autorisation refusée pour cause de plafond dépassé)
34 4970 1000 0000 0099 Paiement refusé (autorisation refusée suite à erreur dans le cryptogramme visuel saisi)
35 */
36
37 class BPLCCyberPlus
38 {
39 // {{{ properties
40
41 var $val;
42
43 var $urlform;
44 var $nomsite = "la BP Lorraine Champagne";
45 var $infos;
46
47 // }}}
48 // {{{ constructor
49
50 function BPLCCyberPlus($val)
51 {
52 // SVA : nombre de chiffres après la virgule dépendant de currency ?
53 $this->val = 100 * strtr(sprintf("%.02f", (float)$val), '.', ',');
54 }
55
56 // }}}
57 // {{{ function form()
58
59 function prepareform(&$pay)
60 {
61 global $globals, $platal;
62 $log = S::v('log');
63
64 // on constuit la reference de la transaction
65 $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
66 $fullref = substr("$prefix-{$pay->id}",-12); // FIXME : check for duplicates
67 $ts = time();
68 $trans_date = date("YmdHis", $ts);
69 $trans_id = date("His", $ts); // FIXME : check for duplicates
70
71 // contenu du formulaire
72 $this->urlform = "https://systempay.cyberpluspaiement.com/vads-payment/";
73 $this->infos['commercant'] = Array(
74 'vads_site_id' => $globals->money->cyperplus_account,
75 'vads_return_mode' => 'NONE',
76 'vads_url_return' => $pay->url ? $pay->url : $globals->baseurl . '/' . $platal->ns);
77 $this->infos['client'] = Array(
78 'vads_cust_email' => S::user()->bestEmail(),
79 'vads_cust_id' => S::v('uid'),
80 'vads_cust_name' => replace_accent(S::user()->fullName()));
81 $this->infos['commande'] = Array(
82 'vads_amount' => $this->val,
83 'vads_currency' => '978', # Euro
84 'vads_payment_config' => 'SINGLE',
85 'vads_trans_date' => $trans_date,
86 'vads_trans_id' => $trans_id,
87 'vads_order_id' => $fullref,
88 'vads_order_info' => Env::v('comment'));
89 $this->infos['divers'] = Array(
90 'vads_version' => 'V2',
91 'vads_ctx_mode' => $globals->money->cyperplus_prod,
92 'vads_page_action' => 'PAYMENT',
93 'vads_action_mode' => 'INTERACTIVE');
94
95 // calcul de la clé d'acceptation en entrée
96 $all_params = array_merge($this->infos['commercant'],$this->infos['client'],$this->infos['commande'],$this->infos['divers']);
97 ksort($all_params);
98 $this->infos['divers']['signature'] = sha1(join('+',$all_params).'+'.$globals->money->cyperplus_key);
99 }
100
101 // }}}
102 }
103
104 $api = 'BPLCCyberPlus';
105
106 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
107 ?>