Clean dead code: Function showStripePaymentUrl, getStripePaymentUrl,

showPaypalPaymentUrl and getPaypalPaymentUrl has been removed. The
generic one showOnlinePaymentUrl and getOnlinePaymentUrl are always
used.
This commit is contained in:
Laurent Destailleur 2020-12-07 11:01:08 +01:00
parent 8b3edd36ea
commit 030df716a2
6 changed files with 167 additions and 211 deletions

View File

@ -243,7 +243,7 @@ Following changes may create regressions for some external modules, but were nec
* The API addPayment for api_invoice has evolved to accept amount into a foreign currency. You must provide array(amount=>X,mutlicurrency_ammount=>Y) instead of simple amount.
* The method select_thirdparty(), deprecated since 3.8, into html.form.class.php has been removed.
* Depreciate all methods with name ->valide(). Use instead methods ->validate().
* Function showStripePaymentUrl, getStripePaymentUrl, showPaypalPaymentUrl and getPaypalPaymentUrl has been removed. The generic one showOnlinePaymentUrl and getOnlinePaymentUrl are always used.
***** ChangeLog for 12.0.3 compared to 12.0.2 *****

View File

@ -22,6 +22,8 @@
* \brief Library for common paypal functions
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
/**
* Define head array for tabs of paypal tools setup pages
@ -54,131 +56,6 @@ function paypaladmin_prepare_head()
}
/**
* Return string with full Url
*
* @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
* @param string $ref Ref of object
* @return string Url string
*/
function showPaypalPaymentUrl($type, $ref)
{
global $conf, $langs;
$langs->load("paypal");
$langs->load("paybox");
$servicename = 'PayPal';
$out = '<br><br>';
$out .= img_picto('', 'globe').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
$url = getPaypalPaymentUrl(0, $type, $ref);
$out .= '<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'">';
$out .= ajax_autoselect("paypalurl", 0);
return $out;
}
/**
* 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
* @param string $freetag Free tag
* @return string Url string
*/
function getPaypalPaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag')
{
global $conf;
$ref = str_replace(' ', '', $ref);
if ($type == 'free')
{
$out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else $out .= '&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
}
}
if ($type == 'order')
{
$out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'order_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else {
$out .= '&securekey='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
$out .= ($mode ? '</font>' : '');
}
}
}
if ($type == 'invoice')
{
$out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'invoice_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else {
$out .= '&securekey='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
$out .= ($mode ? '</font>' : '');
}
}
}
if ($type == 'contractline')
{
$out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'contractline_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else {
$out .= '&securekey='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
$out .= ($mode ? '</font>' : '');
}
}
}
if ($type == 'membersubscription')
{
$out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'member_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else {
$out .= '&securekey='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
$out .= ($mode ? '</font>' : '');
}
}
}
// For multicompany
$out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
return $out;
}
/**
* Send redirect to paypal to browser
*

View File

@ -21,6 +21,8 @@
* \brief Library for common stripe functions
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
/**
* Define head array for tabs of stripe tools setup pages
*
@ -52,87 +54,6 @@ function stripeadmin_prepare_head()
}
/**
* Return string with full Url
*
* @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
* @param string $ref Ref of object
* @return string Url string
*/
function showStripePaymentUrl($type, $ref)
{
global $conf, $langs;
$langs->load("paypal");
$langs->load("paybox");
$langs->load("stripe");
$servicename = 'Stripe';
$out = '<br><br>';
$out .= img_picto('', 'globe').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
$url = getStripePaymentUrl(0, $type, $ref);
$out .= '<input type="text" id="stripeurl" class="quatrevingtpercent" value="'.$url.'"><br>';
$out .= ajax_autoselect("stripeurl", 0);
return $out;
}
/**
* 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
* @param string $freetag Free tag
* @return string Url string
*/
function getStripePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag')
{
global $conf;
$ref = str_replace(' ', '', $ref);
if ($type == 'free')
{
$out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
}
if ($type == 'order')
{
$out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'order_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
}
if ($type == 'invoice')
{
$out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'invoice_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
}
if ($type == 'contractline')
{
$out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'contractline_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
}
if ($type == 'membersubscription')
{
$out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
if ($mode == 1) $out .= 'member_ref';
if ($mode == 0) $out .= urlencode($ref);
$out .= ($mode ? '</font>' : '');
}
// For multicompany
$out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
return $out;
}
/**
* Show footer of company in HTML pages
*

View File

@ -258,6 +258,8 @@ class AllTests
require_once dirname(__FILE__).'/PaypalTest.php';
$suite->addTestSuite('PaypalTest');
require_once dirname(__FILE__).'/StripeTest.php';
$suite->addTestSuite('StripeTest');
return $suite;
}

View File

@ -131,7 +131,7 @@ class PaypalTest extends PHPUnit\Framework\TestCase
}
/**
* testProductCreate
* testPaypalOk
*
* @return void
*/
@ -143,13 +143,13 @@ class PaypalTest extends PHPUnit\Framework\TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$urltotest=getPaypalPaymentUrl(0, 'free');
$urltotest=getOnlinePaymentUrl(0, 'free');
print "urltotest=".$urltotest."\n";
$result=getURLContent($urltotest, 'GET', '', 1, array(), array('http', 'https'), 2);
print __METHOD__." result=".$result."\n";
$this->assertLessThanOrEqual($result, 0);
print __METHOD__." result=".$result['http_code']."\n";
$this->assertEquals(200, $result['http_code']);
return $result;
}

156
test/phpunit/StripeTest.php Normal file
View File

@ -0,0 +1,156 @@
<?php
/* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file test/phpunit/StripeTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php';
require_once dirname(__FILE__).'/../../htdocs/stripe/lib/stripe.lib.php';
if (empty($user->id))
{
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class StripeTest extends PHPUnit\Framework\TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return ProductTest
*/
public function __construct()
{
parent::__construct();
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
/**
* setUpBeforeClass
*
* @return void
*/
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
if (empty($conf->stripe->enabled)) { print __METHOD__." Module Stripe must be enabled.\n"; die(); }
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
/**
* tearDownAfterClass
*
* @return void
*/
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
}
/**
* testStripeOk
*
* @return void
*/
public function testStripeOk()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$urltotest=getOnlinePaymentUrl(0, 'free');
print "urltotest=".$urltotest."\n";
$result=getURLContent($urltotest, 'GET', '', 1, array(), array('http', 'https'), 2);
print __METHOD__." result=".$result['http_code']."\n";
$this->assertEquals(200, $result['http_code']);
return $result;
}
}