Skip to content

Commit

Permalink
Merge branch 'develop' into patch-153
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 24, 2019
2 parents c485cc7 + ab1f371 commit 8007b22
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 191 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
Expand Up @@ -112,7 +112,7 @@ class pdf_standard extends ModeleExpenseReport

/**
* Issuer
* @var Company object that emits
* @var Societe
*/
public $emetteur;

Expand Down Expand Up @@ -1053,18 +1053,18 @@ private function tablePayments(&$pdf, $object, $posy, $outputlangs)
$pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y);
$pdf->MultiCell(30, 4, $outputlangs->trans("AlreadyPaid"), 0, 'L', 0);
$pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AlreadyPaid"), 0, 'L', 0);
$y+=$tab3_height-2;
$pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y);
$pdf->MultiCell(30, 4, $outputlangs->trans("AmountExpected"), 0, 'L', 0);
$pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AmountExpected"), 0, 'L', 0);
$y+=$tab3_height-2;
$remaintopay = $object->total_ttc - $totalpaid;
$pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y);
$pdf->MultiCell(30, 4, $outputlangs->trans("RemainderToPay"), 0, 'L', 0);
$pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("RemainderToPay"), 0, 'L', 0);
}
}
else
Expand Down
45 changes: 25 additions & 20 deletions htdocs/core/tpl/onlinepaymentlinks.tpl.php
Expand Up @@ -29,21 +29,22 @@
// Url list
print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br><br>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'free')."</strong><br><br>\n";
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'free')."</strong><br><br>\n";
if (! empty($conf->commande->enabled))
{
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'order')."</strong><br>\n";
print '<div id="order"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':<br>';
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'order')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("orders");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<form action="'.$_SERVER["PHP_SELF"].'#order" 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 button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_order_ref', 'alpha'))
{
print '<br> -> <strong>';
print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'order', GETPOST('generate_order_ref', 'alpha'));
print $url;
print "</strong><br>\n";
Expand All @@ -54,18 +55,19 @@
}
if (! empty($conf->facture->enabled))
{
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'invoice')."</strong><br>\n";
print '<div id="invoice"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':<br>';
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'invoice')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("bills");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<form action="'.$_SERVER["PHP_SELF"].'#invoice" 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 button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_invoice_ref', 'alpha'))
{
print '<br> -> <strong>';
print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'invoice', GETPOST('generate_invoice_ref', 'alpha'));
print $url;
print "</strong><br>\n";
Expand All @@ -76,18 +78,19 @@
}
if (! empty($conf->contrat->enabled))
{
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'contractline')."</strong><br>\n";
print '<div id="contractline"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':<br>';
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'contractline')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("contracts");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<form action="'.$_SERVER["PHP_SELF"].'#contractline" method="POST">';
print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("ContractLine")).': ';
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 button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_contract_ref'))
{
print '<br> -> <strong>';
print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'contractline', GETPOST('generate_contract_ref', 'alpha'));
print $url;
print "</strong><br>\n";
Expand All @@ -98,18 +101,19 @@
}
if (! empty($conf->adherent->enabled))
{
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'membersubscription')."</strong><br>\n";
print '<div id="membersubscription"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':<br>';
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'membersubscription')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("members");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<form action="'.$_SERVER["PHP_SELF"].'#membersubscription" 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 reposition button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_member_ref'))
{
print '<br> -> <strong>';
print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'membersubscription', GETPOST('generate_member_ref', 'alpha'));
print $url;
print "</strong><br>\n";
Expand All @@ -120,18 +124,19 @@
}
if (! empty($conf->don->enabled))
{
print '<div id="donation"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnDonation", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'donation')."</strong><br>\n";
print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'donation')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
$langs->load("members");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<form action="'.$_SERVER["PHP_SELF"].'#donation" method="POST">';
print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Don")).': ';
print '<input type="text class="flat" id="generate_donation_ref" name="generate_donation_ref" value="'.GETPOST('generate_donation_ref', 'alpha').'" size="10">';
print '<input type="submit" class="none reposition button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_donation_ref'))
{
print '<br> -> <strong>';
print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'donation', GETPOST('generate_donation_ref', 'alpha'));
print $url;
print "</strong><br>\n";
Expand Down
4 changes: 3 additions & 1 deletion htdocs/langs/en_US/stripe.lang
Expand Up @@ -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
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)
26 changes: 14 additions & 12 deletions htdocs/public/payment/newpayment.php
Expand Up @@ -263,7 +263,7 @@
* Actions
*/

// Action dopayment is called after choosing the payment mode
// Action dopayment is called after clicking/choosing the payment mode
if ($action == 'dopayment')
{
if ($paymentmethod == 'paypal')
Expand Down Expand Up @@ -395,7 +395,7 @@
}


// Called when choosing Stripe mode, after the 'dopayment'
// Called when choosing Stripe mode, after clicking the 'dopayment'
if ($action == 'charge' && ! empty($conf->stripe->enabled))
{
$amountstripe = $amount;
Expand Down Expand Up @@ -509,7 +509,7 @@
if (empty($vatcleaned)) $taxinfo=null;

dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe');
$customer = \Stripe\Customer::create(array(
$customer = \Stripe\Customer::create(array(
'email' => $email,
'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'),
'metadata' => $metadata,
Expand All @@ -525,7 +525,7 @@
// The customer was just created with a source, so we can make a charge
// with no card defined, the source just used for customer creation will be used.
dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
$charge = \Stripe\Charge::create(array(
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => price2num($amountstripe, 'MU'),
'currency' => $currency,
Expand Down Expand Up @@ -1658,7 +1658,7 @@
if (preg_match('/^dopayment/', $action))
{

// Strip
// Stripe
if (GETPOST('dopayment_stripe', 'alpha'))
{
// Simple checkout
Expand Down Expand Up @@ -1727,26 +1727,28 @@ class="stripe-button"
<tbody><tr><td class="textpublicpayment">
<div class="form-row left">
<label for="card-element">
'.$langs->trans("CreditOrDebitCard").'
</label>
<label for="card-element">'.$langs->trans("CreditOrDebitCard").'</label>
<div id="card-element">
<!-- a Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors -->
<div id="card-errors" role="alert"></div>
</div>
<br>
<button class="butAction" id="buttontopay">'.$langs->trans("ValidatePayment").'</button>
<img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif'.'">
</td></tr></tbody></table>
</form>
<script src="https://js.stripe.com/v3/"></script>
</form>'."\n";

<script type="text/javascript" language="javascript">';
print '<script src="https://js.stripe.com/v3/"></script>'."\n";

// Code to ask the credit card. This use the default "API version". No way to force API version when using JS code.
print '<script type="text/javascript" language="javascript">'."\n";
?>

// Create a Stripe client.
Expand Down

0 comments on commit 8007b22

Please sign in to comment.