From 57ce70bbc900fb8b542a52c3a8c6384fbea390e6 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 24 Apr 2019 13:08:13 +0200 Subject: [PATCH 1/5] NEW enhancement management of webhooks active / inactive and sync only needed events --- htdocs/stripe/admin/stripe.php | 82 +++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 5e2c27dd392..1336bed8575 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -2,7 +2,7 @@ /* Copyright (C) 2017 Alexandre Spangaro * Copyright (C) 2017 Olivier Geffroy * Copyright (C) 2017 Saasprov - * Copyright (C) 2018 ptibogxiv + * Copyright (C) 2018 Thibault FOUCART * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $servicename='Stripe'; @@ -150,6 +151,8 @@ print ''; dol_fiche_head($head, 'stripeaccount', '', -1); +$stripearrayofwebhookevents=array('payout.created','payout.paid','charge.pending','charge.refunded','charge.succeeded','charge.failed','payment_intent.succeeded','payment_intent.payment_failed','source.chargeable','customer.deleted'); + print $langs->trans("StripeDesc")."
\n"; print '
'; @@ -158,6 +161,7 @@ print ''; print ''; print ''; print ''; +print ''; print "\n"; print ''; @@ -177,24 +181,51 @@ if (empty($conf->stripeconnect->enabled)) print ''.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").''; + print ''; print ''; + print ''; print ''; + print '
'.$out; + print ''; } else { print ''; print ''; + print ''; print ''; + print ''; print ''; + print '
'.$out; + print ''; } else { From 6d06f128e775606680593f628307c53b29c47d2a Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 24 Apr 2019 13:51:41 +0200 Subject: [PATCH 2/5] Update stripe.php --- htdocs/stripe/admin/stripe.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 1336bed8575..f0b9c6361bf 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -199,15 +199,15 @@ if (empty($conf->stripeconnect->enabled)) $url = dol_buildpath('/public/stripe/ipn.php?test', 2); $out.= ''; $out.= ajax_autoselect("onlinetestwebhookurl", 0); - print '
'.$out; + print '
'.$out; print '
'; } else { print ''; @@ -267,9 +267,9 @@ if ( !empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STR \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY); $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID); $endpoint->enabled_events = $stripearrayofwebhookevents; -if ( GETPOST('webhook','alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { -if ( empty( GETPOST('status','alpha') )) { -$endpoint->disabled = true; +if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { +if ( empty( GETPOST('status', 'alpha') )) { +$endpoint->disabled = true; } else { $endpoint->disabled = false; }} @@ -278,15 +278,15 @@ $endpoint->save(); if ($endpoint->status == 'enabled') { print ''; - print img_picto($langs->trans("Activated"),'switch_on'); + print img_picto($langs->trans("Activated"), 'switch_on'); } else { print ''; - print img_picto($langs->trans("Disabled"),'switch_off'); + print img_picto($langs->trans("Disabled"), 'switch_off'); } //print $endpoint; -} else print img_picto($langs->trans("inactive"),'statut5'); +} else print img_picto($langs->trans("inactive"), 'statut5'); print ''; } else From 99e56f9cfa455574b8c8028bdace07e0f7976229 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 24 Apr 2019 14:53:31 +0200 Subject: [PATCH 3/5] Update stripe.php --- htdocs/stripe/admin/stripe.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index f0b9c6361bf..50d4fbf281b 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -209,7 +209,7 @@ if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID ) { if ( empty( GETPOST('status', 'alpha') )) { $endpoint->disabled = true; } else { -$endpoint->disabled = false; + $endpoint->disabled = false; }} $endpoint->url = dol_buildpath('/public/stripe/ipn.php?test', 2); $endpoint->save(); @@ -269,9 +269,9 @@ $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK $endpoint->enabled_events = $stripearrayofwebhookevents; if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { if ( empty( GETPOST('status', 'alpha') )) { -$endpoint->disabled = true; + $endpoint->disabled = true; } else { -$endpoint->disabled = false; + $endpoint->disabled = false; }} $endpoint->url = dol_buildpath('/public/stripe/ipn.php', 2); $endpoint->save(); From c485cc7a89b853f1ef596e712cabc33b4ab5c963 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 24 Apr 2019 15:41:08 +0200 Subject: [PATCH 4/5] Update stripe.php --- htdocs/stripe/admin/stripe.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 50d4fbf281b..54102b99df5 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -206,7 +206,7 @@ if ( !empty($conf->global->STRIPE_TEST_WEBHOOK_KEY) && !empty($conf->global->STR $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID); $endpoint->enabled_events = $stripearrayofwebhookevents; if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID ) { -if ( empty( GETPOST('status', 'alpha') )) { +if ( empty(GETPOST('status', 'alpha')) ) { $endpoint->disabled = true; } else { $endpoint->disabled = false; @@ -261,14 +261,14 @@ if (empty($conf->stripeconnect->enabled)) $url = dol_buildpath('/public/stripe/ipn.php', 2); $out.= ''; $out.= ajax_autoselect("onlinelivewebhookurl", 0); - print '
'.$out; + print '
'.$out; print '
'; print ''; + if ( !empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID) ) { + \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY); + $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID); + $endpoint->enabled_events = $stripearrayofwebhookevents; + if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { + if ( empty(GETPOST('status', 'alpha')) ) { + $endpoint->disabled = true; + } else { + $endpoint->disabled = false; + }} + $endpoint->url = dol_buildpath('/public/stripe/ipn.php', 3); + $endpoint->save(); + if ($endpoint->status == 'enabled') + { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on'); + } + else + { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + } + //print $endpoint; + } else print img_picto($langs->trans("inactive"), 'statut5'); + print ''; } else {
'.$langs->trans("AccountParameter").''.$langs->trans("Value").''.$langs->trans("Status").'
'; print ''; print '   '.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; - print '
'; print ''.$langs->trans("STRIPE_TEST_SECRET_KEY").''; print ''; print '   '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; - print '
'; - print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; + print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; + print ''; + print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; - $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").'
'; + $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").'
'; $url = dol_buildpath('/public/stripe/ipn.php?test', 2); $out.= ''; $out.= ajax_autoselect("onlinetestwebhookurl", 0); - print '
'.$out; - print '
'; +if ( !empty($conf->global->STRIPE_TEST_WEBHOOK_KEY) && !empty($conf->global->STRIPE_TEST_SECRET_KEY) && !empty($conf->global->STRIPE_TEST_WEBHOOK_ID) ) { +\Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY); +$endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID); +$endpoint->enabled_events = $stripearrayofwebhookevents; +if ( GETPOST('webhook','alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID ) { +if ( empty( GETPOST('status','alpha') )) { +$endpoint->disabled = true; +} else { +$endpoint->disabled = false; +}} +$endpoint->url = dol_buildpath('/public/stripe/ipn.php?test', 2); +$endpoint->save(); +if ($endpoint->status == 'enabled') +{ + print ''; + print img_picto($langs->trans("Activated"),'switch_on'); +} +else +{ + print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); +} +//print $endpoint; +} else print img_picto($langs->trans("inactive"),'statut5'); + print'
'.$langs->trans("StripeConnect").''.$langs->trans("StripeConnect_Mode").'
'; @@ -212,24 +243,51 @@ if (empty($conf->stripeconnect->enabled)) print ''.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'
'; print ''; print '   '.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; - print '
'; print ''.$langs->trans("STRIPE_LIVE_SECRET_KEY").''; print ''; print '   '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; - print '
'; - print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; + print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; + print ''; + print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").'
'; $url = dol_buildpath('/public/stripe/ipn.php', 2); $out.= ''; $out.= ajax_autoselect("onlinelivewebhookurl", 0); - print '
'.$out; - print '
'; +if ( !empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID) ) { +\Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY); +$endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID); +$endpoint->enabled_events = $stripearrayofwebhookevents; +if ( GETPOST('webhook','alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { +if ( empty( GETPOST('status','alpha') )) { +$endpoint->disabled = true; +} else { +$endpoint->disabled = false; +}} +$endpoint->url = dol_buildpath('/public/stripe/ipn.php', 2); +$endpoint->save(); +if ($endpoint->status == 'enabled') +{ + print ''; + print img_picto($langs->trans("Activated"),'switch_on'); +} +else +{ + print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); +} +//print $endpoint; +} else print img_picto($langs->trans("inactive"),'statut5'); + print '
'; if ( !empty($conf->global->STRIPE_TEST_WEBHOOK_KEY) && !empty($conf->global->STRIPE_TEST_SECRET_KEY) && !empty($conf->global->STRIPE_TEST_WEBHOOK_ID) ) { \Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY); $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID); $endpoint->enabled_events = $stripearrayofwebhookevents; -if ( GETPOST('webhook','alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID ) { -if ( empty( GETPOST('status','alpha') )) { -$endpoint->disabled = true; +if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID ) { +if ( empty( GETPOST('status', 'alpha') )) { + $endpoint->disabled = true; } else { $endpoint->disabled = false; }} @@ -216,15 +216,15 @@ $endpoint->save(); if ($endpoint->status == 'enabled') { print ''; - print img_picto($langs->trans("Activated"),'switch_on'); + print img_picto($langs->trans("Activated"), 'switch_on'); } else { print ''; - print img_picto($langs->trans("Disabled"),'switch_off'); + print img_picto($langs->trans("Disabled"), 'switch_off'); } //print $endpoint; -} else print img_picto($langs->trans("inactive"),'statut5'); +} else print img_picto($langs->trans("inactive"), 'statut5'); print'
'.$langs->trans("StripeConnect").'
'; if ( !empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID) ) { \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY); $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID); $endpoint->enabled_events = $stripearrayofwebhookevents; if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { -if ( empty( GETPOST('status', 'alpha') )) { +if ( empty(GETPOST('status', 'alpha')) ) { $endpoint->disabled = true; } else { $endpoint->disabled = false; From 77f92a5da32bb9949fc75f5e78db708caad92a08 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2019 21:12:43 +0200 Subject: [PATCH 5/5] Update stripe.php --- htdocs/stripe/admin/stripe.php | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 02471d57a76..3135592d528 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -215,7 +215,7 @@ if ( empty(GETPOST('status', 'alpha')) ) { } else { $endpoint->disabled = false; }} -$endpoint->url = dol_buildpath('/public/stripe/ipn.php?test', 2); +$endpoint->url = dol_buildpath('/public/stripe/ipn.php?test', 3); $endpoint->save(); if ($endpoint->status == 'enabled') { @@ -256,8 +256,8 @@ if (empty($conf->stripeconnect->enabled)) print '
'; - print ''; - print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; + print ''; + print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'
'; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; @@ -267,31 +267,31 @@ if (empty($conf->stripeconnect->enabled)) $out.= ajax_autoselect("onlinelivewebhookurl", 0); print '
'.$out; print '
'; -if ( !empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID) ) { -\Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY); -$endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID); -$endpoint->enabled_events = $stripearrayofwebhookevents; -if ( GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID ) { -if ( empty(GETPOST('status', 'alpha')) ) { - $endpoint->disabled = true; -} else { - $endpoint->disabled = false; -}} -$endpoint->url = dol_buildpath('/public/stripe/ipn.php', 2); -$endpoint->save(); -if ($endpoint->status == 'enabled') -{ - print ''; - print img_picto($langs->trans("Activated"), 'switch_on'); -} -else -{ - print ''; - print img_picto($langs->trans("Disabled"), 'switch_off'); -} -//print $endpoint; -} else print img_picto($langs->trans("inactive"), 'statut5'); - print '