Ehance getPaymentIntent to use it for offline payment

This commit is contained in:
Laurent Destailleur 2019-09-23 11:35:11 +02:00
parent 3faca1dbd1
commit bf9f25fd74

View File

@ -305,16 +305,18 @@ class Stripe extends CommonObject
* @param string $currency_code Currency code
* @param string $tag Tag
* @param string $description Description
* @param Societe $object Object to pay with Stripe
* @param mixed $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
* @param int $status Status (0=test, 1=live)
* @param int $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt
* @param int $mode automatic=automatic confirmation/payment when conditions are ok, manual=need to call confirm() on intent
* @param boolean $confirmnow false=default, true=try to confirm immediatly after create (if conditions are ok)
* @param string $payment_method 'pm_....' (if known)
* @param string $off_session If we use an already known payment method to pay off line.
* @return \Stripe\PaymentIntent|null Stripe PaymentIntent or null if not found and failed to create
*/
public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $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, $payment_method = null, $off_session = 0)
{
global $conf;
@ -335,7 +337,7 @@ class Stripe extends CommonObject
} elseif ($fee < $conf->global->STRIPE_APPLICATION_FEE_MINIMAL) {
$fee = $conf->global->STRIPE_APPLICATION_FEE_MINIMAL;
}
if (! in_array($currency, $arrayzerounitcurrency)) $stripefee = round($fee * 100);
if (! in_array($currency_code, $arrayzerounitcurrency)) $stripefee = round($fee * 100);
else $stripefee = round($fee);
$paymentintent = null;
@ -411,6 +413,12 @@ class Stripe extends CommonObject
// payment_method =
// payment_method_types = array('card')
//var_dump($dataforintent);
if ($off_session)
{
unset($dataforintent['setup_future_usage']);
$dataforintent["off_session"] = true;
}
if (! is_null($payment_method)) $dataforintent["payment_method"] = $payment_method;
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $stripefee > 0)
{
@ -491,7 +499,7 @@ class Stripe extends CommonObject
}
}
dol_syslog("getPaymentIntent return error=".$error, LOG_INFO, -1);
dol_syslog("getPaymentIntent return error=".$error." this->error=".$this->error, LOG_INFO, -1);
if (! $error)
{