Exemplo n.º 1
0
/**
 * Decoder la reponse renvoyee par Ogone
 *
 * @param array $response
 * @param string $mode
 * @return array
 */
function ogone_traite_reponse_transaction($response, $mode = 'ogone')
{
    /*
    	'orderID' => string '15' (length=2)
     'currency' => string 'EUR' (length=3)
     'amount' => string '7' (length=1)
     'PM' => string 'CreditCard' (length=10)
     'ACCEPTANCE' => string 'test123' (length=7)
     'STATUS' => string '9' (length=1)
     'CARDNO' => string 'XXXXXXXXXXXX1111' (length=16)
     'ED' => string '1110' (length=4)
     'CN' => string 'Cedric MORIN' (length=12)
     'TRXDATE' => string '06/28/10' (length=8)
     'PAYID' => string '7599709' (length=7)
     'NCERROR' => string '0' (length=1)
     'BRAND' => string 'VISA' (length=4)
     'ECI' => string '7' (length=1)
     'IP' => string '88.173.4.97' (length=11)
     'SHASIGN' => string '6AC414390B39177A3EA9B70CE2D91BC03DED35F4' (length=40)
    */
    $id_transaction = intval($response['orderID']);
    if (!($row = sql_fetsel("*", "spip_transactions", "id_transaction=" . intval($id_transaction)))) {
        spip_log($t = "call_response : id_transaction {$id_transaction} inconnu:" . var_export($response, true), $mode);
        // on log ca dans un journal dedie
        spip_log($t, $mode . "_douteux");
        // on mail le webmestre
        $envoyer_mail = charger_fonction('envoyer_mail', 'inc');
        $envoyer_mail($GLOBALS['meta']['email_webmaster'], "[{$mode}]Transaction Frauduleuse", $t, "{$mode}@" . $_SERVER['HTTP_HOST']);
        $message = "Une erreur est survenue, les données reçues de la banque ne sont pas conformes. ";
        $message .= "Votre règlement n'a pas été pris en compte (Ref : {$id_transaction})";
        sql_updateq("spip_transactions", array("message" => $message, 'statut' => 'echec'), "id_transaction=" . intval($id_transaction));
        return array($id_transaction, false);
    }
    // ok, on traite le reglement
    $date = time();
    $date_paiement = date("Y-m-d H:i:s", $date);
    $erreur = ogone_response_code($response['STATUS'], $response['NCERROR']);
    $authorisation_id = $response['ACCEPTANCE'];
    $transaction = $response['PAYID'];
    if (!$transaction or !$authorisation_id or $erreur !== 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
        spip_log($t = "call_response : transaction {$id_transaction} refusee :[{$erreur}]:" . var_export($response, true), $mode);
        $message = "Aucun règlement n'a été réalisé" . ($erreur === true ? "" : " ({$erreur})");
        sql_updateq("spip_transactions", array("statut" => 'echec[' . $response['STATUS'] . ':' . $response['NCERROR'] . ']', 'date_paiement' => $date_paiement, 'message' => $message), "id_transaction=" . intval($id_transaction));
        return array($id_transaction, false);
    }
    // Ouf, le reglement a ete accepte
    // on verifie que le montant est bon !
    $montant_regle = floatval($response['amount']);
    if ($montant_regle != $row['montant']) {
        spip_log($t = "call_response : id_transaction {$id_transaction}, montant regle {$montant_regle}!=" . $row['montant'] . ":" . var_export($response, true), $mode);
        // on log ca dans un journal dedie
        spip_log($t, $mode . '_reglements_partiels');
        // mais on continue en acceptant quand meme le paiement
        // car l'erreur est en general dans le traitement
    }
    sql_updateq("spip_transactions", array("autorisation_id" => "{$transaction}/{$authorisation_id}", "mode" => $mode, "montant_regle" => $montant_regle, "date_paiement" => $date_paiement, "statut" => 'ok', "reglee" => 'oui'), "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, "", $row);
    return array($id_transaction, true);
}
Exemplo n.º 2
0
/**
 * Decoder la reponse renvoyee par Ogone
 *
 * @param array $config
 * @param array $response
 * @return array
 */
function ogone_traite_reponse_transaction($config, $response)
{
    $mode = $config['presta'];
    if (isset($config['mode_test']) and $config['mode_test']) {
        $mode .= "_test";
    }
    $config_id = bank_config_id($config);
    /*
    	'orderID' => string '15' (length=2)
     'currency' => string 'EUR' (length=3)
     'amount' => string '7' (length=1)
     'PM' => string 'CreditCard' (length=10)
     'ACCEPTANCE' => string 'test123' (length=7)
     'STATUS' => string '9' (length=1)
     'CARDNO' => string 'XXXXXXXXXXXX1111' (length=16)
     'ED' => string '1110' (length=4)
     'CN' => string 'John Doe' (length=12)
     'TRXDATE' => string '06/28/10' (length=8)
     'PAYID' => string '7599709' (length=7)
     'NCERROR' => string '0' (length=1)
     'BRAND' => string 'VISA' (length=4)
     'ECI' => string '7' (length=1)
     'IP' => string '88.173.4.97' (length=11)
     'SHASIGN' => string '6AC414390B39177A3EA9B70CE2D91BC03DED35F4' (length=40)
    */
    $id_transaction = intval($response['orderID']);
    if (!($row = sql_fetsel("*", "spip_transactions", "id_transaction=" . intval($id_transaction)))) {
        return bank_transaction_invalide($id_transaction, array('mode' => $mode, 'erreur' => "transaction inconnue", 'log' => var_export($response, true)));
    }
    // ok, on traite le reglement
    $date = time();
    $date_paiement = date("Y-m-d H:i:s", $date);
    $erreur = ogone_response_code($response['STATUS'], $response['NCERROR']);
    $authorisation_id = $response['ACCEPTANCE'];
    $transaction = $response['PAYID'];
    if (!$transaction or !$authorisation_id or $erreur !== 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);
        }
        return bank_transaction_echec($id_transaction, array('mode' => $mode, 'config_id' => $config_id, 'date_paiement' => $date_paiement, 'code_erreur' => $response['STATUS'] . ':' . $response['NCERROR'], 'erreur' => $erreur, 'log' => var_export($response, true)));
    }
    // Ouf, le reglement a ete accepte
    // on verifie que le montant est bon !
    $montant_regle = floatval($response['amount']);
    if ($montant_regle != $row['montant']) {
        spip_log($t = "call_response : id_transaction {$id_transaction}, montant regle {$montant_regle}!=" . $row['montant'] . ":" . var_export($response, true), $mode);
        // on log ca dans un journal dedie
        spip_log($t, $mode . '_reglements_partiels');
        // mais on continue en acceptant quand meme le paiement
        // car l'erreur est en general dans le traitement
    }
    sql_updateq("spip_transactions", array("autorisation_id" => "{$transaction}/{$authorisation_id}", "mode" => "{$mode}/{$config_id}", "montant_regle" => $montant_regle, "date_paiement" => $date_paiement, "statut" => 'ok', "reglee" => 'oui'), "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);
}