diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 454dbb23775..3135592d528 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'; @@ -154,6 +155,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 '
'; @@ -162,6 +165,7 @@ print ''; print ''; print ''; print ''; +print ''; print "\n"; print ''; @@ -181,24 +185,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 {
'.$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 ''; + print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; print ''; 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.= ''; $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', 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'
'.$langs->trans("StripeConnect").''.$langs->trans("StripeConnect_Mode").'
'; @@ -216,15 +247,17 @@ 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 ''; + print '   '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx
'; print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'
'; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; @@ -232,8 +265,33 @@ if (empty($conf->stripeconnect->enabled)) $url = dol_buildpath('/public/stripe/ipn.php', 3); $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', 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 '