From e572ca69c1fed2e6f19a93c72c3e4c7cbcbd8389 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 19 Feb 2019 16:43:00 +0100 Subject: [PATCH 1/9] Update stripe version api for payment intent --- htdocs/stripe/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index fb0ef25f8bdee..a0234d3c9a2b0 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -55,4 +55,4 @@ \Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version -\Stripe\Stripe::setApiVersion("2018-11-08"); // force version API +\Stripe\Stripe::setApiVersion("2018-02-11"); // force version API From e8a6b64b6b2957aa37b0f37cf0e02aba78265d88 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 19 Feb 2019 16:50:05 +0100 Subject: [PATCH 2/9] Update config.php --- htdocs/stripe/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index a0234d3c9a2b0..aa5d5889d9417 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -55,4 +55,4 @@ \Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version -\Stripe\Stripe::setApiVersion("2018-02-11"); // force version API +\Stripe\Stripe::setApiVersion("2019-02-11"); // force version API From 665174f9aaaba9af4101465156bf56b11741b565 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 19 Feb 2019 19:55:06 +0100 Subject: [PATCH 3/9] Update config.php --- htdocs/stripe/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index aa5d5889d9417..3b0e5ba9f6ebc 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -55,4 +55,4 @@ \Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version -\Stripe\Stripe::setApiVersion("2019-02-11"); // force version API +\Stripe\Stripe::setApiVersion("2019-02-19"); // force version API From 9da734569dcd6a4d76d2a51ed5842293a361581a Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 15 Mar 2019 12:34:21 +0100 Subject: [PATCH 4/9] Update config.php --- htdocs/stripe/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/stripe/config.php b/htdocs/stripe/config.php index 3b0e5ba9f6ebc..5638a10d332d1 100644 --- a/htdocs/stripe/config.php +++ b/htdocs/stripe/config.php @@ -55,4 +55,4 @@ \Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version -\Stripe\Stripe::setApiVersion("2019-02-19"); // force version API +\Stripe\Stripe::setApiVersion("2019-03-14"); // force version API From fe3fe60efc805162d093a49a36fba06ef76aa1fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2019 18:31:11 +0200 Subject: [PATCH 5/9] Cleaner setup page --- htdocs/core/tpl/onlinepaymentlinks.tpl.php | 45 ++++++++++++---------- htdocs/langs/en_US/stripe.lang | 4 +- htdocs/stripe/admin/stripe.php | 14 +++---- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/htdocs/core/tpl/onlinepaymentlinks.tpl.php b/htdocs/core/tpl/onlinepaymentlinks.tpl.php index b32fcf3658abc..990368d87381c 100644 --- a/htdocs/core/tpl/onlinepaymentlinks.tpl.php +++ b/htdocs/core/tpl/onlinepaymentlinks.tpl.php @@ -29,21 +29,22 @@ // Url list print ''.$langs->trans("FollowingUrlAreAvailableToMakePayments").':

'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount", $servicename).':
'; -print ''.getOnlinePaymentUrl(1, 'free')."

\n"; +print ''.getOnlinePaymentUrl(1, 'free')."

\n"; if (! empty($conf->commande->enabled)) { - print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':
'; - print ''.getOnlinePaymentUrl(1, 'order')."
\n"; + print '
'; + print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':
'; + print ''.getOnlinePaymentUrl(1, 'order')."
\n"; if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $langs->load("orders"); - print '
'; + print ''; print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Order")).': '; print ''; print ''; if (GETPOST('generate_order_ref', 'alpha')) { - print '
-> '; + print '
-> '; $url=getOnlinePaymentUrl(0, 'order', GETPOST('generate_order_ref', 'alpha')); print $url; print "
\n"; @@ -54,18 +55,19 @@ } if (! empty($conf->facture->enabled)) { - print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':
'; - print ''.getOnlinePaymentUrl(1, 'invoice')."
\n"; + print '
'; + print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':
'; + print ''.getOnlinePaymentUrl(1, 'invoice')."
\n"; if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $langs->load("bills"); - print ''; + print ''; print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Invoice")).': '; print ''; print ''; if (GETPOST('generate_invoice_ref', 'alpha')) { - print '
-> '; + print '
-> '; $url=getOnlinePaymentUrl(0, 'invoice', GETPOST('generate_invoice_ref', 'alpha')); print $url; print "
\n"; @@ -76,18 +78,19 @@ } if (! empty($conf->contrat->enabled)) { - print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':
'; - print ''.getOnlinePaymentUrl(1, 'contractline')."
\n"; + print '
'; + print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':
'; + print ''.getOnlinePaymentUrl(1, 'contractline')."
\n"; if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $langs->load("contracts"); - print ''; + print ''; print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("ContractLine")).': '; print ''; print ''; if (GETPOST('generate_contract_ref')) { - print '
-> '; + print '
-> '; $url=getOnlinePaymentUrl(0, 'contractline', GETPOST('generate_contract_ref', 'alpha')); print $url; print "
\n"; @@ -98,18 +101,19 @@ } if (! empty($conf->adherent->enabled)) { - print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':
'; - print ''.getOnlinePaymentUrl(1, 'membersubscription')."
\n"; + print '
'; + print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':
'; + print ''.getOnlinePaymentUrl(1, 'membersubscription')."
\n"; if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $langs->load("members"); - print ''; + print ''; print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Member")).': '; print ''; print ''; if (GETPOST('generate_member_ref')) { - print '
-> '; + print '
-> '; $url=getOnlinePaymentUrl(0, 'membersubscription', GETPOST('generate_member_ref', 'alpha')); print $url; print "
\n"; @@ -120,18 +124,19 @@ } if (! empty($conf->don->enabled)) { + print '
'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnDonation", $servicename).':
'; - print ''.getOnlinePaymentUrl(1, 'donation')."
\n"; + print ''.getOnlinePaymentUrl(1, 'donation')."
\n"; if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $langs->load("members"); - print ''; + print ''; print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Don")).': '; print ''; print ''; if (GETPOST('generate_donation_ref')) { - print '
-> '; + print '
-> '; $url=getOnlinePaymentUrl(0, 'donation', GETPOST('generate_donation_ref', 'alpha')); print $url; print "
\n"; diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 46de5f4485b19..64ce7b15aff58 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -62,4 +62,6 @@ CreateCustomerOnStripe=Create customer on Stripe CreateCardOnStripe=Create card on Stripe ShowInStripe=Show in Stripe StripeUserAccountForActions=User account to use for email notification of some Stripe events (Stripe payouts) -StripePayoutList=List of Stripe payouts \ No newline at end of file +StripePayoutList=List of Stripe payouts +ToOfferALinkForTestWebhook=Link to setup Stripe WebHook to call the IPN (test mode) +ToOfferALinkForLiveWebhook=Link to setup Stripe WebHook to call the IPN (live mode) \ No newline at end of file diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 5e2c27dd3928d..39a9c1a249d9b 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -187,11 +187,11 @@ print ''; print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; - print ''; + print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; - $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").'
'; + $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").' '; $url = dol_buildpath('/public/stripe/ipn.php?test', 2); - $out.= ''; + $out.= ''; $out.= ajax_autoselect("onlinetestwebhookurl", 0); print '
'.$out; print ''; @@ -222,11 +222,11 @@ print ''; print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; - print ''; + print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; - $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").'
'; - $url = dol_buildpath('/public/stripe/ipn.php', 2); - $out.= ''; + $out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").' '; + $url = dol_buildpath('/public/stripe/ipn.php', 2); + $out.= ''; $out.= ajax_autoselect("onlinelivewebhookurl", 0); print '
'.$out; print ''; From 79c37f2226574b9ee3e5110f415ee443686e2e78 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2019 18:47:11 +0200 Subject: [PATCH 6/9] 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 70f3e87eaf979..b73d59c6cfdc2 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 39a9c1a249d9b..454dbb23775d2 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -41,6 +41,10 @@ $action = GETPOST('action', 'alpha'); +/* + * Actions + */ + if ($action == 'setvalue' && $user->admin) { $db->begin(); @@ -190,7 +194,7 @@ 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 @@ 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; From 8d2850659516e1a343d26df4d87d8d06aed42bce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2019 19:25:04 +0200 Subject: [PATCH 7/9] Better code --- htdocs/public/payment/newpayment.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 1d3f14c3a3797..613505b873c8e 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1727,26 +1727,28 @@ class="stripe-button"
- + +
+ +
+
- - - + '."\n"; - '."\n"; + // Code to ask the credit card. This use the default "API version". No way to force API version when using JS code. + print '