Clean code for IPN
This commit is contained in:
parent
488279aed8
commit
2e563d1ce1
@ -470,7 +470,9 @@ if ($event->type == 'payout.created') {
|
|||||||
$companypaymentmode = new CompanyPaymentMode($db);
|
$companypaymentmode = new CompanyPaymentMode($db);
|
||||||
|
|
||||||
$idthirdparty = $societeaccount->getThirdPartyID($db->escape($event->data->object->customer), 'stripe', $servicestatus);
|
$idthirdparty = $societeaccount->getThirdPartyID($db->escape($event->data->object->customer), 'stripe', $servicestatus);
|
||||||
if ($idthirdparty > 0) { // If the payment mode is on an external customer that is known in societeaccount, we can create the payment mode
|
if ($idthirdparty > 0) {
|
||||||
|
// If the payment mode attached is to a stripe account owned by an external customer in societe_account (so a thirdparty that has a Stripe account),
|
||||||
|
// we can create the payment mode
|
||||||
$companypaymentmode->stripe_card_ref = $db->escape($event->data->object->id);
|
$companypaymentmode->stripe_card_ref = $db->escape($event->data->object->id);
|
||||||
$companypaymentmode->fk_soc = $idthirdparty;
|
$companypaymentmode->fk_soc = $idthirdparty;
|
||||||
$companypaymentmode->bank = null;
|
$companypaymentmode->bank = null;
|
||||||
@ -488,23 +490,27 @@ if ($event->type == 'payout.created') {
|
|||||||
$companypaymentmode->country_code = $db->escape($event->data->object->card->country);
|
$companypaymentmode->country_code = $db->escape($event->data->object->card->country);
|
||||||
$companypaymentmode->status = $servicestatus;
|
$companypaymentmode->status = $servicestatus;
|
||||||
|
|
||||||
|
// TODO Check that a payment mode $companypaymentmode->stripe_card_ref does not exists yet to avoid to create duplicates
|
||||||
|
// so we can remove the test on STRIPE_NO_DUPLICATE_CHECK
|
||||||
|
if (getDolGlobalString('STRIPE_NO_DUPLICATE_CHECK')) {
|
||||||
$db->begin();
|
$db->begin();
|
||||||
if (!$error) {
|
|
||||||
$result = $companypaymentmode->create($user);
|
$result = $companypaymentmode->create($user);
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$db->commit();
|
$db->commit();
|
||||||
} else {
|
} else {
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} elseif ($event->type == 'payment_method.updated') {
|
} elseif ($event->type == 'payment_method.updated') {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php';
|
||||||
$companypaymentmode = new CompanyPaymentMode($db);
|
$companypaymentmode = new CompanyPaymentMode($db);
|
||||||
$companypaymentmode->fetch(0, '', 0, '', " AND stripe_card_ref = '".$db->escape($event->data->object->id)."'");
|
$companypaymentmode->fetch(0, '', 0, '', " AND stripe_card_ref = '".$db->escape($event->data->object->id)."'");
|
||||||
|
if ($companypaymentmode->id > 0) {
|
||||||
|
// If we found a payment mode with the ID
|
||||||
$companypaymentmode->bank = null;
|
$companypaymentmode->bank = null;
|
||||||
$companypaymentmode->label = null;
|
$companypaymentmode->label = null;
|
||||||
$companypaymentmode->number = $db->escape($event->data->object->id);
|
$companypaymentmode->number = $db->escape($event->data->object->id);
|
||||||
@ -531,6 +537,7 @@ if ($event->type == 'payout.created') {
|
|||||||
} else {
|
} else {
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} elseif ($event->type == 'payment_method.detached') {
|
} elseif ($event->type == 'payment_method.detached') {
|
||||||
$db->begin();
|
$db->begin();
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib WHERE number = '".$db->escape($event->data->object->id)."' and status = ".((int) $servicestatus);
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib WHERE number = '".$db->escape($event->data->object->id)."' and status = ".((int) $servicestatus);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user