Merge branch 'develop' into patch-153
This commit is contained in:
commit
8007b222d0
@ -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;
|
||||
@ -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>':'');
|
||||
@ -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>':'');
|
||||
@ -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>':'');
|
||||
@ -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>':'');
|
||||
@ -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>':'');
|
||||
|
||||
@ -112,7 +112,7 @@ class pdf_standard extends ModeleExpenseReport
|
||||
|
||||
/**
|
||||
* Issuer
|
||||
* @var Company object that emits
|
||||
* @var Societe
|
||||
*/
|
||||
public $emetteur;
|
||||
|
||||
@ -1053,18 +1053,18 @@ class pdf_standard extends ModeleExpenseReport
|
||||
$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
|
||||
|
||||
@ -29,21 +29,22 @@ print '<!-- BEGIN PHP TEMPLATE ONLINEPAYMENTLINKS -->';
|
||||
// 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";
|
||||
@ -54,18 +55,19 @@ if (! empty($conf->commande->enabled))
|
||||
}
|
||||
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";
|
||||
@ -76,18 +78,19 @@ if (! empty($conf->facture->enabled))
|
||||
}
|
||||
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";
|
||||
@ -98,18 +101,19 @@ if (! empty($conf->contrat->enabled))
|
||||
}
|
||||
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";
|
||||
@ -120,18 +124,19 @@ if (! empty($conf->adherent->enabled))
|
||||
}
|
||||
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";
|
||||
|
||||
@ -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)
|
||||
@ -263,7 +263,7 @@ elseif (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramc
|
||||
* 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')
|
||||
@ -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))
|
||||
{
|
||||
$amountstripe = $amount;
|
||||
@ -509,7 +509,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
|
||||
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,
|
||||
@ -525,7 +525,7 @@ $customer = \Stripe\Customer::create(array(
|
||||
// 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,
|
||||
@ -1658,7 +1658,7 @@ print '<br>';
|
||||
if (preg_match('/^dopayment/', $action))
|
||||
{
|
||||
|
||||
// Strip
|
||||
// Stripe
|
||||
if (GETPOST('dopayment_stripe', 'alpha'))
|
||||
{
|
||||
// Simple checkout
|
||||
@ -1727,26 +1727,28 @@ if (preg_match('/^dopayment/', $action))
|
||||
<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>
|
||||
</form>'."\n";
|
||||
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
|
||||
<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.
|
||||
|
||||
@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
|
||||
|
||||
if (empty($conf->stripe->enabled)) accessforbidden('', 0, 0, 1);
|
||||
|
||||
|
||||
// You can find your endpoint's secret in your webhook settings
|
||||
if (isset($_GET['connect']))
|
||||
{
|
||||
@ -50,7 +51,7 @@ if (isset($_GET['connect']))
|
||||
{
|
||||
$endpoint_secret = $conf->global->STRIPE_LIVE_WEBHOOK_CONNECT_KEY;
|
||||
$service = 'StripeLive';
|
||||
$servicestatus = 1;
|
||||
$servicestatus = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -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");
|
||||
$sig_header = $_SERVER["HTTP_STRIPE_SIGNATURE"];
|
||||
$event = null;
|
||||
@ -89,8 +102,6 @@ catch(\UnexpectedValueException $e) {
|
||||
|
||||
// Do something with $event
|
||||
|
||||
http_response_code(200); // PHP 5.4 or greater
|
||||
|
||||
$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
|
||||
@ -98,7 +109,8 @@ $user = new User($db);
|
||||
$user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS);
|
||||
$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.= " FROM ".MAIN_DB_PREFIX."oauth_token";
|
||||
$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
|
||||
$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') {
|
||||
$error=0;
|
||||
|
||||
@ -133,7 +154,8 @@ if ($event->type == 'payout.created') {
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$subject = '[NOTIFICATION] Stripe payout scheduled';
|
||||
|
||||
$subject = $societeName.' - [NOTIFICATION] Stripe payout scheduled';
|
||||
if (!empty($user->email)) {
|
||||
$sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
|
||||
} else {
|
||||
@ -163,11 +185,13 @@ if ($event->type == 'payout.created') {
|
||||
|
||||
$ret = $mailfile->sendfile();
|
||||
|
||||
http_response_code(200); // PHP 5.4 or greater
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
http_response_code(500); // PHP 5.4 or greater
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -212,7 +236,7 @@ elseif ($event->type == 'payout.paid') {
|
||||
if (! ($result > 0)) $error++;
|
||||
}
|
||||
|
||||
$subject = '[NOTIFICATION] Stripe payout done';
|
||||
$subject = $societeName.' - [NOTIFICATION] Stripe payout done';
|
||||
if (!empty($user->email)) {
|
||||
$sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
|
||||
} 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');
|
||||
|
||||
$mailfile = new CMailFile(
|
||||
$mailfile = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
$replyto,
|
||||
@ -242,18 +266,16 @@ $mailfile = new CMailFile(
|
||||
|
||||
$ret = $mailfile->sendfile();
|
||||
|
||||
http_response_code(200); // PHP 5.4 or greater
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
http_response_code(500); // PHP 5.4 or greater
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
elseif ($event->type == 'charge.succeeded') {
|
||||
|
||||
//TODO: create fees
|
||||
}
|
||||
elseif ($event->type == 'customer.source.created') {
|
||||
|
||||
//TODO: save customer's source
|
||||
@ -266,130 +288,34 @@ elseif ($event->type == 'customer.source.delete') {
|
||||
|
||||
//TODO: delete customer's source
|
||||
}
|
||||
elseif ($event->type == 'customer.deleted') {
|
||||
$db->begin();
|
||||
$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);
|
||||
$db->query($sql);
|
||||
$db->commit();
|
||||
}
|
||||
elseif ($event->type == 'charge.succeeded') {
|
||||
// TODO: create fees
|
||||
// TODO: Redirect to paymentok.php
|
||||
}
|
||||
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.'>';
|
||||
// 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;
|
||||
// Save into $tmptag all metadata
|
||||
dol_syslog("fulltag=".$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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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') {
|
||||
$db->begin();
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE key_account = '".$event->data->object->id."' and site='stripe' ";
|
||||
dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
|
||||
$db->query($sql);
|
||||
$db->commit();
|
||||
*/
|
||||
}
|
||||
|
||||
http_response_code(200); // PHP 5.4 or greater
|
||||
|
||||
@ -42,6 +42,10 @@ if (! $user->admin) accessforbidden();
|
||||
$action = GETPOST('action', 'alpha');
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'setvalue' && $user->admin)
|
||||
{
|
||||
$db->begin();
|
||||
@ -190,14 +194,14 @@ if (empty($conf->stripeconnect->enabled))
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<span>'.$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 '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.$conf->global->STRIPE_TEST_WEBHOOK_ID.'">';
|
||||
print ' '.$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 ' '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").'<br>';
|
||||
$url = dol_buildpath('/public/stripe/ipn.php?test', 2);
|
||||
$out.= '<input type="text" id="onlinetestwebhookurl" class="quatrevingtpercent" value="'.$url.'">';
|
||||
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForTestWebhook").' ';
|
||||
$url = dol_buildpath('/public/stripe/ipn.php?test', 3);
|
||||
$out.= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'">';
|
||||
$out.= ajax_autoselect("onlinetestwebhookurl", 0);
|
||||
print '<br />'.$out;
|
||||
print '</td><td>';
|
||||
@ -252,14 +256,14 @@ if (empty($conf->stripeconnect->enabled))
|
||||
print '</td><td></td></tr>';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<span>'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
|
||||
print '<input class="minwidth500" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_ID.'">';
|
||||
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.$conf->global->STRIPE_LIVE_WEBHOOK_ID.'">';
|
||||
print ' '.$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 ' '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx';
|
||||
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").'<br>';
|
||||
$url = dol_buildpath('/public/stripe/ipn.php', 2);
|
||||
$out.= '<input type="text" id="onlinelivewebhookurl" class="quatrevingtpercent" value="'.$url.'">';
|
||||
$out = img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForLiveWebhook").' ';
|
||||
$url = dol_buildpath('/public/stripe/ipn.php', 3);
|
||||
$out.= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'">';
|
||||
$out.= ajax_autoselect("onlinelivewebhookurl", 0);
|
||||
print '<br />'.$out;
|
||||
print '</td><td>';
|
||||
|
||||
@ -55,4 +55,4 @@ else
|
||||
|
||||
\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("2019-03-14"); // force version API
|
||||
|
||||
@ -2234,7 +2234,7 @@ div.tabBar table.tableforservicepart2:last-child {
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
/* Payment Screen : Pointer cursor in the autofill image */
|
||||
table.noborder .AutoFillAmout {
|
||||
.AutoFillAmount {
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
|
||||
@ -1542,6 +1542,10 @@ img.photorefnoborder {
|
||||
margin: 0;
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
/* Payment Screen : Pointer cursor in the autofill image */
|
||||
.AutoFillAmount {
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
|
||||
/* ============================================================================== */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user