Merge branch 'develop' into patch-153

This commit is contained in:
Laurent Destailleur 2019-04-24 21:10:27 +02:00 committed by GitHub
commit 8007b222d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 143 additions and 191 deletions

View File

@ -147,18 +147,27 @@ function showOnlinePaymentUrl($type, $ref)
* @param string $ref Ref of object * @param string $ref Ref of object
* @param int $amount Amount (required for $type='free' only) * @param int $amount Amount (required for $type='free' only)
* @param string $freetag Free tag * @param string $freetag Free tag
* @param string $localorexternal 0=Url for browser, 1=Url for external access
* @return string Url string * @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); $ref=str_replace(' ', '', $ref);
$out=''; $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') 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))
{ {
if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$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') 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 == 1) $out.='order_ref';
if ($mode == 0) $out.=urlencode($ref); if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':''); $out.=($mode?'</font>':'');
@ -185,7 +194,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag
} }
elseif ($type == 'invoice') 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 == 1) $out.='invoice_ref';
if ($mode == 0) $out.=urlencode($ref); if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':''); $out.=($mode?'</font>':'');
@ -203,7 +212,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag
} }
elseif ($type == 'contractline') 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 == 1) $out.='contractline_ref';
if ($mode == 0) $out.=urlencode($ref); if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':''); $out.=($mode?'</font>':'');
@ -221,7 +230,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag
} }
elseif ($type == 'member' || $type == 'membersubscription') 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 == 1) $out.='member_ref';
if ($mode == 0) $out.=urlencode($ref); if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':''); $out.=($mode?'</font>':'');
@ -239,7 +248,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag
} }
if ($type == 'donation') 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 == 1) $out.='donation_ref';
if ($mode == 0) $out.=urlencode($ref); if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':''); $out.=($mode?'</font>':'');

View File

@ -112,7 +112,7 @@ class pdf_standard extends ModeleExpenseReport
/** /**
* Issuer * Issuer
* @var Company object that emits * @var Societe
*/ */
public $emetteur; public $emetteur;
@ -1053,18 +1053,18 @@ class pdf_standard extends ModeleExpenseReport
$pdf->SetXY($tab3_posx+17, $tab3_top+$y); $pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0); $pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y); $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; $y+=$tab3_height-2;
$pdf->SetXY($tab3_posx+17, $tab3_top+$y); $pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0); $pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y); $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; $y+=$tab3_height-2;
$remaintopay = $object->total_ttc - $totalpaid; $remaintopay = $object->total_ttc - $totalpaid;
$pdf->SetXY($tab3_posx+17, $tab3_top+$y); $pdf->SetXY($tab3_posx+17, $tab3_top+$y);
$pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0); $pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
$pdf->SetXY($tab3_posx+35, $tab3_top+$y); $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 else

View File

@ -29,21 +29,22 @@ print '<!-- BEGIN PHP TEMPLATE ONLINEPAYMENTLINKS -->';
// Url list // Url list
print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br><br>'; print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br><br>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount", $servicename).':<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)) if (! empty($conf->commande->enabled))
{ {
print '<div id="order"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':<br>'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'order')."</strong><br>\n"; print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'order')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$langs->load("orders"); $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 $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="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").'">'; print '<input type="submit" class="none button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_order_ref', 'alpha')) if (GETPOST('generate_order_ref', 'alpha'))
{ {
print '<br> -> <strong>'; print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'order', GETPOST('generate_order_ref', 'alpha')); $url=getOnlinePaymentUrl(0, 'order', GETPOST('generate_order_ref', 'alpha'));
print $url; print $url;
print "</strong><br>\n"; print "</strong><br>\n";
@ -54,18 +55,19 @@ if (! empty($conf->commande->enabled))
} }
if (! empty($conf->facture->enabled)) if (! empty($conf->facture->enabled))
{ {
print '<div id="invoice"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':<br>'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'invoice')."</strong><br>\n"; print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'invoice')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$langs->load("bills"); $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 $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="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").'">'; print '<input type="submit" class="none button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_invoice_ref', 'alpha')) if (GETPOST('generate_invoice_ref', 'alpha'))
{ {
print '<br> -> <strong>'; print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'invoice', GETPOST('generate_invoice_ref', 'alpha')); $url=getOnlinePaymentUrl(0, 'invoice', GETPOST('generate_invoice_ref', 'alpha'));
print $url; print $url;
print "</strong><br>\n"; print "</strong><br>\n";
@ -76,18 +78,19 @@ if (! empty($conf->facture->enabled))
} }
if (! empty($conf->contrat->enabled)) if (! empty($conf->contrat->enabled))
{ {
print '<div id="contractline"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':<br>'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'contractline')."</strong><br>\n"; print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'contractline')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$langs->load("contracts"); $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 $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="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").'">'; print '<input type="submit" class="none button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_contract_ref')) if (GETPOST('generate_contract_ref'))
{ {
print '<br> -> <strong>'; print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'contractline', GETPOST('generate_contract_ref', 'alpha')); $url=getOnlinePaymentUrl(0, 'contractline', GETPOST('generate_contract_ref', 'alpha'));
print $url; print $url;
print "</strong><br>\n"; print "</strong><br>\n";
@ -98,18 +101,19 @@ if (! empty($conf->contrat->enabled))
} }
if (! empty($conf->adherent->enabled)) if (! empty($conf->adherent->enabled))
{ {
print '<div id="membersubscription"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':<br>'; print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription", $servicename).':<br>';
print '<strong>'.getOnlinePaymentUrl(1, 'membersubscription')."</strong><br>\n"; print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'membersubscription')."</strong><br>\n";
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$langs->load("members"); $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 $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="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").'">'; print '<input type="submit" class="none reposition button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_member_ref')) if (GETPOST('generate_member_ref'))
{ {
print '<br> -> <strong>'; print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'membersubscription', GETPOST('generate_member_ref', 'alpha')); $url=getOnlinePaymentUrl(0, 'membersubscription', GETPOST('generate_member_ref', 'alpha'));
print $url; print $url;
print "</strong><br>\n"; print "</strong><br>\n";
@ -120,18 +124,19 @@ if (! empty($conf->adherent->enabled))
} }
if (! empty($conf->don->enabled)) if (! empty($conf->don->enabled))
{ {
print '<div id="donation"></div>';
print img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnDonation", $servicename).':<br>'; 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)) if (! empty($conf->global->PAYMENT_SECURITY_TOKEN) && ! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{ {
$langs->load("members"); $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 $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="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").'">'; print '<input type="submit" class="none reposition button" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_donation_ref')) if (GETPOST('generate_donation_ref'))
{ {
print '<br> -> <strong>'; print '<br> -> <strong class="wordbreak">';
$url=getOnlinePaymentUrl(0, 'donation', GETPOST('generate_donation_ref', 'alpha')); $url=getOnlinePaymentUrl(0, 'donation', GETPOST('generate_donation_ref', 'alpha'));
print $url; print $url;
print "</strong><br>\n"; print "</strong><br>\n";

View File

@ -63,3 +63,5 @@ CreateCardOnStripe=Create card on Stripe
ShowInStripe=Show in Stripe ShowInStripe=Show in Stripe
StripeUserAccountForActions=User account to use for email notification of some Stripe events (Stripe payouts) 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)

View File

@ -263,7 +263,7 @@ elseif (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramc
* Actions * Actions
*/ */
// Action dopayment is called after choosing the payment mode // Action dopayment is called after clicking/choosing the payment mode
if ($action == 'dopayment') if ($action == 'dopayment')
{ {
if ($paymentmethod == 'paypal') if ($paymentmethod == 'paypal')
@ -395,7 +395,7 @@ if ($action == 'dopayment')
} }
// Called when choosing Stripe mode, after the 'dopayment' // Called when choosing Stripe mode, after clicking the 'dopayment'
if ($action == 'charge' && ! empty($conf->stripe->enabled)) if ($action == 'charge' && ! empty($conf->stripe->enabled))
{ {
$amountstripe = $amount; $amountstripe = $amount;
@ -509,7 +509,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
if (empty($vatcleaned)) $taxinfo=null; if (empty($vatcleaned)) $taxinfo=null;
dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe'); dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe');
$customer = \Stripe\Customer::create(array( $customer = \Stripe\Customer::create(array(
'email' => $email, 'email' => $email,
'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'), 'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'),
'metadata' => $metadata, 'metadata' => $metadata,
@ -525,7 +525,7 @@ $customer = \Stripe\Customer::create(array(
// The customer was just created with a source, so we can make a charge // 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. // with no card defined, the source just used for customer creation will be used.
dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
$charge = \Stripe\Charge::create(array( $charge = \Stripe\Charge::create(array(
'customer' => $customer->id, 'customer' => $customer->id,
'amount' => price2num($amountstripe, 'MU'), 'amount' => price2num($amountstripe, 'MU'),
'currency' => $currency, 'currency' => $currency,
@ -1658,7 +1658,7 @@ print '<br>';
if (preg_match('/^dopayment/', $action)) if (preg_match('/^dopayment/', $action))
{ {
// Strip // Stripe
if (GETPOST('dopayment_stripe', 'alpha')) if (GETPOST('dopayment_stripe', 'alpha'))
{ {
// Simple checkout // Simple checkout
@ -1727,26 +1727,28 @@ if (preg_match('/^dopayment/', $action))
<tbody><tr><td class="textpublicpayment"> <tbody><tr><td class="textpublicpayment">
<div class="form-row left"> <div class="form-row left">
<label for="card-element">
'.$langs->trans("CreditOrDebitCard").' <label for="card-element">'.$langs->trans("CreditOrDebitCard").'</label>
</label>
<div id="card-element"> <div id="card-element">
<!-- a Stripe Element will be inserted here. --> <!-- a Stripe Element will be inserted here. -->
</div> </div>
<!-- Used to display form errors --> <!-- Used to display form errors -->
<div id="card-errors" role="alert"></div> <div id="card-errors" role="alert"></div>
</div> </div>
<br> <br>
<button class="butAction" id="buttontopay">'.$langs->trans("ValidatePayment").'</button> <button class="butAction" id="buttontopay">'.$langs->trans("ValidatePayment").'</button>
<img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif'.'"> <img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif'.'">
</td></tr></tbody></table> </td></tr></tbody></table>
</form> </form>'."\n";
<script src="https://js.stripe.com/v3/"></script> print '<script src="https://js.stripe.com/v3/"></script>'."\n";
<script type="text/javascript" language="javascript">';
// 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. // Create a Stripe client.

View File

@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
if (empty($conf->stripe->enabled)) accessforbidden('', 0, 0, 1); if (empty($conf->stripe->enabled)) accessforbidden('', 0, 0, 1);
// You can find your endpoint's secret in your webhook settings // You can find your endpoint's secret in your webhook settings
if (isset($_GET['connect'])) if (isset($_GET['connect']))
{ {
@ -68,6 +69,18 @@ else {
} }
} }
if (empty($endpoint_secret))
{
print 'Error: Setup of module Stripe not complete for mode '.$service.'. The WEBHOOK_KEY is not defined.';
http_response_code(400); // PHP 5.4 or greater
exit();
}
/*
* Actions
*/
$payload = @file_get_contents("php://input"); $payload = @file_get_contents("php://input");
$sig_header = $_SERVER["HTTP_STRIPE_SIGNATURE"]; $sig_header = $_SERVER["HTTP_STRIPE_SIGNATURE"];
$event = null; $event = null;
@ -89,8 +102,6 @@ catch(\UnexpectedValueException $e) {
// Do something with $event // Do something with $event
http_response_code(200); // PHP 5.4 or greater
$langs->load("main"); $langs->load("main");
// TODO Do we really need a user in setup just to have an name to fill an email topic when it is a technical system notification email // TODO Do we really need a user in setup just to have an name to fill an email topic when it is a technical system notification email
@ -98,7 +109,8 @@ $user = new User($db);
$user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS); $user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS);
$user->getrights(); $user->getrights();
if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc)) { if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc))
{
$sql = "SELECT entity"; $sql = "SELECT entity";
$sql.= " FROM ".MAIN_DB_PREFIX."oauth_token"; $sql.= " FROM ".MAIN_DB_PREFIX."oauth_token";
$sql.= " WHERE service = '".$db->escape($service)."' and tokenstring = '%".$db->escape($event->account)."%'"; $sql.= " WHERE service = '".$db->escape($service)."' and tokenstring = '%".$db->escape($event->account)."%'";
@ -126,6 +138,15 @@ if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabl
// list of action // list of action
$stripe=new Stripe($db); $stripe=new Stripe($db);
// Subject
$societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
dol_syslog("Stripe IPN was calle with event->type = ".$event->type);
if ($event->type == 'payout.created') { if ($event->type == 'payout.created') {
$error=0; $error=0;
@ -133,7 +154,8 @@ if ($event->type == 'payout.created') {
if ($result > 0) if ($result > 0)
{ {
$subject = '[NOTIFICATION] Stripe payout scheduled';
$subject = $societeName.' - [NOTIFICATION] Stripe payout scheduled';
if (!empty($user->email)) { if (!empty($user->email)) {
$sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">"; $sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
} else { } else {
@ -163,11 +185,13 @@ if ($event->type == 'payout.created') {
$ret = $mailfile->sendfile(); $ret = $mailfile->sendfile();
http_response_code(200); // PHP 5.4 or greater
return 1; return 1;
} }
else else
{ {
$error++; $error++;
http_response_code(500); // PHP 5.4 or greater
return -1; return -1;
} }
} }
@ -212,7 +236,7 @@ elseif ($event->type == 'payout.paid') {
if (! ($result > 0)) $error++; if (! ($result > 0)) $error++;
} }
$subject = '[NOTIFICATION] Stripe payout done'; $subject = $societeName.' - [NOTIFICATION] Stripe payout done';
if (!empty($user->email)) { if (!empty($user->email)) {
$sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">"; $sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
} else { } else {
@ -226,7 +250,7 @@ elseif ($event->type == 'payout.paid') {
$message = "A bank transfer of ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." has been done to your account the ".dol_print_date($event->data->object->arrival_date, 'dayhour'); $message = "A bank transfer of ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." has been done to your account the ".dol_print_date($event->data->object->arrival_date, 'dayhour');
$mailfile = new CMailFile( $mailfile = new CMailFile(
$subject, $subject,
$sendto, $sendto,
$replyto, $replyto,
@ -242,18 +266,16 @@ $mailfile = new CMailFile(
$ret = $mailfile->sendfile(); $ret = $mailfile->sendfile();
http_response_code(200); // PHP 5.4 or greater
return 1; return 1;
} }
else else
{ {
$error++; $error++;
http_response_code(500); // PHP 5.4 or greater
return -1; return -1;
} }
} }
elseif ($event->type == 'charge.succeeded') {
//TODO: create fees
}
elseif ($event->type == 'customer.source.created') { elseif ($event->type == 'customer.source.created') {
//TODO: save customer's source //TODO: save customer's source
@ -266,130 +288,34 @@ elseif ($event->type == 'customer.source.delete') {
//TODO: delete customer's source //TODO: delete customer's source
} }
elseif ($event->type == 'charge.failed') {
$subject = 'Your payment has been received: '.$event->data->object->id.'';
$headers = 'From: "'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
}
elseif (($event->type == 'source.chargeable') && ($event->data->object->type == 'three_d_secure') && ($event->data->object->three_d_secure->authenticated==true)) {
$fulltag=$event->data->object->metadata->FULLTAG;
// Save into $tmptag all metadata
$tmptag=dolExplodeIntoArray($fulltag, '.', '=');
if (! empty($tmptag['ORD'])) {
$order=new Commande($db);
$order->fetch('', $tmptag['ORD']);
$origin='order';
$item=$order->id;
} elseif (! empty($tmptag['INV'])) {
$invoice = new Facture($db);
$invoice->fetch('', $tmptag['INV']);
$origin='invoice';
$item=$invoice->id;
}
$stripe=new Stripe($db);
$stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
$stripecu = $stripe->getStripeCustomerAccount($tmptag['CUS'], $servicestatus); // Get thirdparty cu_...
$charge=$stripe->createPaymentStripe($event->data->object->amount/100, $event->data->object->currency, $origin, $item, $event->data->object->id, $stripecu, $stripeacc, $servicestatus);
if (isset($charge->id) && $charge->statut=='error') {
$msg=$charge->message;
$code=$charge->code;
$error++;
}
elseif (isset($charge->id) && $charge->statut=='success' && (! empty($tmptag['ORD']))) {
//$order=new Commande($db);
//$order->fetch('',$tmptag['ORD']);
$invoice = new Facture($db);
$idinv=$invoice->createFromOrder($order, $user);
if ($idinv > 0)
{
$result=$invoice->validate($user);
if ($result > 0) {
$invoice->fetch($idinv);
$paiement = $invoice->getSommePaiement();
$creditnotes=$invoice->getSumCreditNotesUsed();
$deposits=$invoice->getSumDepositsUsed();
$ref=$invoice->ref;
$ifverif=$invoice->socid;
$currency=$invoice->multicurrency_code;
$total=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
} else {
$msg=$invoice->error;
$error++;
}
} else {
$msg=$invoice->error;
$error++;
}
}
if (!$error) {
$datepaye = dol_now();
$paymentType ="CB";
$amounts=array();
$amounts[$invoice->id] = $total;
$multicurrency_amounts=array();
//$multicurrency_amounts[$item] = $total;
$paiement = new Paiement($db);
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array with all payments dispatching
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
$paiement->paiementid = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
$paiement->num_paiement = $charge->message;
$paiement->note = '';
}
if (! $error) {
$paiement_id=$paiement->create($user, 0);
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($invoice->lines)) {
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$model=$invoice->modelpdf;
$ret = $invoice->fetch($invoice->id); // Reload to get new records
$invoice->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
if ($paiement_id < 0) {
$msg=$paiement->errors;
$error++;
} else {
if ($event->data->object->metadata->source=='order') {
$order->classifyBilled($user);
}
}
}
if (! $error) {
$label='(CustomerInvoicePayment)';
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
$paiement->addPaymentToBank($user, 'payment', $label, $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, '', '');
if ($result < 0)
{
$msg=$paiement->errors;
$error++;
}
$invoice->set_paid($user);
}
$body = "";
$subject = 'Facture '.$invoice->ref;
$headers = 'From: "'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
}
elseif ($event->type == 'customer.deleted') { elseif ($event->type == 'customer.deleted') {
$db->begin(); $db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE key_account = '".$event->data->object->id."' and site='stripe' "; $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE key_account = '".$db->escape($event->data->object->id)."' and site='stripe'";
dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
$db->query($sql); $db->query($sql);
$db->commit(); $db->commit();
} }
elseif ($event->type == 'charge.succeeded') {
// TODO: create fees
// TODO: Redirect to paymentok.php
}
elseif ($event->type == 'charge.failed') {
// TODO: Redirect to paymentko.php
}
elseif (($event->type == 'source.chargeable') && ($event->data->object->type == 'three_d_secure') && ($event->data->object->three_d_secure->authenticated==true)) {
$fulltag=$event->data->object->metadata->FULLTAG;
dol_syslog("fulltag=".$fulltag);
// Save into $tmptag all metadata
$tmptag=dolExplodeIntoArray($fulltag, '.', '=');
// TODO: Set $_POST var from $event->data and call newpayment.php with $action = 'charge'
$stripe=new Stripe($db);
/*
$stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
$stripecu = $stripe->getStripeCustomerAccount($tmptag['CUS'], $servicestatus); // Get thirdparty cu_...
$charge=$stripe->createPaymentStripe($event->data->object->amount/100, $event->data->object->currency, $origin, $item, $event->data->object->id, $stripecu, $stripeacc, $servicestatus);
*/
}
http_response_code(200); // PHP 5.4 or greater

View File

@ -42,6 +42,10 @@ if (! $user->admin) accessforbidden();
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
/*
* Actions
*/
if ($action == 'setvalue' && $user->admin) if ($action == 'setvalue' && $user->admin)
{ {
$db->begin(); $db->begin();
@ -190,14 +194,14 @@ if (empty($conf->stripeconnect->enabled))
print '</td><td></td></tr>'; print '</td><td></td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print '<span>'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>'; print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
print '<input class="minwidth500" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.$conf->global->STRIPE_TEST_WEBHOOK_ID.'">'; print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.$conf->global->STRIPE_TEST_WEBHOOK_ID.'">';
print ' &nbsp; '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>'; print ' &nbsp; '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>';
print '<input class="minwidth500" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.$conf->global->STRIPE_TEST_WEBHOOK_KEY.'">'; 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'; print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").'<br>'; $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="quatrevingtpercent" value="'.$url.'">'; $out.= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'">';
$out.= ajax_autoselect("onlinetestwebhookurl", 0); $out.= ajax_autoselect("onlinetestwebhookurl", 0);
print '<br />'.$out; print '<br />'.$out;
print '</td><td>'; print '</td><td>';
@ -252,14 +256,14 @@ if (empty($conf->stripeconnect->enabled))
print '</td><td></td></tr>'; print '</td><td></td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print '<span>'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>'; print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_ID.'">';
print '<input class="minwidth500" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_ID.'">';
print ' &nbsp; '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>'; print ' &nbsp; '.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx<br>';
print '<input class="minwidth500" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_KEY.'">'; print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
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'; print ' &nbsp; '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").'<br>'; $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="quatrevingtpercent" value="'.$url.'">'; $out.= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'">';
$out.= ajax_autoselect("onlinelivewebhookurl", 0); $out.= ajax_autoselect("onlinelivewebhookurl", 0);
print '<br />'.$out; print '<br />'.$out;
print '</td><td>'; print '</td><td>';

View File

@ -55,4 +55,4 @@ else
\Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']); \Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']);
\Stripe\Stripe::setAppInfo("Dolibarr Stripe", DOL_VERSION, "https://www.dolibarr.org"); // add dolibarr version \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("2019-03-14"); // force version API

View File

@ -2234,7 +2234,7 @@ div.tabBar table.tableforservicepart2:last-child {
padding-top: 0 !important; padding-top: 0 !important;
} }
/* Payment Screen : Pointer cursor in the autofill image */ /* Payment Screen : Pointer cursor in the autofill image */
table.noborder .AutoFillAmout { .AutoFillAmount {
cursor:pointer; cursor:pointer;
} }

View File

@ -1542,6 +1542,10 @@ img.photorefnoborder {
margin: 0; margin: 0;
padding-bottom: 0 !important; padding-bottom: 0 !important;
} }
/* Payment Screen : Pointer cursor in the autofill image */
.AutoFillAmount {
cursor:pointer;
}
/* ============================================================================== */ /* ============================================================================== */