Skip to content

Commit

Permalink
Fix link for endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 24, 2019
1 parent fe3fe60 commit 79c37f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
37 changes: 23 additions & 14 deletions htdocs/core/lib/payments.lib.php
Expand Up @@ -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?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
$out=$urltouse.'/public/payment/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
{
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
Expand All @@ -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?'<font color="#666666">':'');
$out=$urltouse.'/public/payment/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='order_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
Expand All @@ -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?'<font color="#666666">':'');
$out=$urltouse.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='invoice_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
Expand All @@ -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?'<font color="#666666">':'');
$out=$urltouse.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='contractline_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
Expand All @@ -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?'<font color="#666666">':'');
$out=$urltouse.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='member_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
Expand All @@ -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?'<font color="#666666">':'');
$out=$urltouse.'/public/payment/newpayment.php?source=donation&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='donation_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
Expand Down
8 changes: 6 additions & 2 deletions htdocs/stripe/admin/stripe.php
Expand Up @@ -41,6 +41,10 @@
$action = GETPOST('action', 'alpha');


/*
* Actions
*/

if ($action == 'setvalue' && $user->admin)
{
$db->begin();
Expand Down Expand Up @@ -190,7 +194,7 @@
print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.$conf->global->STRIPE_TEST_WEBHOOK_KEY.'">';
print ' &nbsp; '.$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.= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'">';
$out.= ajax_autoselect("onlinetestwebhookurl", 0);
print '<br>'.$out;
Expand Down Expand Up @@ -225,7 +229,7 @@
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">';
print ' &nbsp; '.$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.= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'">';
$out.= ajax_autoselect("onlinelivewebhookurl", 0);
print '<br>'.$out;
Expand Down

0 comments on commit 79c37f2

Please sign in to comment.