Debug stripe deprecated page
This commit is contained in:
parent
dfaf2ae34b
commit
71227e43fa
@ -803,7 +803,8 @@ class Stripe extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
|
* Create charge.
|
||||||
|
* This is called by page htdocs/stripe/payment.php and may be deprecated.
|
||||||
*
|
*
|
||||||
* @param int $amount Amount to pay
|
* @param int $amount Amount to pay
|
||||||
* @param string $currency EUR, GPB...
|
* @param string $currency EUR, GPB...
|
||||||
@ -854,12 +855,12 @@ class Stripe extends CommonObject
|
|||||||
|
|
||||||
$description = "";
|
$description = "";
|
||||||
$ref = "";
|
$ref = "";
|
||||||
if ($origin == order) {
|
if ($origin == 'order') {
|
||||||
$order = new Commande($this->db);
|
$order = new Commande($this->db);
|
||||||
$order->fetch($item);
|
$order->fetch($item);
|
||||||
$ref = $order->ref;
|
$ref = $order->ref;
|
||||||
$description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
|
$description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
|
||||||
} elseif ($origin == invoice) {
|
} elseif ($origin == 'invoice') {
|
||||||
$invoice = new Facture($this->db);
|
$invoice = new Facture($this->db);
|
||||||
$invoice->fetch($item);
|
$invoice->fetch($item);
|
||||||
$ref = $invoice->ref;
|
$ref = $invoice->ref;
|
||||||
@ -881,9 +882,42 @@ class Stripe extends CommonObject
|
|||||||
global $stripearrayofkeysbyenv;
|
global $stripearrayofkeysbyenv;
|
||||||
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
|
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
|
||||||
|
|
||||||
if (empty($conf->stripeconnect->enabled))
|
if (empty($conf->stripeconnect->enabled)) // With a common Stripe account
|
||||||
{
|
{
|
||||||
if (preg_match('/acct_/i', $source))
|
if (preg_match('/pm_/i', $source))
|
||||||
|
{
|
||||||
|
$stripecard = $source;
|
||||||
|
$amountstripe = $stripeamount;
|
||||||
|
$FULLTAG = 'PFBO'; // Payment From Back Office
|
||||||
|
$stripe = $return;
|
||||||
|
$amounttopay = $amount;
|
||||||
|
$servicestatus = $status;
|
||||||
|
|
||||||
|
dol_syslog("* createPaymentStripe get stripeacc", LOG_DEBUG);
|
||||||
|
$stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account if it exists (no network access here)
|
||||||
|
|
||||||
|
dol_syslog("* createPaymentStripe Create payment on card ".$stripecard->id.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG);
|
||||||
|
|
||||||
|
// Create payment intent and charge payment (confirmnow = true)
|
||||||
|
$paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard->id, 1);
|
||||||
|
|
||||||
|
$charge = new stdClass();
|
||||||
|
if ($paymentintent->status == 'succeeded')
|
||||||
|
{
|
||||||
|
$charge->status = 'ok';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$charge->status = 'failed';
|
||||||
|
$charge->failure_code = $stripe->code;
|
||||||
|
$charge->failure_message = $stripe->error;
|
||||||
|
$charge->failure_declinecode = $stripe->declinecode;
|
||||||
|
$stripefailurecode = $stripe->code;
|
||||||
|
$stripefailuremessage = $stripe->error;
|
||||||
|
$stripefailuredeclinecode = $stripe->declinecode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (preg_match('/acct_/i', $source))
|
||||||
{
|
{
|
||||||
$charge = \Stripe\Charge::create(array(
|
$charge = \Stripe\Charge::create(array(
|
||||||
"amount" => "$stripeamount",
|
"amount" => "$stripeamount",
|
||||||
@ -914,12 +948,14 @@ class Stripe extends CommonObject
|
|||||||
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$description"));
|
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$description"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fee = $amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE;
|
// With Stripe Connect
|
||||||
if ($fee >= $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL && $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL > $conf->global->STRIPE_APPLICATION_FEE_MINIMAL) {
|
$fee = $amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE;
|
||||||
$fee = $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL;
|
if ($fee >= $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL && $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL > $conf->global->STRIPE_APPLICATION_FEE_MINIMAL) {
|
||||||
} elseif ($fee < $conf->global->STRIPE_APPLICATION_FEE_MINIMAL) {
|
$fee = $conf->global->STRIPE_APPLICATION_FEE_MAXIMAL;
|
||||||
$fee = $conf->global->STRIPE_APPLICATION_FEE_MINIMAL;
|
} 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, $arrayzerounitcurrency)) $stripefee = round($fee * 100);
|
||||||
else $stripefee = round($fee);
|
else $stripefee = round($fee);
|
||||||
|
|
||||||
@ -942,22 +978,64 @@ class Stripe extends CommonObject
|
|||||||
$paymentarray["receipt_email"] = $societe->email;
|
$paymentarray["receipt_email"] = $societe->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$description", "stripe_account" => "$account"));
|
if (preg_match('/pm_/i', $source))
|
||||||
|
{
|
||||||
|
$stripecard = $source;
|
||||||
|
$amountstripe = $stripeamount;
|
||||||
|
$FULLTAG = 'PFBO'; // Payment From Back Office
|
||||||
|
$stripe = $return;
|
||||||
|
$amounttopay = $amount;
|
||||||
|
$servicestatus = $status;
|
||||||
|
|
||||||
|
dol_syslog("* createPaymentStripe get stripeacc", LOG_DEBUG);
|
||||||
|
$stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account if it exists (no network access here)
|
||||||
|
|
||||||
|
dol_syslog("* createPaymentStripe Create payment on card ".$stripecard->id.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG);
|
||||||
|
|
||||||
|
// Create payment intent and charge payment (confirmnow = true)
|
||||||
|
$paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard->id, 1);
|
||||||
|
|
||||||
|
$charge = new stdClass();
|
||||||
|
if ($paymentintent->status == 'succeeded')
|
||||||
|
{
|
||||||
|
$charge->status = 'ok';
|
||||||
|
$charge->id = $paymentintent->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$charge->status = 'failed';
|
||||||
|
$charge->failure_code = $stripe->code;
|
||||||
|
$charge->failure_message = $stripe->error;
|
||||||
|
$charge->failure_declinecode = $stripe->declinecode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$description", "stripe_account" => "$account"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($charge->id)) {}
|
if (isset($charge->id)) {}
|
||||||
|
|
||||||
$return->statut = 'success';
|
$return->statut = 'success';
|
||||||
$return->id = $charge->id;
|
$return->id = $charge->id;
|
||||||
if ($charge->source->type == 'card') {
|
|
||||||
$return->message = $charge->source->card->brand . " ...." . $charge->source->card->last4;
|
if (preg_match('/pm_/i', $source))
|
||||||
} elseif ($charge->source->type == 'three_d_secure') {
|
{
|
||||||
$stripe = new Stripe($this->db);
|
$return->message = 'Payment retreived by card status = '.$charge->status;
|
||||||
$src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
|
}
|
||||||
"stripe_account" => $stripe->getStripeAccount($service)
|
else
|
||||||
));
|
{
|
||||||
$return->message = $src->card->brand . " ...." . $src->card->last4;
|
if ($charge->source->type == 'card') {
|
||||||
} else {
|
$return->message = $charge->source->card->brand . " ...." . $charge->source->card->last4;
|
||||||
$return->message = $charge->id;
|
} elseif ($charge->source->type == 'three_d_secure') {
|
||||||
|
$stripe = new Stripe($this->db);
|
||||||
|
$src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
|
||||||
|
"stripe_account" => $stripe->getStripeAccount($service)
|
||||||
|
));
|
||||||
|
$return->message = $src->card->brand . " ...." . $src->card->last4;
|
||||||
|
} else {
|
||||||
|
$return->message = $charge->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\Stripe\Error\Card $e) {
|
} catch (\Stripe\Error\Card $e) {
|
||||||
include DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
include DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
/**
|
/**
|
||||||
* \file htdocs/stripe/payment.php
|
* \file htdocs/stripe/payment.php
|
||||||
* \ingroup stripe
|
* \ingroup stripe
|
||||||
* \brief Payment page for customers invoices. TODO Seems deprecated and bugged !
|
* \brief Payment page for customers invoices. @TODO Seems deprecated and bugged and not used (no link to this page) !
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Load Dolibarr environment
|
// Load Dolibarr environment
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user