Exemplo n.º 1
0
 function __construct($config, $sLangue = "FR")
 {
     // contrôle de l'existence des constantes de paramétrages.
     $aRequiredConstants = array('_CMCIC_VERSION');
     $this->_checkTpeParams($config, $aRequiredConstants);
     $this->sVersion = _CMCIC_VERSION;
     $this->_sCle = $config['CLE'];
     $this->sNumero = $config['TPE'];
     $this->sUrlPaiement = cmcic_url_serveur($config);
     $this->sCodeSociete = $config['CODESOCIETE'];
     $this->sLangue = $sLangue;
     $this->sUrlOK = defined('_CMCIC_URLOK') ? _CMCIC_URLOK : "";
     $this->sUrlKO = defined('_CMCIC_URLKO') ? _CMCIC_URLKO : "";
 }
Exemplo n.º 2
0
/**
 * Generer le contexte pour le formulaire de requete de paiement
 * il faut avoir un id_transaction et un transaction_hash coherents
 * pour se premunir d'une tentative d'appel exterieur
 *
 * @param int $id_transaction
 * @param string $transaction_hash
 * @param $config
 *   configuration du module
 * @return array
 */
function presta_cmcic_call_request_dist($id_transaction, $transaction_hash, $config)
{
    if (!($row = sql_fetsel("*", "spip_transactions", "id_transaction=" . intval($id_transaction) . " AND transaction_hash=" . sql_quote($transaction_hash)))) {
        return array();
    }
    include_spip('inc/filtres');
    $contexte = array();
    $oTpe = new CMCIC_Tpe($config, strtoupper($GLOBALS['spip_lang']));
    if (!$oTpe->isOK) {
        return false;
    }
    $oHmac = new CMCIC_Hmac($oTpe);
    // Control String for support
    $CtlHmac = sprintf(_CMCIC_CTLHMAC, $oTpe->sVersion, $oTpe->sNumero, $oHmac->computeHmac(sprintf(_CMCIC_CTLHMACSTR, $oTpe->sVersion, $oTpe->sNumero)));
    // Currency : ISO 4217 compliant
    $devise = "EUR";
    // Amount : format  "xxxxx.yy" (no spaces)
    $montant = $row['montant'];
    $contexte['version'] = $oTpe->sVersion;
    $contexte['TPE'] = $oTpe->sNumero;
    // transaction date : format d/m/y:h:m:s
    $contexte['date'] = date("d/m/Y:H:i:s");
    $contexte['montant'] = $montant . $devise;
    // Reference: unique, alphaNum (A-Z a-z 0-9), 12 characters max
    $contexte['reference'] = substr($transaction_hash, 0, 12);
    $contexte['lgue'] = $oTpe->sLangue;
    $contexte['societe'] = $oTpe->sCodeSociete;
    // on transmet dans le texte libre les données id_transaction & hash
    // pour les avoir dans le retour URL CGI2 qui est une url à donner à la banque
    // et qui n'a pas connaissance autrement de notre id_transaction et hash :(
    // URL CGI2 à donner à la banque :
    // http(s)://votresite.org/?action=bank_autoresponse&bankp=cmcic
    $contenu = array('id' => $id_transaction, 'hash' => $transaction_hash, 'lang' => $GLOBALS['spip_lang'], 'contenu' => $row['contenu']);
    // texte-libre doit etre protege car le formulaire est parfois reinjecte par Cmcic
    // dans une page de redirection pour les mobiles
    $contexte['texte-libre'] = urlencode(serialize($contenu));
    $contexte['mail'] = bank_porteur_email($row);
    // Data to certify
    $PHP1_FIELDS = sprintf(_CMCIC_CGI1_FIELDS, $contexte['TPE'], $contexte['date'], $montant, $devise, $contexte['reference'], $contexte['texte-libre'], $oTpe->sVersion, $oTpe->sLangue, $oTpe->sCodeSociete, $contexte['mail'], "", "", "", "", "", "", "", "", "", "");
    // MAC computation
    $contexte['MAC'] = $oHmac->computeHmac($PHP1_FIELDS);
    // Urls de retour.
    // La banque poste d'abord sur l'URL CGI2 (cf cmcic/config.php) qui doit traiter
    // le paiement positif et en attend une réponse (texte).
    // Puis, elle présente sur la banque au choix ces urls pour revenir sur le site
    // - retour OK si le paiement s'est bien déroulé
    $contexte['url_retour_ok'] = bank_url_api_retour($config, "response", "id={$id_transaction};{$transaction_hash}");
    // - retour err si le paiement a été refusé
    $contexte['url_retour_err'] = bank_url_api_retour($config, "cancel", "id={$id_transaction};{$transaction_hash}");
    // - retour (bouton Annuler) si le bonhomme décide d'abandonner le paiement
    $contexte['url_retour'] = $contexte['url_retour_ok'];
    $hidden = "";
    foreach ($contexte as $k => $v) {
        $hidden .= "<input type='hidden' name='{$k}' value='" . str_replace("'", "&#39;", $v) . "' />";
    }
    include_spip('inc/filtres_mini');
    $contexte = array('hidden' => $hidden, 'action' => cmcic_url_serveur($config), 'backurl' => url_absolue(self()), 'id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    return $contexte;
}