Integration of the new BPLC payment system.
[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 $url_return = str_replace("https://","http://", $globals->baseurl)
50 . '/' . $platal->ns . "payment/cyber2_return/";
51
52 // on constuit la reference de la transaction
53 $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
54 $fullref = substr("$prefix-{$pay->id}",-12); // FIXME : check for duplicates
55 $ts = time();
56 $trans_date = date("YmdHis", $ts);
57 $trans_id = date("His", $ts); // FIXME : check for duplicates
58
59 // contenu du formulaire
60 $this->urlform = "https://systempay.cyberpluspaiement.com/vads-payment/";
61 $this->infos['commercant'] = Array(
62 'vads_site_id' => $globals->money->cyperplus_account,
63 'vads_return_mode' => 'NONE',
64 'vads_url_return' => $url_return);
65 $this->infos['client'] = Array(
66 'vads_cust_email' => S::user()->bestEmail(),
67 'vads_cust_id' => S::v('uid'),
68 'vads_cust_name' => replace_accent(S::user()->fullName()));
69 $this->infos['commande'] = Array(
70 'vads_amount' => $this->val,
71 'vads_currency' => '978', # Euro
72 'vads_payment_config' => 'SINGLE',
73 'vads_trans_date' => $trans_date,
74 'vads_trans_id' => $trans_id,
75 'vads_order_id' => $fullref,
76 'vads_order_info' => Env::v('comment'));
77 $this->infos['divers'] = Array(
78 'vads_version' => 'V2',
79 'vads_ctx_mode' => 'TEST',
80 'vads_page_action' => 'PAYMENT',
81 'vads_action_mode' => 'INTERACTIVE');
82
83 // calcul de la clé d'acceptation en entrée
84 $all_params = array_merge($this->infos['commercant'],$this->infos['client'],$this->infos['commande'],$this->infos['divers']);
85 ksort($all_params);
86 $this->infos['divers']['signature'] = sha1(join('+',$all_params).'+'.$globals->money->cyperplus_key);
87 }
88
89 // }}}
90 }
91
92 $api = 'BPLCCyberPlus';
93
94 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
95 ?>