Browse Source

[Backend] Crédit : compte prépayé crédité deux fois #683

refactoring
Guillaume Bourgeois 2 years ago
parent
commit
7f475e71f4
1 changed files with 72 additions and 61 deletions
  1. +72
    -61
      producer/controllers/CreditController.php

+ 72
- 61
producer/controllers/CreditController.php View File

switch ($event->type) { switch ($event->type) {
case 'charge.succeeded': case 'charge.succeeded':


// on crédite le crédit du client
$creditHistory = new CreditHistory;
$creditHistory->id_user = $idUser;
$creditHistory->id_user_action = $idUser;
$creditHistory->id_producer = $idProducer;
$creditHistory->type = CreditHistory::TYPE_CREDIT;
$creditHistory->comment = null;
$creditHistory->amount = $amount;
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD;
$creditHistory->save();
$creditHistoryExist = CreditHistory::searchOne([
'id_user' => $idUser,
'amount' => $amount,
], [
'conditions' => [
'date > DATE_SUB(NOW(), INTERVAL 1 MINUTE)'
]
]);


if(isset($order) && $order) {
// paiement de la commande
$order->saveCreditHistory(
if(!$creditHistoryExist) {

// on crédite le crédit du client
$creditHistory = new CreditHistory;
$creditHistory->id_user = $idUser;
$creditHistory->id_user_action = $idUser;
$creditHistory->id_producer = $idProducer;
$creditHistory->type = CreditHistory::TYPE_CREDIT;
$creditHistory->comment = null;
$creditHistory->amount = $amount;
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD;
$creditHistory->save();

if (isset($order) && $order) {
// paiement de la commande
$order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT, CreditHistory::TYPE_PAYMENT,
$amount, $amount,
$idProducer, $idProducer,
$order->id_user, $order->id_user,
$order->id_user $order->id_user
);
);


// client : envoi d'un email de confirmation de paiement
/*$paramsEmail = [
// client : envoi d'un email de confirmation de paiement
$paramsEmail = [
'from_email' => $producer->getEmailOpendistrib(), 'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name, 'from_name' => $producer->name,
'to_email' => $user->email, 'to_email' => $user->email,
'to_name' => $user->getUsername(), 'to_name' => $user->getUsername(),
'subject' => '['.$producer->name.'] Confirmation de paiement',
'subject' => '[' . $producer->name . '] Confirmation de paiement',
'content_view_text' => '@common/mail/paymentOrderConfirm-text.php', 'content_view_text' => '@common/mail/paymentOrderConfirm-text.php',
'content_view_html' => '@common/mail/paymentOrderConfirm-html.php', 'content_view_html' => '@common/mail/paymentOrderConfirm-html.php',
'content_params' => [ 'content_params' => [
'amount' => $amount,
'user' => $user,
'producer' => $producer,
'amount' => $amount,
'user' => $user,
'producer' => $producer,
] ]
] ;
Mailjet::sendMail($paramsEmail);*/
];
//Mailjet::sendMail($paramsEmail);


// producteur : mail de confirmation
Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $contactProducer->email,
'to_name' => $contactProducer->name,
'subject' => '[' . $producer->name . '] Confirmation de commande',
'content_view_text' => '@common/mail/orderConfirmProducer-text.php',
'content_view_html' => '@common/mail/orderConfirmProducer-html.php',
'content_params' => [
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
]
]);
}
else {
// envoi d'un email de confirmation
$userProducer = UserProducer::find()
// producteur : mail de confirmation
Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $contactProducer->email,
'to_name' => $contactProducer->name,
'subject' => '[' . $producer->name . '] Confirmation de commande',
'content_view_text' => '@common/mail/orderConfirmProducer-text.php',
'content_view_html' => '@common/mail/orderConfirmProducer-html.php',
'content_params' => [
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
]
]);
} else {
// envoi d'un email de confirmation
$userProducer = UserProducer::find()
->where([ ->where([
'id_user' => $idUser,
'id_producer' => $idProducer
])
'id_user' => $idUser,
'id_producer' => $idProducer
])
->one(); ->one();


Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '['.$producer->name.'] Alimentation de votre crédit',
'content_view_text' => '@common/mail/creditConfirm-text.php',
'content_view_html' => '@common/mail/creditConfirm-html.php',
'content_params' => [
'user' => $user,
'userProducer' => $userProducer,
'producer' => $producer,
'amount' => $amount,
]
]);
Mailjet::sendMail([
'from_email' => $producer->getEmailOpendistrib(),
'from_name' => $producer->name,
'to_email' => $user->email,
'to_name' => $user->getUsername(),
'subject' => '[' . $producer->name . '] Alimentation de votre crédit',
'content_view_text' => '@common/mail/creditConfirm-text.php',
'content_view_html' => '@common/mail/creditConfirm-html.php',
'content_params' => [
'user' => $user,
'userProducer' => $userProducer,
'producer' => $producer,
'amount' => $amount,
]
]);
}
} }


break; break;

Loading…
Cancel
Save