Add mailing list headers to newsletters
[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 /** Card numbers for tests.
23 * Non 3D-Secure shop:
24 * 4970 1000 0000 0003 Payment accepted (authorized)
25 * 3D-Secure shop:
26 * 4970 1000 0000 0000 Payment accepted, with user authentication.
27 * 4970 1000 0000 0001 Payment accepted, without user authentication (non 3D-Secure user).
28 * 4970 1000 0000 0002 Must contact card issuer (which must force transaction). Succesful authentication.
29 * 4970 1000 0000 0006 Technical issue while computing payment warranty.
30 * 4970 1000 0000 0007 Technical issue during user authentication.
31 * 4970 1000 0000 0097 Payment refused due to 3D-Secure authentication failure (user failed to authenticate).
32 * 4970 1000 0000 0098 Payment refused (user credit limit overrun).
33 * 4970 1000 0000 0099 Payment refused (invalid credit card visual cryptogramm).
34 */
35
36 class BPLCCyberPlus
37 {
38 // {{{ properties
39
40 var $val;
41
42 var $urlform;
43 var $nomsite = "la BP Lorraine Champagne";
44 var $infos;
45
46 // }}}
47 // {{{ constructor
48
49 function BPLCCyberPlus($val)
50 {
51 // Improvement: number of digits after the coma might depend from the currency.
52 $this->val = 100 * strtr($val, ',', '.');
53 }
54
55 // }}}
56 // {{{ function form()
57
58 private static function replaceNonAlpha($string)
59 {
60 return trim(preg_replace('/\s\s+/', ' ', preg_replace('/[^a-zA-Z0-9]/', ' ', $string)));
61 }
62
63 function prepareform($pay, $user)
64 {
65 global $globals, $platal;
66 $log = S::v('log');
67
68 // Transaction's reference computation.
69 $prefix = rand_url_id();
70 $fullref = substr("$prefix-{$pay->id}",-12); // FIXME : check for duplicates
71 $ts = time();
72 $trans_date = gmdate("YmdHis", $ts);
73 $trans_id = gmdate("His", $ts); // FIXME : check for duplicates
74
75 // Form's content.
76 $this->urlform = "https://systempay.cyberpluspaiement.com/vads-payment/";
77 $this->infos['commercant'] = Array(
78 'vads_site_id' => $globals->money->cyperplus_account,
79 'vads_return_mode' => 'NONE',
80 'vads_url_return' => $pay->url ? $pay->url : $globals->baseurl . '/' . $platal->ns);
81 $this->infos['client'] = Array(
82 'vads_cust_email' => $user->bestEmail(),
83 'vads_cust_id' => $user->id(),
84 'vads_cust_name' => substr(self::replaceNonAlpha(replace_accent($user->shortName())), 0, 127));
85 $this->infos['commande'] = Array(
86 'vads_amount' => $this->val,
87 'vads_currency' => '978', # Euro
88 'vads_payment_config' => 'SINGLE',
89 'vads_trans_date' => $trans_date,
90 'vads_trans_id' => $trans_id,
91 'vads_order_id' => $fullref,
92 'vads_order_info' => substr(self::replaceNonAlpha(replace_accent(Env::v('comment'))), 0, 255),
93 'vads_order_info2' => Post::i('display'));
94 $this->infos['divers'] = Array(
95 'vads_version' => 'V2',
96 'vads_ctx_mode' => $globals->money->cyperplus_prod,
97 'vads_page_action' => 'PAYMENT',
98 'vads_action_mode' => 'INTERACTIVE');
99
100 // Entry key computation.
101 $all_params = array_merge($this->infos['commercant'],$this->infos['client'],$this->infos['commande'],$this->infos['divers']);
102 ksort($all_params);
103 $this->infos['divers']['signature'] = sha1(join('+',$all_params).'+'.$globals->money->cyperplus_key);
104 }
105
106 // }}}
107 }
108
109 $api = 'BPLCCyberPlus';
110
111 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
112 ?>