|
|
@@ -235,86 +235,97 @@ class CreditController extends ProducerBaseController |
|
|
|
switch ($event->type) { |
|
|
|
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, |
|
|
|
$amount, |
|
|
|
$idProducer, |
|
|
|
$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_name' => $producer->name, |
|
|
|
'to_email' => $user->email, |
|
|
|
'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_html' => '@common/mail/paymentOrderConfirm-html.php', |
|
|
|
'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([ |
|
|
|
'id_user' => $idUser, |
|
|
|
'id_producer' => $idProducer |
|
|
|
]) |
|
|
|
'id_user' => $idUser, |
|
|
|
'id_producer' => $idProducer |
|
|
|
]) |
|
|
|
->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; |