Fix return url
[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 class BPLCCyberPlus
23 {
24 // {{{ properties
25
26 var $val;
27
28 var $urlform;
29 var $nomsite = "la BP Lorraine Champagne";
30 var $infos;
31
32 // }}}
33 // {{{ constructor
34
35 function BPLCCyberPlus($val)
36 {
37 // SVA : nombre de chiffres après la virgule dépendant de currency ?
38 $this->val = 100 * strtr(sprintf("%.02f", (float)$val), '.', ',');
39 }
40
41 // }}}
42 // {{{ function form()
43
44 function prepareform(&$pay)
45 {
46 global $globals, $platal;
47 $log = S::v('log');
48
49 // on constuit la reference de la transaction
50 $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
51 $fullref = substr("$prefix-{$pay->id}",-12); // FIXME : check for duplicates
52 $ts = time();
53 $trans_date = date("YmdHis", $ts);
54 $trans_id = date("His", $ts); // FIXME : check for duplicates
55
56 // contenu du formulaire
57 $this->urlform = "https://systempay.cyberpluspaiement.com/vads-payment/";
58 $this->infos['commercant'] = Array(
59 'vads_site_id' => $globals->money->cyperplus_account,
60 'vads_return_mode' => 'NONE',
61 'vads_url_return' => $pay->url ? $pay->url : $globals->baseurl . '/' . $platal->ns);
62 $this->infos['client'] = Array(
63 'vads_cust_email' => S::user()->bestEmail(),
64 'vads_cust_id' => S::v('uid'),
65 'vads_cust_name' => replace_accent(S::user()->fullName()));
66 $this->infos['commande'] = Array(
67 'vads_amount' => $this->val,
68 'vads_currency' => '978', # Euro
69 'vads_payment_config' => 'SINGLE',
70 'vads_trans_date' => $trans_date,
71 'vads_trans_id' => $trans_id,
72 'vads_order_id' => $fullref,
73 'vads_order_info' => Env::v('comment'));
74 $this->infos['divers'] = Array(
75 'vads_version' => 'V2',
76 'vads_ctx_mode' => 'TEST',
77 'vads_page_action' => 'PAYMENT',
78 'vads_action_mode' => 'INTERACTIVE');
79
80 // calcul de la clé d'acceptation en entrée
81 $all_params = array_merge($this->infos['commercant'],$this->infos['client'],$this->infos['commande'],$this->infos['divers']);
82 ksort($all_params);
83 $this->infos['divers']['signature'] = sha1(join('+',$all_params).'+'.$globals->money->cyperplus_key);
84 }
85
86 // }}}
87 }
88
89 $api = 'BPLCCyberPlus';
90
91 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
92 ?>