From 79c37f2226574b9ee3e5110f415ee443686e2e78 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2019 18:47:11 +0200 Subject: [PATCH] Fix link for endpoint --- htdocs/core/lib/payments.lib.php | 37 ++++++++++++++++++++------------ htdocs/stripe/admin/stripe.php | 8 +++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index 70f3e87eaf9..b73d59c6cfd 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -142,23 +142,32 @@ function showOnlinePaymentUrl($type, $ref) /** * Return string with full Url * - * @param int $mode 0=True url, 1=Url formated with colors - * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) - * @param string $ref Ref of object - * @param int $amount Amount (required for $type='free' only) - * @param string $freetag Free tag - * @return string Url string + * @param int $mode 0=True url, 1=Url formated with colors + * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) + * @param string $ref Ref of object + * @param int $amount Amount (required for $type='free' only) + * @param string $freetag Free tag + * @param string $localorexternal 0=Url for browser, 1=Url for external access + * @return string Url string */ -function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag') +function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag', $localorexternal=0) { - global $conf; + global $conf, $dolibarr_main_url_root; $ref=str_replace(' ', '', $ref); $out=''; + // Define $urlwithroot + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + $urltouse = DOL_MAIN_URL_ROOT; + if ($localorexternal) $urltouse = $urlwithroot; + if ($type == 'free') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?amount='.($mode?'':'').$amount.($mode?'':'').'&tag='.($mode?'':'').$freetag.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?amount='.($mode?'':'').$amount.($mode?'':'').'&tag='.($mode?'':'').$freetag.($mode?'':''); if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) { if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; @@ -167,7 +176,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } elseif ($type == 'order') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=order&ref='.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?source=order&ref='.($mode?'':''); if ($mode == 1) $out.='order_ref'; if ($mode == 0) $out.=urlencode($ref); $out.=($mode?'':''); @@ -185,7 +194,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } elseif ($type == 'invoice') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'':''); if ($mode == 1) $out.='invoice_ref'; if ($mode == 0) $out.=urlencode($ref); $out.=($mode?'':''); @@ -203,7 +212,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } elseif ($type == 'contractline') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'':''); if ($mode == 1) $out.='contractline_ref'; if ($mode == 0) $out.=urlencode($ref); $out.=($mode?'':''); @@ -221,7 +230,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } elseif ($type == 'member' || $type == 'membersubscription') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'':''); if ($mode == 1) $out.='member_ref'; if ($mode == 0) $out.=urlencode($ref); $out.=($mode?'':''); @@ -239,7 +248,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag } if ($type == 'donation') { - $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=donation&ref='.($mode?'':''); + $out=$urltouse.'/public/payment/newpayment.php?source=donation&ref='.($mode?'':''); if ($mode == 1) $out.='donation_ref'; if ($mode == 0) $out.=urlencode($ref); $out.=($mode?'':''); diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 39a9c1a249d..454dbb23775 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -41,6 +41,10 @@ if (! $user->admin) accessforbidden(); $action = GETPOST('action', 'alpha'); +/* + * Actions + */ + if ($action == 'setvalue' && $user->admin) { $db->begin(); @@ -190,7 +194,7 @@ if (empty($conf->stripeconnect->enabled)) print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").' '; - $url = dol_buildpath('/public/stripe/ipn.php?test', 2); + $url = dol_buildpath('/public/stripe/ipn.php?test', 3); $out.= ''; $out.= ajax_autoselect("onlinetestwebhookurl", 0); print '
'.$out; @@ -225,7 +229,7 @@ if (empty($conf->stripeconnect->enabled)) print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").' '; - $url = dol_buildpath('/public/stripe/ipn.php', 2); + $url = dol_buildpath('/public/stripe/ipn.php', 3); $out.= ''; $out.= ajax_autoselect("onlinelivewebhookurl", 0); print '
'.$out;