Standardize code for payment

This commit is contained in:
Laurent Destailleur 2017-05-13 22:05:58 +02:00
parent 8dcec30d89
commit 0ed4b607b2
8 changed files with 195 additions and 47 deletions

View File

@ -43,6 +43,7 @@ $action = GETPOST('action','alpha');
if ($action == 'setvalue' && $user->admin)
{
$db->begin();
$result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",GETPOST('PAYPAL_API_SANDBOX','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);

View File

@ -86,8 +86,21 @@ if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL))
$sendto=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define link to login card
$appli=constant('DOL_APPLICATION_TITLE');
if (! empty($conf->global->MAIN_APPLICATION_TITLE))
{
$appli=$conf->global->MAIN_APPLICATION_TITLE;
if (preg_match('/\d\.\d/', $appli))
{
if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
}
else $appli.=" ".DOL_VERSION;
}
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentFailed");
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentFailed");
$content=$langs->transnoentitiesnoconv("NewPayboxPaymentFailed")."\n".$fulltag;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($topic, $sendto, $from, $content);

View File

@ -135,8 +135,21 @@ if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL))
$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
// Define link to login card
$appli=constant('DOL_APPLICATION_TITLE');
if (! empty($conf->global->MAIN_APPLICATION_TITLE))
{
$appli=$conf->global->MAIN_APPLICATION_TITLE;
if (preg_match('/\d\.\d/', $appli))
{
if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
}
else $appli.=" ".DOL_VERSION;
}
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentReceived");
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentReceived");
$tmptag=dolExplodeIntoArray($fulltag,'.','=');
$content="";
if (! empty($tmptag['MEM']))

View File

@ -1,11 +1,11 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
* 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
* 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,
@ -23,7 +23,6 @@
* \file htdocs/public/paypal/newpayment.php
* \ingroup paypal
* \brief File to offer a way to make a payment for a particular Dolibarr entity
* \author Laurent Destailleur
*/
define("NOLOGIN",1); // This means this output page does not require to be logged.
@ -353,7 +352,7 @@ $error=0;
$var=false;
// Free payment
if (! GETPOST("source") && $valid)
if (! GETPOST("source"))
{
$found=true;
$tag=GETPOST("tag");
@ -400,7 +399,7 @@ if (! GETPOST("source") && $valid)
// Payment on customer order
if (GETPOST("source") == 'order' && $valid)
if (GETPOST("source") == 'order')
{
$found=true;
$langs->load("orders");
@ -507,7 +506,7 @@ if (GETPOST("source") == 'order' && $valid)
// Payment on customer invoice
if (GETPOST("source") == 'invoice' && $valid)
if (GETPOST("source") == 'invoice')
{
$found=true;
$langs->load("bills");
@ -613,7 +612,7 @@ if (GETPOST("source") == 'invoice' && $valid)
}
// Payment on contract line
if (GETPOST("source") == 'contractline' && $valid)
if (GETPOST("source") == 'contractline')
{
$found=true;
$langs->load("contracts");
@ -808,7 +807,7 @@ if (GETPOST("source") == 'contractline' && $valid)
}
// Payment on member subscription
if (GETPOST("source") == 'membersubscription' && $valid)
if (GETPOST("source") == 'membersubscription')
{
$found=true;
$langs->load("members");

View File

@ -108,8 +108,21 @@ if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL))
$sendto=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define link to login card
$appli=constant('DOL_APPLICATION_TITLE');
if (! empty($conf->global->MAIN_APPLICATION_TITLE))
{
$appli=$conf->global->MAIN_APPLICATION_TITLE;
if (preg_match('/\d\.\d/', $appli))
{
if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
}
else $appli.=" ".DOL_VERSION;
}
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentFailed");
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentFailed");
$content=$langs->transnoentitiesnoconv("NewPaypalPaymentFailed")."\ntag=".$fulltag."\ntoken=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($topic, $sendto, $from, $content);

View File

@ -188,8 +188,21 @@ if ($PAYPALTOKEN)
$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
// Define link to login card
$appli=constant('DOL_APPLICATION_TITLE');
if (! empty($conf->global->MAIN_APPLICATION_TITLE))
{
$appli=$conf->global->MAIN_APPLICATION_TITLE;
if (preg_match('/\d\.\d/', $appli))
{
if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
}
else $appli.=" ".DOL_VERSION;
}
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentReceived");
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentReceived");
$tmptag=dolExplodeIntoArray($fulltag,'.','=');
$content="";
if (! empty($tmptag['MEM']))
@ -258,8 +271,21 @@ if ($PAYPALTOKEN)
$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
// Define link to login card
$appli=constant('DOL_APPLICATION_TITLE');
if (! empty($conf->global->MAIN_APPLICATION_TITLE))
{
$appli=$conf->global->MAIN_APPLICATION_TITLE;
if (preg_match('/\d\.\d/', $appli))
{
if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core
}
else $appli.=" ".DOL_VERSION;
}
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("ValidationOfPaypalPaymentFailed");
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("ValidationOfPaypalPaymentFailed");
$content="";
$content.=$langs->transnoentitiesnoconv("PaypalConfirmPaymentPageWasCalledButFailed")."\n";
$content.="\n";

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2017 Saasprov <saasprov@gmail.com>
* Copyright (C) 2017 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
@ -35,6 +36,7 @@ if (empty($conf->stripe->enabled)) accessforbidden('',0,0,1);
$langs->load("main");
$langs->load("other");
$langs->load("paybox"); // File with generic data
$langs->load("stripe");
$source=GETPOST("source",'alpha');

View File

@ -36,8 +36,7 @@ $langs->load("paypal");
$langs->load("paybox");
$langs->load("stripe");
if (!$user->admin)
accessforbidden();
if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
@ -96,6 +95,8 @@ if ($action=="setlive")
* View
*/
$form=new Form($db);
$SECRET_TEST_KEY="sk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test secret key
if (empty($conf->global->STRIPE_TEST_SECRET_KEY)) $conf->global->STRIPE_TEST_SECRET_KEY = $SECRET_TEST_KEY;
$PUBLISHABLE_TEST_KEY="pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test publishable key
@ -108,10 +109,8 @@ if (empty($conf->global->STRIPE_LIVE_PUBLISHABLE_KEY)) $conf->global->STRIPE_LIV
llxHeader('',$langs->trans("StripeSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("ModuleSetup").' Stripe',$linkback);
print '<br>';
$head=stripeadmin_prepare_head();
@ -119,22 +118,19 @@ print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setvalue">';
dol_fiche_head($head, 'stripeaccount', '');
dol_fiche_head($head, 'stripeaccount', '', -1);
print $langs->trans("StripeDesc")."<br>\n";
print '<br>';
$var=true;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AccountParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n";
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<tr class="oddeven">';
print '<td class="titlefield fieldrequired">';
print $langs->trans("StripeLiveEnabled").'</td><td>';
if (!empty($conf->global->STRIPE_LIVE))
@ -149,29 +145,25 @@ else
}
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">';
print '<br>'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">';
print '<br>'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
@ -187,29 +179,25 @@ print '<td>'.$langs->trans("UsageParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n";
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print $langs->trans("VendorName").'</td><td>';
print '<input size="64" type="text" name="STRIPE_CREDITOR" value="'.$conf->global->STRIPE_CREDITOR.'">';
print '<br>'.$langs->trans("Example").': '.$mysoc->name;
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
print '<input size="64" type="text" name="STRIPE_CSS_URL" value="'.$conf->global->STRIPE_CSS_URL.'">';
print '<br>'.$langs->trans("Example").': http://mysite/mycss.css';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print $langs->trans("MessageOK").'</td><td>';
$doleditor=new DolEditor('STRIPE_MESSAGE_OK',$conf->global->STRIPE_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_2,'90%');
$doleditor->Create();
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr class="oddeven"><td>';
print $langs->trans("MessageKO").'</td><td>';
$doleditor=new DolEditor('STRIPE_MESSAGE_KO',$conf->global->STRIPE_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_2,'90%');
$doleditor->Create();
@ -225,35 +213,128 @@ print '</form>';
print '<br><br>';
/*
$token='';
// Url list
print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br>';
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount",$servicename).':<br>';
print '<b>'.DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount=<i>9.99</i>&tag=<i>your_free_tag</i></b>'."<br>\n";
print '<strong>'.getStripePaymentUrl(1,'free')."</strong><br><br>\n";
if (! empty($conf->commande->enabled))
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
print '<b>'.DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref=<i>order_ref</i></b>'."<br>\n";
print '<strong>'.getStripePaymentUrl(1,'order')."</strong><br>\n";
if (! empty($conf->global->STRIPE_SECURITY_TOKEN) && ! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
{
$langs->load("orders");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Order")).': ';
print '<input type="text class="flat" id="generate_order_ref" name="generate_order_ref" value="'.GETPOST('generate_order_ref','alpha').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_order_ref','alpha'))
{
print '<br> -> <strong>';
$url=getStripePaymentUrl(0,'order',GETPOST('generate_order_ref','alpha'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
print '<br>';
}
if (! empty($conf->facture->enabled))
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
print '<b>'.DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref=<i>invoice_ref</i></b>'."<br>\n";
print '<strong>'.getStripePaymentUrl(1,'invoice')."</strong><br>\n";
if (! empty($conf->global->STRIPE_SECURITY_TOKEN) && ! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
{
$langs->load("bills");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Invoice")).': ';
print '<input type="text class="flat" id="generate_invoice_ref" name="generate_invoice_ref" value="'.GETPOST('generate_invoice_ref','alpha').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_invoice_ref','alpha'))
{
print '<br> -> <strong>';
$url=getPaypalPaymentUrl(0,'invoice',GETPOST('generate_invoice_ref','alpha'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
print '<br>';
}
if (! empty($conf->contrat->enabled))
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
print '<b>'.DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref=<i>contractline_ref</i></b>'."<br>\n";
print '<strong>'.getStripePaymentUrl(1,'contractline')."</strong><br>\n";
if (! empty($conf->global->STRIPE_SECURITY_TOKEN) && ! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
{
$langs->load("contract");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Contract")).': ';
print '<input type="text class="flat" id="generate_contract_ref" name="generate_contract_ref" value="'.GETPOST('generate_contract_ref','alpha').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_contract_ref'))
{
print '<br> -> <strong>';
$url=getPaypalPaymentUrl(0,'contractline',GETPOST('generate_contract_ref','alpha'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
print '<br>';
}
if (! empty($conf->adherent->enabled))
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
print '<b>'.DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref=<i>member_ref</i></b>'."<br>\n";
print '<strong>'.getStripePaymentUrl(1,'membersubscription')."</strong><br>\n";
if (! empty($conf->global->STRIPE_SECURITY_TOKEN) && ! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
{
$langs->load("members");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Member")).': ';
print '<input type="text class="flat" id="generate_member_ref" name="generate_member_ref" value="'.GETPOST('generate_member_ref','alpha').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_member_ref'))
{
print '<br> -> <strong>';
$url=getPaypalPaymentUrl(0,'membersubscription',GETPOST('generate_member_ref','alpha'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
}
print "<br>";
print info_admin($langs->trans("YouCanAddTagOnUrl"));
*/
if (! empty($conf->use_javascript_ajax))
{
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#apidoca").hide();
$("#apidoca").click(function() {
$("#apidoc").show();
$("#apidoca").hide();
});
$("#generate_token").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
action: \'getrandompassword\',
generic: true
},
function(token) {
$("#STRIPE_SECURITY_TOKEN").val(token);
});
});
});';
print '</script>';
}
llxFooter();
$db->close();