/** * Verifier le statut d'une transaction lors du retour de l'internaute * * @param array $config * @param null|array $response * @return array */ function presta_sips_call_response_dist($config, $response = null) { include_spip('inc/bank'); $mode = $config['presta']; include_spip('inc/config'); $merchant_id = $config['merchant_id']; $service = $config['service']; $certif = $config['certificat']; // recuperer la reponse en post et la decoder if (is_null($response)) { $response = sips_response($service, $merchant_id, $certif); } if ($response['merchant_id'] !== $merchant_id) { return bank_transaction_invalide(0, array('mode' => $mode, 'erreur' => "merchant_id invalide", 'log' => sips_shell_args($response))); } return sips_traite_reponse_transaction($config, $response); }
function presta_sips_exec_request_dist($service, $params, $certificat, $dir_logo, $request = "request") { $path_bin = find_in_path("presta/sips/bin/{$request}"); if (!$path_bin or !file_exists($path_bin)) { spip_log("Binaire {$path_bin} non trouve", "sips." . _LOG_ERREUR); return false; } $path_bin = realpath($path_bin); include_spip("presta/sips/inc/sips"); $merchant_id = $params['merchant_id']; $realdir = sips_ecrire_config_merchant($service, $merchant_id, $certificat, $dir_logo); $params['pathfile'] = $realdir . "/pathfile"; // transformer la table d'arguments en commande shell $params = sips_shell_args($params); // Appel du binaire request spip_log("sips_exec_request : {$path_bin} {$params}", 'sips'); $result = exec("{$path_bin} {$params}"); return $result; }
/** * Traiter la reponse apres son decodage * * @param array $config * @param array $response * @return array */ function sips_traite_reponse_transaction($config, $response) { $mode = $config['presta']; $config_id = bank_config_id($config); $id_transaction = $response['order_id']; $transaction_id = $response['transaction_id']; $row = sql_fetsel("*", "spip_transactions", "id_transaction=" . intval($id_transaction)); if (!$row) { return bank_transaction_invalide($id_transaction, array('mode' => $mode, 'erreur' => "transaction inconnue", 'log' => sips_shell_args($response))); } /* include_spip('inc/filtres'); if ($transaction_hash!=modulo($row['transaction_hash'],999999)){ return bank_transaction_invalide($id_transaction, array( 'mode'=>$mode, 'erreur' => "hash $transaction_hash invalide", 'log' => sips_shell_args($response) ) ); } */ // ok, on traite le reglement $date = 'payment'; if ($mode == 'sipsabo') { $date = 'sub'; } //"Y-m-d H:i:s" $date_paiement = substr($response[$date . '_date'], 0, 4) . "-" . substr($response[$date . '_date'], 4, 2) . "-" . substr($response[$date . '_date'], 6, 2) . " " . substr($response[$date . '_time'], 0, 2) . ":" . substr($response[$date . '_time'], 2, 2) . ":" . substr($response[$date . '_time'], 4, 2); $response_code = sips_response_code($response['response_code']); $bank_response_code = sips_bank_response_code($response['bank_response_code']); if ($response_code !== true or $bank_response_code !== true) { // regarder si l'annulation n'arrive pas apres un reglement (internaute qui a ouvert 2 fenetres de paiement) if ($row['reglee'] == 'oui') { return array($id_transaction, true); } // sinon enregistrer l'absence de paiement et l'erreur return bank_transaction_echec($id_transaction, array('mode' => $mode, 'config_id' => $config_id, 'date_paiement' => $date_paiement, 'code_erreur' => $response['response_code'] . (strlen($response['bank_response_code']) ? ":" . $response['bank_response_code'] : ''), 'erreur' => trim($response_code . " " . $bank_response_code), 'log' => sips_shell_args($response), 'send_mail' => $response['response_code'] == '03')); } // Ouf, le reglement a ete accepte // on verifie que le montant est bon ! $montant_regle = $response[($mode == 'sipsabo' ? 'sub_' : '') . 'amount'] / 100; if ($montant_regle != $row['montant']) { spip_log($t = "call_response : id_transaction {$id_transaction}, montant regle {$montant_regle}!=" . $row['montant'] . ":" . sips_shell_args($response), $mode); // on log ca dans un journal dedie spip_log($t, $mode . '_reglements_partiels'); } // mais sinon on note regle quand meme, // pour ne pas creer des problemes hasardeux // (il y a des fois une erreur d'un centime) $authorisation_id = $response['authorisation_id']; $set = array("autorisation_id" => $authorisation_id, "mode" => "{$mode}/{$config_id}", "montant_regle" => $montant_regle, "date_paiement" => $date_paiement, "statut" => 'ok', "reglee" => 'oui'); sql_updateq("spip_transactions", $set, "id_transaction=" . intval($id_transaction)); spip_log("call_response : id_transaction {$id_transaction}, reglee", $mode); $regler_transaction = charger_fonction('regler_transaction', 'bank'); $regler_transaction($id_transaction, array('row_prec' => $row)); return array($id_transaction, true); }