Merge pull request #11062 from ptibogxiv/patch-153
FIX: enhancement management of webhooks
This commit is contained in:
commit
b8a72cec2f
@ -2,7 +2,7 @@
|
||||
/* Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
||||
* Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2017 Saasprov <saasprov@gmail.com>
|
||||
* Copyright (C) 2018 ptibogxiv <support@ptibogxiv.net>
|
||||
* Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
|
||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
|
||||
*
|
||||
* 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';
|
||||
|
||||
@ -154,6 +155,8 @@ print '<input type="hidden" name="action" value="setvalue">';
|
||||
|
||||
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")."<br>\n";
|
||||
|
||||
print '<br>';
|
||||
@ -162,6 +165,7 @@ print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("AccountParameter").'</td>';
|
||||
print '<td>'.$langs->trans("Value").'</td>';
|
||||
print '<td>'.$langs->trans("Status").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
@ -181,24 +185,51 @@ if (empty($conf->stripeconnect->enabled))
|
||||
print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
print '</td></tr>';
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
print '</td></tr>';
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.$conf->global->STRIPE_TEST_WEBHOOK_ID.'">';
|
||||
print ' '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.$conf->global->STRIPE_TEST_WEBHOOK_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").' ';
|
||||
$url = dol_buildpath('/public/stripe/ipn.php?test', 3);
|
||||
$url = dol_buildpath('/public/stripe/ipn.php?test', 3);
|
||||
$out.= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'">';
|
||||
$out.= ajax_autoselect("onlinetestwebhookurl", 0);
|
||||
print '<br>'.$out;
|
||||
print '</td></tr>';
|
||||
print '<br />'.$out;
|
||||
print '</td><td>';
|
||||
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', 3);
|
||||
$endpoint->save();
|
||||
if ($endpoint->status == 'enabled')
|
||||
{
|
||||
print '<a href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
|
||||
print img_picto($langs->trans("Activated"), 'switch_on');
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
|
||||
print img_picto($langs->trans("Disabled"), 'switch_off');
|
||||
}
|
||||
//print $endpoint;
|
||||
} else print img_picto($langs->trans("inactive"), 'statut5');
|
||||
print'</td></tr>';
|
||||
} else {
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
|
||||
print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br/>';
|
||||
@ -216,15 +247,17 @@ if (empty($conf->stripeconnect->enabled))
|
||||
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
print '</td></tr>';
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
print '</td></tr>';
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_ID.'">';
|
||||
print ' '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>';
|
||||
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">';
|
||||
print ' '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
@ -232,8 +265,33 @@ if (empty($conf->stripeconnect->enabled))
|
||||
$url = dol_buildpath('/public/stripe/ipn.php', 3);
|
||||
$out.= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'">';
|
||||
$out.= ajax_autoselect("onlinelivewebhookurl", 0);
|
||||
print '<br>'.$out;
|
||||
print '</td></tr>';
|
||||
print '<br />'.$out;
|
||||
print '</td><td>';
|
||||
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 '<a href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
|
||||
print img_picto($langs->trans("Activated"), 'switch_on');
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
|
||||
print img_picto($langs->trans("Disabled"), 'switch_off');
|
||||
}
|
||||
//print $endpoint;
|
||||
} else print img_picto($langs->trans("inactive"), 'statut5');
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user