Пример #1
0
function presta_gratuit_payer_acte_dist($config, $id_transaction, $transaction_hash, $options = array())
{
    include_spip('inc/bank');
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    $contexte['sign'] = bank_sign_response_simple("gratuit", $contexte);
    $contexte['action'] = bank_url_api_retour($config, "response");
    $contexte = array_merge($options, $contexte);
    return recuperer_fond('presta/gratuit/payer/acte', $contexte);
}
Пример #2
0
function bank_simu_url_fin_paiement($config, $id_transaction, $transaction_hash)
{
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    $contexte['sign'] = bank_sign_response_simple('simu', $contexte);
    // url action
    $action = bank_url_api_retour($config, 'response');
    foreach ($contexte as $k => $v) {
        $action = parametre_url($action, $k, $v);
    }
    return $action;
}
Пример #3
0
/**
 * @param array $config
 * @param int $id_transaction
 * @param string $transaction_hash
 * @param array $options
 * @return array|string
 */
function presta_simu_payer_acte_dist($config, $id_transaction, $transaction_hash, $options = array())
{
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    $contexte['sign'] = bank_sign_response_simple($config['presta'], $contexte);
    // url action
    $action = bank_url_api_retour($config, 'response');
    foreach ($contexte as $k => $v) {
        $action = parametre_url($action, $k, $v);
    }
    $contexte['action'] = $action;
    $contexte = array_merge($options, $contexte);
    return recuperer_fond('presta/simu/payer/acte', $contexte);
}
Пример #4
0
/**
 * @param array $config
 * @param int $id_transaction
 * @param string $transaction_hash
 * @param array $options
 * @return array|string
 */
function presta_virement_payer_acte_dist($config, $id_transaction, $transaction_hash, $options = array())
{
    include_spip("inc/bank");
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash, 'autorisation_id' => 'wait');
    $contexte['sign'] = bank_sign_response_simple($config['presta'], $contexte);
    // url action
    $action = bank_url_api_retour($config, 'response');
    foreach ($contexte as $k => $v) {
        $action = parametre_url($action, $k, $v);
    }
    $contexte['action'] = $action;
    $contexte['config'] = $config;
    $contexte = array_merge($options, $contexte);
    return recuperer_fond('presta/virement/payer/acte', $contexte);
}
Пример #5
0
/**
 * @param array $config
 * @param int $id_transaction
 * @param string $transaction_hash
 * @param array $options
 * @return array|string
 */
function presta_simu_payer_abonnement_dist($config, $id_transaction, $transaction_hash, $options = array())
{
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    $contexte['sign'] = bank_sign_response_simple('simu', $contexte);
    // url action
    $action = bank_url_api_retour($config, 'response');
    foreach ($contexte as $k => $v) {
        $action = parametre_url($action, $k, $v);
    }
    $action = parametre_url($action, "abo", "oui");
    // paiement en attente
    unset($contexte['sign']);
    $contexte['autorisation_id'] = 'wait';
    $contexte['sign'] = bank_sign_response_simple('simu', $contexte);
    $action_wait = $action;
    foreach ($contexte as $k => $v) {
        $action_wait = parametre_url($action_wait, $k, $v);
    }
    $contexte['action'] = $action;
    $contexte['action_wait'] = $action_wait;
    $contexte = array_merge($options, $contexte);
    return recuperer_fond('presta/simu/payer/abonnement', $contexte);
}
Пример #6
0
function formulaires_encaisser_reglement_traiter_dist($id_transaction, $config)
{
    include_spip('inc/bank');
    if (is_string($config)) {
        $config = bank_config($config);
    }
    $mode = $config['presta'];
    $hash = sql_getfetsel("transaction_hash", "spip_transactions", "id_transaction=" . intval($id_transaction));
    $autorisation_id = autorisation_suffixe();
    if (strlen($autorisation_id) < 55) {
        $autorisation_id = _request('autorisation_id') . "|" . $autorisation_id;
    }
    include_spip('inc/bank');
    $response = array('id_transaction' => $id_transaction, 'transaction_hash' => $hash, 'autorisation_id' => $autorisation_id);
    $sign = bank_sign_response_simple($mode, $response);
    foreach ($response as $k => $v) {
        set_request($k, $v);
    }
    set_request("sign", $sign);
    set_request("bankp", $mode . "-" . bank_config_id($config));
    // on charge l'action et on l'appelle pour passer par tout le processus de paiement standard
    $bank_response = charger_fonction("bank_response", "action");
    return array('message_ok' => $bank_response());
}
Пример #7
0
/**
 * Recuperer la reponse postee et verifier sa signature
 * @param string $mode
 * @return array|bool
 */
function bank_response_simple($mode)
{
    $vars = array('id_transaction', 'transaction_hash', 'autorisation_id', 'abo');
    $response = array();
    foreach ($vars as $k) {
        if (!is_null($v = _request($k))) {
            $response[$k] = $v;
        }
    }
    if (!($s = _request('sign')) or $s !== bank_sign_response_simple($mode, $response)) {
        spip_log("bank_response_simple : signature invalide", "bank" . _LOG_ERREUR);
        return false;
    }
    return $response;
}
Пример #8
0
/**
 * Preparation de la requete par cartes
 * 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
 * @param string $type
 *   type de paiement : acte ou abo
 * @return array
 */
function presta_stripe_call_request_dist($id_transaction, $transaction_hash, $config, $type = "acte")
{
    $mode = 'stripe';
    if (!is_array($config) or !isset($config['type']) or !isset($config['presta'])) {
        spip_log("call_request : config invalide " . var_export($config, true), $mode . _LOG_ERREUR);
        return "";
    }
    $mode = $config['presta'];
    if (isset($config['mode_test']) and $config['mode_test']) {
        $mode .= "_test";
    }
    if (!($row = sql_fetsel("*", "spip_transactions", "id_transaction=" . intval($id_transaction) . " AND transaction_hash=" . sql_quote($transaction_hash)))) {
        spip_log("call_request : transaction {$id_transaction} / {$transaction_hash} introuvable", $mode . _LOG_ERREUR);
        return "";
    }
    if (!$row['id_auteur'] and isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) {
        sql_updateq("spip_transactions", array("id_auteur" => intval($row['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'])), "id_transaction=" . intval($id_transaction));
    }
    // si c'est un abonnement, verifier qu'on saura le traiter vu les limitations de Stripe
    // c'est un abonnement
    if ($type === 'abo') {
        // on decrit l'echeance
        if ($decrire_echeance = charger_fonction("decrire_echeance", "abos", true) and $echeance = $decrire_echeance($id_transaction)) {
            if ($echeance['montant'] > 0) {
                // si plus d'une echeance initiale prevue on ne sait pas faire avec Stripe
                if (isset($echeance['count_init']) and $echeance['count_init'] > 1) {
                    spip_log("Transaction #{$id_transaction} : nombre d'echeances init " . $echeance['count_init'] . ">1 non supporte", $mode . _LOG_ERREUR);
                    return "";
                }
                // si nombre d'echeances limitees, on ne sait pas faire avec Stripe
                if (isset($echeance['count']) and $echeance['count'] > 0) {
                    spip_log("Transaction #{$id_transaction} : nombre d'echeances " . $echeance['count'] . ">0 non supporte", $mode . _LOG_ERREUR);
                    return "";
                }
                if (isset($echeance['date_start']) and $echeance['date_start'] and strtotime($echeance['date_start']) > time()) {
                    spip_log("Transaction #{$id_transaction} : date_start " . $echeance['date_start'] . " non supportee", $mode . _LOG_ERREUR);
                    return "";
                }
            }
        }
    }
    $email = bank_porteur_email($row);
    // passage en centimes d'euros : round en raison des approximations de calcul de PHP
    $montant = intval(round(100 * $row['montant'], 0));
    if (strlen($montant) < 3) {
        $montant = str_pad($montant, 3, '0', STR_PAD_LEFT);
    }
    include_spip('inc/filtres_mini');
    // url_absolue
    $contexte = array('id_transaction' => $id_transaction, 'transaction_hash' => $transaction_hash);
    if ($type === 'abo') {
        $contexte['abo'] = 1;
    }
    $contexte['sign'] = bank_sign_response_simple($mode, $contexte);
    $action = bank_url_api_retour($config, "response");
    foreach ($contexte as $k => $v) {
        $action = parametre_url($action, $k, $v);
    }
    $contexte['action'] = $action;
    $contexte['email'] = $email;
    $contexte['amount'] = $montant;
    $contexte['currency'] = 'eur';
    $contexte['key'] = $config['mode_test'] ? $config['PUBLISHABLE_KEY_test'] : $config['PUBLISHABLE_KEY'];
    $contexte['name'] = textebrut($GLOBALS['meta']['nom_site']);
    $contexte['description'] = _T('bank:titre_transaction') . '#' . $id_transaction;
    $contexte['image'] = find_in_path('img/logo-paiement-stripe.png');
    if (!$contexte['image']) {
        $chercher_logo = charger_fonction('chercher_logo', 'inc');
        if ($logo = $chercher_logo(0, 'site')) {
            $logo = reset($logo);
            $contexte['image'] = $logo;
        }
    }
    if ($contexte['image']) {
        $contexte['image'] = url_absolue($contexte['image']);
    }
    return $contexte;
}