X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fpayment%2Fmoney%2Fpaypal.inc.php;h=3ea2c63e075a1aec1458164fd579f900b230723f;hb=d71cf889a597a64abd6351f9a0097ec9bf9da42c;hp=4d7fb02e23d55212f10085ac3ab2ed159f6cd65d;hpb=4f494e74bb1310de55ce335324a966e31b6c72cb;p=platal.git diff --git a/modules/payment/money/paypal.inc.php b/modules/payment/money/paypal.inc.php index 4d7fb02..3ea2c63 100644 --- a/modules/payment/money/paypal.inc.php +++ b/modules/payment/money/paypal.inc.php @@ -1,6 +1,6 @@ val_number = $val; } - // }}} - // {{{ function form() - - function prepareform(&$pay) + function prepareform($pay, $user) { - // toute la doc sur : - // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf - // attention : le renvoi automatique ne fonctionne que si - // on oblige les gens à créer un compte paypal - // nous ne l'utilisons pas ; il faut donc que l'utilisateur - // revienne sur le site + // Documentation: + // https://www.paypal.com/developer + // Warning: the automatic return only works if we force the + // users to create a paypal account. We do not use it; thus + // the user must come back on the site. global $globals, $platal; - $this->urlform = 'https://'.$globals->money->paypal_site.'/cgi-bin/webscr'; - $req = XDB::query("SELECT IF(nom_usage!='', nom_usage, nom) AS nom - FROM auth_user_md5 - WHERE user_id = {?}",S::v('uid')); - $name = $req->fetchOneCell(); + $this->urlform = 'https://' . $globals->money->paypal_site . '/cgi-bin/webscr'; $roboturl = str_replace("https://","http://",$globals->baseurl) - . '/' . $platal->ns . "payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment')); - - $this->infos = Array(); - - $this->infos['commercant'] = Array( - 'business' => $globals->money->paypal_compte, - 'rm' => 2, - 'return' => $roboturl, - 'cn' => 'Commentaires', - 'no_shipping' => 1, - 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? - 'Revenir sur polytechnique.org' : - 'Revenir sur polytechnique.net'); - - $info_client = Array( - 'first_name' => S::v('prenom'), - 'last_name' => $name, - 'email' => S::user()->bestEmail()); - - $res = XDB::query( - "SELECT a.adr1 AS address1, a.adr2 AS address2, - a.city, a.postcode AS zip, a.country, - IF(t.tel, t.tel, q.profile_mobile) AS night_phone_b - FROM auth_user_quick AS q - LEFT JOIN adresses AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut)) - LEFT JOIN tels AS t ON (t.uid = a.uid AND t.adrid = a.adrid) - WHERE q.user_id = {?} - LIMIT 1", S::v('uid')); - $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc())); - - // on constuit la reference de la transaction - $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id(); - $fullref = substr("$prefix-xorg-{$pay->id}",-15); - - $this->infos['commande'] = Array( - 'item_name' => replace_accent($pay->text), - 'amount' => $this->val_number, + . '/' . $platal->ns . "payment/paypal_return/" . S::v('uid') + . "?comment=" . urlencode(Env::v('comment')) . '&display=' . Post::i('display'); + + $this->infos = array( + 'commercant' => array( + 'business' => $globals->money->paypal_compte, + 'rm' => 2, + 'return' => $roboturl, + 'cn' => 'Commentaires', + 'no_shipping' => 1, + 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? 'Revenir sur polytechnique.org.' : 'Revenir sur polytechnique.net.' + ) + ); + + $info_client = array( + 'first_name' => $user->firstName(), + 'last_name' => $user->lastName(), + 'email' => $user->bestEmail() + ); + + if ($user->hasProfile()) { + $res = XDB::query("SELECT pa.text, GROUP_CONCAT(pace2.short_name) AS city, + GROUP_CONCAT(pace3.short_name) AS zip, GROUP_CONCAT(pace1.short_name) AS country, + IF(pp1.display_tel != '', pp1.display_tel, pp2.display_tel) AS night_phone_b + FROM profile_addresses AS pa + LEFT JOIN profile_phones AS pp1 ON (pp1.pid = pa.pid AND pp1.link_type = 'address' AND pp1.link_id = pa.id) + LEFT JOIN profile_phones AS pp2 ON (pp2.pid = pa.pid AND pp2.link_type = 'user' AND pp2.link_id = 0) + LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid + AND pa.type = pc.type AND pa.id = pc.id) + LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET('country', pace1.types) AND pace1.id = pc.component_id) + LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET('locality', pace2.types) AND pace2.id = pc.component_id) + LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET('postal_code', pace3.types) AND pace3.id = pc.component_id) + WHERE pa.pid = {?} AND FIND_IN_SET('current', pa.flags) + GROUP BY pa.pid, pa.jobid, pa.groupid, pa.id, pa.type + LIMIT 1", + $user->profile()->id()); + $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc())); + list($this->infos['client']['address1'], $this->infos['client']['address2']) = + explode("\n", Geocoder::getFirstLines($this->infos['client']['text'], + $this->infos['client']['zip'], 2)); + unset($this->infos['client']['text']); + } else { + $this->infos['client'] = replace_accent($info_client); + } + + // We build the transaction's reference + $prefix = ($pay->flags->hasflag('unique')) ? str_pad("", 15, "0") : rand_url_id(); + $fullref = substr("$prefix-xorg-{$pay->id}", -15); + + $this->infos['commande'] = array( + 'item_name' => replace_accent($pay->text), + 'amount' => $this->val_number, 'currency_code' => 'EUR', - 'custom' => $fullref); + 'custom' => $fullref + ); - $this->infos['divers'] = Array('cmd' => '_xclick'); + $this->infos['divers'] = array('cmd' => '_xclick'); } - - // }}} } $api = 'PayPal';