Fixes vim mode line.
[platal.git] / modules / payment / money / bplccyberplus.inc.php
CommitLineData
9b947ed0
DB
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
9b947ed0
DB
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
42357ba1
SJ
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).
40a43ddb
DB
34*/
35
9b947ed0
DB
36class 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 {
42357ba1 51 // Improvement: number of digits after the coma might depend from the currency.
996cab6c 52 $this->val = 100 * strtr($val, ',', '.');
9b947ed0
DB
53 }
54
6b3e8ff5 55 // }}}
9b947ed0
DB
56 // {{{ function form()
57
fc1227ef
SJ
58 private static function replaceNonAlpha($string)
59 {
60 return trim(preg_replace('/\s\s+/', ' ', preg_replace('/[^a-zA-Z0-9]/', ' ', $string)));
61 }
62
6643b3f0 63 function prepareform($pay, $user)
9b947ed0
DB
64 {
65 global $globals, $platal;
66 $log = S::v('log');
67
42357ba1 68 // Transaction's reference computation.
1c02b178 69 $prefix = rand_url_id();
9b947ed0 70 $fullref = substr("$prefix-{$pay->id}",-12); // FIXME : check for duplicates
ab9241a2
RB
71 $ts = time();
72 $trans_date = gmdate("YmdHis", $ts);
73 $trans_id = gmdate("His", $ts); // FIXME : check for duplicates
6b3e8ff5 74
42357ba1 75 // Form's content.
9b947ed0
DB
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',
31d6c664 80 'vads_url_return' => $pay->url ? $pay->url : $globals->baseurl . '/' . $platal->ns);
9b947ed0 81 $this->infos['client'] = Array(
6643b3f0 82 'vads_cust_email' => $user->bestEmail(),
688bec5e 83 'vads_cust_id' => $user->id(),
6643b3f0 84 'vads_cust_name' => substr(self::replaceNonAlpha(replace_accent($user->shortName())), 0, 127));
9b947ed0
DB
85 $this->infos['commande'] = Array(
86 'vads_amount' => $this->val,
87 'vads_currency' => '978', # Euro
6b3e8ff5
SJ
88 'vads_payment_config' => 'SINGLE',
89 'vads_trans_date' => $trans_date,
9b947ed0
DB
90 'vads_trans_id' => $trans_id,
91 'vads_order_id' => $fullref,
fbb196fa
SJ
92 'vads_order_info' => substr(self::replaceNonAlpha(replace_accent(Env::v('comment'))), 0, 255),
93 'vads_order_info2' => Post::i('display'));
9b947ed0
DB
94 $this->infos['divers'] = Array(
95 'vads_version' => 'V2',
40a43ddb 96 'vads_ctx_mode' => $globals->money->cyperplus_prod,
9b947ed0
DB
97 'vads_page_action' => 'PAYMENT',
98 'vads_action_mode' => 'INTERACTIVE');
aab2ffdd 99
42357ba1 100 // Entry key computation.
9b947ed0
DB
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
448c8cdc 111// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
9b947ed0 112?>