26 require
'../../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
28 use OAuth\Common\Storage\DoliStorage;
29 use OAuth\Common\Consumer\Credentials;
30 use OAuth\OAuth2\Service\GitHub;
33 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
34 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
38 $action =
GETPOST(
'action',
'aZ09');
39 $backtourl =
GETPOST(
'backtourl',
'alpha');
40 $keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
41 if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
42 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
52 $currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/stripelive_oauthcallback.php');
60 $serviceFactory = new \OAuth\ServiceFactory();
61 $httpClient = new \OAuth\Common\Http\Client\CurlClient();
65 $serviceFactory->setHttpClient($httpClient);
68 $storage =
new DoliStorage($db, $conf);
71 $keyforparamid =
'OAUTH_STRIPE_LIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
72 $keyforparamsecret =
'OAUTH_STRIPE_LIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
73 $credentials =
new Credentials(
76 $currentUri->getAbsoluteUri()
79 $requestedpermissionsarray = array();
81 $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
93 $servicesuffix = ($keyforprovider ?
'-'.$keyforprovider :
'');
94 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token SET service = 'StripeLive".$db->escape($servicesuffix).
"', entity = ".((int) $conf->entity);
100 $langs->load(
"oauth");
103 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
106 accessforbidden(
'Setup of service is not complete. Secret key is missing');
115 if ($action ==
'delete') {
116 $storage->clearToken(
'StripeLive');
120 header(
'Location: '.$backtourl);
124 if (!empty($_GET[
'code'])) {
128 dol_syslog(
"We are coming from the oauth provider page");
136 $state = isset($_GET[
'state']) ? $_GET[
'state'] :
null;
146 $token = $apiService->requestAccessToken($_GET[
'code']);
154 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
155 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
157 header(
'Location: '.$backtourl);
160 print $e->getMessage();
164 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
165 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
166 $_SESSION[
'oauthstateanticsrf'] = $state;
171 $url = $apiService->getAuthorizationUri(array(
'state'=>
GETPOST(
'state')));
175 $url =
'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->$keyforparamid.
'&scope=read_write';
179 header(
'Location: '.$url);
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
if(empty($keyforprovider) &&!empty($_SESSION["oauthkeyforproviderbeforeoauthjump"]) &&(GETPOST('code')|| $action=='delete')) $uriFactory
Create a new instance of the URI class with the current URI, stripping the query string.