From 7bff3890361c3787ee997001d3389fe1c4daf5b5 Mon Sep 17 00:00:00 2001 From: yohooo Date: Mon, 29 Apr 2024 19:27:39 +0200 Subject: [PATCH 1/5] Permettre de s'abonner plus d'une heure, un jour ou un mois avec Stripe... Depuis le temps ! --- presta/stripe/call/request.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/presta/stripe/call/request.php b/presta/stripe/call/request.php index 060da88..c29a105 100644 --- a/presta/stripe/call/request.php +++ b/presta/stripe/call/request.php @@ -291,6 +291,8 @@ function presta_stripe_call_request_dist($id_transaction, $transaction_hash, $co } } + $interval_count = 1; + $session_desc = [ 'payment_method_types' => $payment_types, 'mode' => 'subscription', @@ -321,7 +323,7 @@ function presta_stripe_call_request_dist($id_transaction, $transaction_hash, $co 'unit_amount' => $montant_echeance, 'recurring' => [ 'interval' => $interval, - 'interval_count' => 1, + 'interval_count' => $echeance['interval_count'], //'trial_period_days' => 0, // default ], //'billing_scheme' => 'per_unit', // implicite, non modifiable via price_data From 49478a0a52b1676285934d2e45cefb15bcf65b70 Mon Sep 17 00:00:00 2001 From: yohooo Date: Mon, 29 Apr 2024 22:56:20 +0200 Subject: [PATCH 2/5] Fix, recuperation de la variable. --- presta/stripe/call/request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presta/stripe/call/request.php b/presta/stripe/call/request.php index c29a105..c45427b 100644 --- a/presta/stripe/call/request.php +++ b/presta/stripe/call/request.php @@ -323,7 +323,7 @@ function presta_stripe_call_request_dist($id_transaction, $transaction_hash, $co 'unit_amount' => $montant_echeance, 'recurring' => [ 'interval' => $interval, - 'interval_count' => $echeance['interval_count'], + 'interval_count' => $echeance['interval_count'] ?? $interval_count , //'trial_period_days' => 0, // default ], //'billing_scheme' => 'per_unit', // implicite, non modifiable via price_data From b7137a132298eff1043a4d6d48614d0545467231 Mon Sep 17 00:00:00 2001 From: yohooo Date: Wed, 15 May 2024 10:06:48 +0200 Subject: [PATCH 3/5] RIen --- presta/stripe/call/request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presta/stripe/call/request.php b/presta/stripe/call/request.php index c45427b..c29a105 100644 --- a/presta/stripe/call/request.php +++ b/presta/stripe/call/request.php @@ -323,7 +323,7 @@ function presta_stripe_call_request_dist($id_transaction, $transaction_hash, $co 'unit_amount' => $montant_echeance, 'recurring' => [ 'interval' => $interval, - 'interval_count' => $echeance['interval_count'] ?? $interval_count , + 'interval_count' => $echeance['interval_count'], //'trial_period_days' => 0, // default ], //'billing_scheme' => 'per_unit', // implicite, non modifiable via price_data From dff0ca7292dc6f668b8c79385c80fa47606dd3fe Mon Sep 17 00:00:00 2001 From: yohooo Date: Thu, 30 May 2024 23:44:16 +0200 Subject: [PATCH 4/5] =?UTF-8?q?Ajout=20d'une=20balise=20#CHANGER=5FMOYEN?= =?UTF-8?q?=5FPAIEMENT=20permetant=20de=20modifier=20la=20carte=20de=20pai?= =?UTF-8?q?ement=20li=C3=A9e=20=C3=A0=20un=20abonnement=20sous=20Stripe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- presta/stripe/call/modifier_paiement.php | 130 +++++++++++++++++++++++ presta/stripe/payer/configurer.html | 28 +++++ presta/stripe/payer/configurer.php | 35 ++++++ 3 files changed, 193 insertions(+) create mode 100644 presta/stripe/call/modifier_paiement.php create mode 100644 presta/stripe/payer/configurer.html create mode 100644 presta/stripe/payer/configurer.php diff --git a/presta/stripe/call/modifier_paiement.php b/presta/stripe/call/modifier_paiement.php new file mode 100644 index 0000000..ad5185e --- /dev/null +++ b/presta/stripe/call/modifier_paiement.php @@ -0,0 +1,130 @@ + $id_transaction, + 'transaction_hash' => $transaction_hash, + ); + $contexte['sign'] = bank_sign_response_simple($mode, $contexte); + $url_success = bank_url_api_retour($config,"response"); + $url_cancel = bank_url_api_retour($config,"cancel"); + foreach($contexte as $k=>$v){ + $url_success = parametre_url($url_success, $k, $v, '&'); + $url_cancel = parametre_url($url_cancel, $k, $v, '&'); + } + + $contexte['action'] = str_replace('&', '&', $url_success); + $contexte['email'] = $email; + $contexte['key'] = ($config['mode_test'] ? $config['PUBLISHABLE_KEY_test'] : $config['PUBLISHABLE_KEY']); + $contexte['name'] = bank_nom_site(); + $contexte['description'] = _T('bank:titre_transaction') . '#' . $id_transaction; + $contexte['image'] = find_in_path('img/logo-paiement-stripe.png'); + + stripe_init_api($config); + stripe_set_webhook($config); + + // ================== CUSTOMER =================== + + // Coté Stripe : on vérifie que le customer existe + if ($row['id_auteur']) { + $config_id = bank_config_id($config); + $customer_id = sql_getfetsel('pay_id', 'spip_transactions', + 'pay_id!=' . sql_quote('') . ' AND id_auteur=' . intval($row['id_auteur']) . ' AND statut=' . sql_quote('ok') . ' AND mode=' . sql_quote("$mode/$config_id"), + '', 'date_paiement DESC', '0,1'); + if ($customer_id + and $customer = stripe_customer($mode, ['id' => $customer_id]) + and $customer->email === $contexte['email'] + ){ + spip_log("call_modifier_paiement : Customer retrouvé :". $id_customer,$mode._LOG_DEBUG); + $checkout_customer_id = $customer_id; + } else { + spip_log("call_modifier_paiement : ce Customer n'existe pas chez Stripe". $id_customer,$mode._LOG_ERREUR); + return false; + } + if (!$checkout_customer_id + and $customer = stripe_customer($mode, ['email' => $contexte['email'], 'nom' => trim($billing['prenom'] . ' ' . $billing['nom'])])){ + $checkout_customer_id = $customer->id; + } + } + + // On prépare la sessions avec les données génériques + $session_desc = [ + 'payment_method_types' => ['card'], + 'success_url' => $url_success . '&session_id={CHECKOUT_SESSION_ID}', + 'cancel_url' => $url_success, // on revient sur success aussi car response gerera l'echec du fait de l'absence de session_id + 'locale' => stripe_locale($GLOBALS['spip_lang']), + 'customer_email' => $email, + ]; + + // Et on déclare les paramètres particuliers du mode "setup" de la session checkout. + $session_desc['mode'] = 'setup'; + $session_desc[ 'setup_intent_data']['description'] = 'Enregistrement de nouveau moyen de paiement'; + $session_desc[ 'setup_intent_data']['metadata']['customer_id'] = $id_customer; + $session_desc[ 'setup_intent_data']['metadata']['subscription_id'] = str_replace('/','',$row['abo_uid']); + + $session = \Stripe\Checkout\Session::create($session_desc); + $contexte['checkout_session_id'] = $session->id; + + return $contexte; + +} \ No newline at end of file diff --git a/presta/stripe/payer/configurer.html b/presta/stripe/payer/configurer.html new file mode 100644 index 0000000..5858446 --- /dev/null +++ b/presta/stripe/payer/configurer.html @@ -0,0 +1,28 @@ +[(#REM) +/* +* Paiement Bancaire +* module de paiement bancaire multi prestataires +* stockage des transactions +* +* Auteurs : + * Laurent Lefebvre largement inspiré du code de Cedric Morin / Nursit.com + * (c) 2012-2024 - Distribue sous licence GNU/GPL +* +*/ +]#CACHE{0} + +
+ [(#SET{id,[setup(#ID_TRANSACTION)]})] + [(#BOUTON_ACTION{ + Modifier le moyen de paiement pour cet abonnement, + #ENV*{action}, + [stripe_button_(#GET{id}) btn btn-defaut btn-petit btn-fleche], + '', + '', + [stripe_button_(#GET{id})_callback\(\)] + })] + [ + ] + +
+ diff --git a/presta/stripe/payer/configurer.php b/presta/stripe/payer/configurer.php new file mode 100644 index 0000000..83acad8 --- /dev/null +++ b/presta/stripe/payer/configurer.php @@ -0,0 +1,35 @@ + Date: Thu, 30 May 2024 23:45:22 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Ajout=20d'une=20balise=20#CHANGER=5FMOYEN?= =?UTF-8?q?=5FPAIEMENT=20permetant=20de=20modifier=20la=20carte=20de=20pai?= =?UTF-8?q?ement=20li=C3=A9e=20=C3=A0=20un=20abonnement=20sous=20Stripe=20?= =?UTF-8?q?/=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bank_fonctions.php | 18 ++++++++++++++++++ bank_options.php | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/bank_fonctions.php b/bank_fonctions.php index 0c6b9eb..9ed06e3 100644 --- a/bank_fonctions.php +++ b/bank_fonctions.php @@ -61,6 +61,24 @@ function balise_PAYER_ABONNEMENT_dist($p){ return $p; } +/** + * #CHANGER_MOYEN_PAIEMENT{#ID_ABONNEMENT,#ID_TRANSACTION} + * @param $p + * @return mixed + */ +function balise_CHANGER_MOYEN_PAIEMENT_dist($p){ + + $_idabo = interprete_argument_balise(1, $p); + $_idtrans = interprete_argument_balise(2, $p); + $p->code = ""; + + if ($_idabo AND $_idtrans) { + $p->code = "bank_changer_paiement($_idabo,$_idtrans)"; + } + + $p->interdire_scripts = false; + return $p; +} /** * #GERER_ABONNEMENT{#MODE_PAIEMENT,#ABO_UID} diff --git a/bank_options.php b/bank_options.php index 2f91b5d..c5757e1 100644 --- a/bank_options.php +++ b/bank_options.php @@ -183,3 +183,23 @@ function bank_affiche_gerer_abonnement($config, $abo_uid){ return ""; } + +/** + * Afficher le bouton pour changer de moyen de paiement d'un abonnement + * @param array|string $config + * @param string $abo_uid + * @return array|string + */ +function bank_changer_paiement($id_abo, $id_trans){ + // $config de type string ? + include_spip('inc/bank'); + + if ($trans = sql_fetsel("*", "spip_transactions", $w = "id_transaction=" . sql_quote($id_trans))){ + $config = bank_config($trans['mode']); + if ($configurer = charger_fonction('configurer', 'presta/'.$config['presta'] . '/payer', true)){ + return $configurer($id_trans, $trans['transaction_hash']); + } + } + + return ""; +}