'.
print ''."\n";
print "\n";
+
if ($action != 'dopayment')
{
if ($found && ! $error) // We are in a management option and no error
@@ -1748,13 +1778,13 @@ if ($action != 'dopayment')
if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled))
{
// If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of paybox
- print '
';
}
if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled))
{
// If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of stripe
- print '
';
}
if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled))
@@ -1763,11 +1793,11 @@ if ($action != 'dopayment')
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
{
- print '
';
}
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
- print '
';
}
}
}
@@ -1799,17 +1829,6 @@ if (preg_match('/^dopayment/', $action))
// Stripe
if (GETPOST('dopayment_stripe', 'alpha'))
{
- // Simple checkout
- /*
- print '';
- */
-
// Personalized checkout
print '';
- print '
+ print '
'."\n";
+ print ''."\n";
print ''."\n";
@@ -1931,7 +1968,6 @@ if (preg_match('/^dopayment/', $action))
};
var cardElement = elements.create('card', {style: style});
- var cardholderName = document.getElementById('cardholder-name');
// Add an instance of the card Element into the `card-element`
cardElement.mount('#card-element');
@@ -1940,44 +1976,70 @@ if (preg_match('/^dopayment/', $action))
cardElement.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
- console.log("Show event error");
+ console.log("Show event error (like 'Incorrect card number', ...)");
displayError.textContent = event.error.message;
} else {
- console.log("No error");
+ console.log("Reset error message");
displayError.textContent = '';
}
});
// Handle form submission
+ var cardholderName = document.getElementById('cardholder-name');
var cardButton = document.getElementById('buttontopay');
var clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', function(event) {
- stripe.handleCardPayment(
- clientSecret, cardElement, {
- source_data: {
- owner: {
- name: cardholderName.value,
+ console.log("We click on buttontopay");
+ event.preventDefault();
+
+ if (cardholderName.value == '')
+ {
+ console.log("Field Card holder is empty");
+ var displayError = document.getElementById('card-errors');
+ displayError.textContent = 'trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardOwner"))); ?>';
+ }
+ else
+ {
+ stripe.handleCardPayment(
+ clientSecret, cardElement, {
+ payment_method_data: {
+ billing_details: {
+ name: cardholderName.value
+ , email: '',
+ thirdparty)) { ?>, phone: thirdparty->phone; ?>',
+ thirdparty)) {
+ print ', address: {'."\n";
+ print ' city: '.$object->thirdparty->town.',';
+ print ' country: '.$object->thirdparty->country_code.',';
+ print ' line1: '.$object->thirdparty->address.',';
+ print ' postal_code: '.$object->thirdparty->zip;
+ print '}'."\n";
+ } ?>
+ } /* TODO Add all other known data like emails, ... to be SCA compliant */
+ },
+ save_payment_method: false
}
- }
+ ).then(function(result) {
+ console.log(result);
+ if (result.error) {
+ console.log("Error on result of handleCardPayment");
+ jQuery('#buttontopay').show();
+ jQuery('#hourglasstopay').hide();
+ // Inform the user if there was an error
+ var errorElement = document.getElementById('card-errors');
+ errorElement.textContent = result.error.message;
+ } else {
+ // The payment has succeeded. Display a success message.
+ console.log("No error on result of handleCardPayment, so we submit the form");
+ // Submit the form
+ jQuery('#buttontopay').hide();
+ jQuery('#hourglasstopay').show();
+ // Send form (action=charge that will do nothing)
+ jQuery('#payment-form').submit();
+ }
+ });
}
- ).then(function(result) {
- jQuery('#buttontopay').hide();
- jQuery('#hourglasstopay').show();
- if (result.error) {
- console.log("Error on result of handleCardPayment");
- jQuery('#buttontopay').show();
- jQuery('#hourglasstopay').hide();
- // Inform the user if there was an error
- var errorElement = document.getElementById('card-errors');
- errorElement.textContent = result.error.message;
- } else {
- console.log("No error on result of handleCardPayment, so we submit the form");
- // Submit the form
- jQuery('#buttontopay').hide();
- jQuery('#hourglasstopay').show();
- }
- });
});
diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php
index 62d709fc674..52413921f90 100644
--- a/htdocs/public/payment/paymentok.php
+++ b/htdocs/public/payment/paymentok.php
@@ -280,7 +280,7 @@ $fulltag = $FULLTAG;
$tmptag=dolExplodeIntoArray($fulltag, '.', '=');
-dol_syslog("ispaymentok=".$ispaymentok, LOG_DEBUG, 0, '_payment');
+dol_syslog("ispaymentok=".$ispaymentok." tmptag=".var_export($tmptag, true), LOG_DEBUG, 0, '_payment');
// Make complementary actions
@@ -296,7 +296,7 @@ if ($ispaymentok)
$user->rights->facture->creer = 1;
$user->rights->adherent->cotisation->creer = 1;
- if (in_array('MEM', array_keys($tmptag)))
+ if (array_key_exists('MEM', $tmptag) && $tmptag['MEM'] > 0)
{
// Validate member
// Create subscription
@@ -583,7 +583,7 @@ if ($ispaymentok)
$ispostactionok = -1;
}
}
- elseif (in_array('INV', array_keys($tmptag)))
+ elseif (array_key_exists('INV', $tmptag) && $tmptag['INV'] > 0)
{
// Record payment
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -769,14 +769,14 @@ if ($ispaymentok)
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived");
$content="";
- if (in_array('MEM', array_keys($tmptag)))
+ if (array_key_exists('MEM', $tmptag))
{
$url=$urlwithroot."/adherents/subscription.php?rowid=".$tmptag['MEM'];
$content.='
'.$companylangs->trans("PaymentSubscription")."\n";
$content.=$companylangs->trans("MemberId").':
'.$tmptag['MEM']."\n";
$content.=$companylangs->trans("Link").':
'.$url.''."
\n";
}
- elseif (in_array('INV', array_keys($tmptag)))
+ elseif (array_key_exists('INV', $tmptag))
{
$url=$urlwithroot."/compta/facture/card.php?id=".$tmptag['INV'];
$content.='
'.$companylangs->trans("Payment")."\n";
diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php
index 1f2f39719a8..ee1c1a67f0a 100644
--- a/htdocs/stripe/class/stripe.class.php
+++ b/htdocs/stripe/class/stripe.class.php
@@ -243,6 +243,7 @@ class Stripe extends CommonObject
* @param double $amount Amount
* @param string $currency_code Currency code
* @param string $tag Tag
+ * @param string $description Description
* @param Societe $object Object to pay with Stripe
* @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
* @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
@@ -252,10 +253,14 @@ class Stripe extends CommonObject
* @param boolean $confirmnow false=default, true=try to confirm immediatly after create (if conditions are ok)
* @return \Stripe\PaymentIntent|null Stripe PaymentIntent or null if not found
*/
- public function getPaymentIntent($amount, $currency_code, $tag, $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false)
+ public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false)
{
global $conf, $user, $mysoc;
+ dol_syslog("getPaymentIntent");
+
+ $error = 0;
+
if (empty($status)) $service = 'StripeTest';
else $service = 'StripeLive';
@@ -305,6 +310,7 @@ class Stripe extends CommonObject
}
catch(Exception $e)
{
+ $error++;
$this->error = $e->getMessage();
}
}
@@ -314,9 +320,6 @@ class Stripe extends CommonObject
if (empty($paymentintent))
{
$ipaddress=getUserRemoteIP();
- // Not enough space for a ref so we store id. Also with multicompany we can have same ref for 2 different
- // object and we need a unique (this is used later as idempotency_key)
- $description=$tag;
$metadata = array('dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>$ipaddress);
if (is_object($object))
{
@@ -330,12 +333,14 @@ class Stripe extends CommonObject
"amount" => $stripeamount,
"currency" => $currency_code,
"payment_method_types" => ["card"],
- "statement_descriptor" => dol_trunc($description, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description)
+ "description" => $description,
+ "statement_descriptor" => dol_trunc($tag, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description)
"metadata" => $metadata
);
if (! is_null($customer)) $dataforintent["customer"]=$customer;
// save_payment_method = true,
// payment_method =
+ //var_dump($dataforintent);
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{
@@ -353,9 +358,12 @@ class Stripe extends CommonObject
if (empty($key)) { // If the Stripe connect account not set, we use common API usage
$paymentintent = \Stripe\PaymentIntent::create($dataforintent, array("idempotency_key" => "$description"));
+ //$paymentintent = \Stripe\PaymentIntent::create($dataforintent, array());
} else {
$paymentintent = \Stripe\PaymentIntent::create($dataforintent, array("idempotency_key" => "$description", "stripe_account" => $key));
+ //$paymentintent = \Stripe\PaymentIntent::create($dataforintent, array("stripe_account" => $key));
}
+ //var_dump($paymentintent);
// Store the payment intent
if (is_object($object))
@@ -366,6 +374,7 @@ class Stripe extends CommonObject
$resql = $this->db->query($sql);
if (! $resql)
{
+ $error++;
$this->error = $this->db->lasterror();
dol_syslog(get_class($this) . "::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database.");
}
@@ -377,10 +386,18 @@ class Stripe extends CommonObject
}
catch(Exception $e)
{
+ /*var_dump($dataforintent);
+ var_dump($description);
+ var_dump($key);
+ var_dump($paymentintent);
+ var_dump($e->getMessage());*/
+ $error++;
$this->error = $e->getMessage();
}
}
+ dol_syslog("getPaymentIntent return error=".$error);
+
return $paymentintent;
}
diff --git a/htdocs/stripe/lib/stripe.lib.php b/htdocs/stripe/lib/stripe.lib.php
index d806d6a39b3..100ce840e24 100644
--- a/htdocs/stripe/lib/stripe.lib.php
+++ b/htdocs/stripe/lib/stripe.lib.php
@@ -87,12 +87,12 @@ function showStripePaymentUrl($type, $ref)
* @param string $freetag Free tag
* @return string Url string
*/
-function getStripePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag')
+function getStripePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag')
{
global $conf;
$ref=str_replace(' ', '', $ref);
-
+
if ($type == 'free')
{
$out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode?'
':'').$amount.($mode?'':'').'&tag='.($mode?'
':'').$freetag.($mode?'':'');
diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php
index b8ffa08fbaf..7302191fc84 100644
--- a/htdocs/theme/eldy/global.inc.php
+++ b/htdocs/theme/eldy/global.inc.php
@@ -132,19 +132,27 @@ input.smallpadd { /* Used for timesheet input */
input.buttongen {
vertical-align: middle;
}
-input.buttonpayment {
+input.buttonpayment, button.buttonpayment, div.buttonpayment {
min-width: 320px;
margin-bottom: 15px;
background-image: none;
line-height: 24px;
padding: 8px;
background: none;
- padding-left: 38px;
- text-align: ;
- border: 1px solid #ddd;
- background-color: #eee;
+ text-align: center;
+ border: 0;
+ background-color: #9999bb;
white-space: normal;
- box-shadow: 1px 1px 8px #bbb;
+ box-shadow: 1px 1px 4px #bbb;
+ color: #fff;
+ border-radius: 4px;
+}
+div.buttonpayment input {
+ background-color: unset;
+ color: #fff;
+ border-bottom: unset;
+ font-weight: bold;
+ text-transform: uppercase;
}
input.buttonpaymentcb {
background-image: url();
@@ -3569,6 +3577,7 @@ div#card-errors {
color: #fa755a;
text-align: center;
padding-top: 3px;
+ max-width: 320px;
}
diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php
index 755736eb79f..2906da3729c 100644
--- a/htdocs/theme/md/style.css.php
+++ b/htdocs/theme/md/style.css.php
@@ -352,18 +352,25 @@ input.smallpadd { /* Used for timesheet input */
input.buttongen {
vertical-align: middle;
}
-input.buttonpayment {
+input.buttonpayment, button.buttonpayment, div.buttonpayment {
min-width: 320px;
margin-bottom: 15px;
background-image: none;
line-height: 24px;
padding: 8px;
background: none;
- padding-left: 30px;
- text-align: ;
+ text-align: center;
border: 2px solid #ccc;
background-color: #eee;
white-space: normal;
+ color: #888 !important;
+}
+div.buttonpayment input {
+ background-color: unset;
+ border-bottom: unset;
+ font-weight: bold;
+ text-transform: uppercase;
+ color: #333;
}
input.buttonpaymentcb {
background-image: url();
@@ -3660,6 +3667,7 @@ div#card-errors {
color: #fa755a;
text-align: center;
padding-top: 3px;
+ max-width: 320px;
}