diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 3f2c2979e00..92eb0a5e856 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -264,11 +264,12 @@ else if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$param * Actions */ +// Action dopayment is called after choosing the payment mode if ($action == 'dopayment') { if ($paymentmethod == 'paypal') { - $PAYPAL_API_PRICE=price2num(GETPOST("newamount"),'MT'); + $PAYPAL_API_PRICE=price2num(GETPOST("newamount",'alpha'),'MT'); $PAYPAL_PAYMENT_TYPE='Sale'; $origfulltag=GETPOST("fulltag",'alpha'); @@ -310,6 +311,7 @@ if ($action == 'dopayment') dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG); dol_syslog("PAYPAL_API_PRICE: $PAYPAL_API_PRICE", LOG_DEBUG); dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG); + // All those fields may be empty when making a payment for a free amount for example dol_syslog("shipToName: $shipToName", LOG_DEBUG); dol_syslog("shipToStreet: $shipToStreet", LOG_DEBUG); dol_syslog("shipToCity: $shipToCity", LOG_DEBUG); @@ -327,9 +329,10 @@ if ($action == 'dopayment') //$_SESSION["FinalPaymentAmt"]=$PAYPAL_API_PRICE; // A redirect is added if API call successfull - print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG); + $mesg = print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG); - exit; + // If we are here, it means the Paypal redirect was not done, so we show error message + $action = ''; } } @@ -366,7 +369,7 @@ if ($action == 'dopayment') if ($paymentmethod == 'stripe') { - if (GETPOST('newamount')) $amount = GETPOST('newamount'); + if (GETPOST('newamount','alpha')) $amount = price2num(GETPOST('newamount','alpha'),'MT'); else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); @@ -379,10 +382,12 @@ if ($action == 'dopayment') // Called when choosing Stripe mode, after the 'dopayment' if ($action == 'charge') { + $amountstripe = $amount; + // Correct the amount according to unit of currency // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support $arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); - if (! in_array($currency, $arrayzerounitcurrency)) $amount=$amount * 100; + if (! in_array($currency, $arrayzerounitcurrency)) $amountstripe=$amountstripe * 100; dol_syslog("POST keys : ".join(',', array_keys($_POST)), LOG_DEBUG, 0, '_stripe'); dol_syslog("POST values: ".join(',', $_POST), LOG_DEBUG, 0, '_stripe'); @@ -411,7 +416,7 @@ if ($action == 'charge') dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, - 'amount' => price2num($amount, 'MU'), + 'amount' => price2num($amountstripe, 'MU'), 'currency' => $currency, 'description' => 'Stripe payment: '.$FULLTAG, 'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name), @@ -529,7 +534,7 @@ if (! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBO { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning'); } -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); } @@ -647,7 +652,7 @@ if (! $source) if (empty($amount) || ! is_numeric($amount)) { print ''; - print ''; + print ''; } else { print ''.price($amount).''; @@ -661,7 +666,7 @@ if (! $source) // Tag print '
@@ -1537,3 +1546,4 @@ htmlPrintOnlinePaymentFooter($mysoc,$langs,1,$suffix,$object);
llxFooter('', 'public');
$db->close();
+