|
|
@@ -194,6 +194,7 @@ class CreditController extends ProducerBaseController |
|
|
|
public function actionStripeVerification() |
|
|
|
{ |
|
|
|
$producer = $this->getProducer(); |
|
|
|
$contactProducer = $producer->getMainContact(); |
|
|
|
|
|
|
|
$payload = @file_get_contents('php://input'); |
|
|
|
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE']; |
|
|
@@ -222,6 +223,14 @@ class CreditController extends ProducerBaseController |
|
|
|
$user = User::findOne($paymentIntentMetadata->user_id); |
|
|
|
$idProducer = $paymentIntentMetadata->producer_id; |
|
|
|
|
|
|
|
if(isset($paymentIntentMetadata->order_id)) { |
|
|
|
$order = Order::searchOne([ |
|
|
|
'id' => $paymentIntentMetadata->order_id |
|
|
|
]); |
|
|
|
$pointSale = PointSale::searchOne(['id' => $order->id_point_sale]); |
|
|
|
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one(); |
|
|
|
} |
|
|
|
|
|
|
|
// Handle the event |
|
|
|
switch ($event->type) { |
|
|
|
case 'charge.succeeded': |
|
|
@@ -237,61 +246,50 @@ class CreditController extends ProducerBaseController |
|
|
|
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD; |
|
|
|
$creditHistory->save(); |
|
|
|
|
|
|
|
if(isset($paymentIntentMetadata->order_id)) { |
|
|
|
$order = Order::searchOne([ |
|
|
|
'id' => $paymentIntentMetadata->order_id |
|
|
|
]); |
|
|
|
|
|
|
|
if($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 = [ |
|
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
'from_name' => $producer->name, |
|
|
|
'to_email' => $user->email, |
|
|
|
'to_name' => $user->getUsername(), |
|
|
|
'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, |
|
|
|
] |
|
|
|
] ; |
|
|
|
Mailjet::sendMail($paramsEmail);*/ |
|
|
|
|
|
|
|
// producteur : mail de confirmation |
|
|
|
$contactProducer = $producer->getMainContact(); |
|
|
|
$pointSale = PointSale::searchOne(['id' => $order->id_point_sale]); |
|
|
|
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one(); |
|
|
|
|
|
|
|
$paramsEmail = [ |
|
|
|
'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 |
|
|
|
] |
|
|
|
]; |
|
|
|
Mailjet::sendMail($paramsEmail); |
|
|
|
} |
|
|
|
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 = [ |
|
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
'from_name' => $producer->name, |
|
|
|
'to_email' => $user->email, |
|
|
|
'to_name' => $user->getUsername(), |
|
|
|
'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, |
|
|
|
] |
|
|
|
] ; |
|
|
|
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 |
|
|
@@ -302,44 +300,62 @@ class CreditController extends ProducerBaseController |
|
|
|
]) |
|
|
|
->one(); |
|
|
|
|
|
|
|
$paramsEmail = [ |
|
|
|
'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($paramsEmail); |
|
|
|
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; |
|
|
|
|
|
|
|
case 'charge.failed': |
|
|
|
|
|
|
|
$paramsEmail = [ |
|
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
'from_name' => $producer->name, |
|
|
|
'to_email' => $user->email, |
|
|
|
'to_name' => $user->getUsername(), |
|
|
|
'subject' => '['.$producer->name.'] Erreur de paiement', |
|
|
|
'content_view_text' => '@common/mail/paymentError-text.php', |
|
|
|
'content_view_html' => '@common/mail/paymentError-html.php', |
|
|
|
'content_params' => [ |
|
|
|
'amount' => $amount, |
|
|
|
'user' => $user, |
|
|
|
'producer' => $producer, |
|
|
|
] |
|
|
|
] ; |
|
|
|
Mailjet::sendMail($paramsEmail); |
|
|
|
// client |
|
|
|
Mailjet::sendMail([ |
|
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
'from_name' => $producer->name, |
|
|
|
'to_email' => $user->email, |
|
|
|
'to_name' => $user->getUsername(), |
|
|
|
'subject' => '['.$producer->name.'] Erreur de paiement', |
|
|
|
'content_view_text' => '@common/mail/paymentError-text.php', |
|
|
|
'content_view_html' => '@common/mail/paymentError-html.php', |
|
|
|
'content_params' => [ |
|
|
|
'amount' => $amount, |
|
|
|
'user' => $user, |
|
|
|
'producer' => $producer, |
|
|
|
] |
|
|
|
]); |
|
|
|
|
|
|
|
// producteur |
|
|
|
if(isset($order) && $order) { |
|
|
|
Mailjet::sendMail([ |
|
|
|
'from_email' => $producer->getEmailOpendistrib(), |
|
|
|
'from_name' => $producer->name, |
|
|
|
'to_email' => $contactProducer->email, |
|
|
|
'to_name' => $contactProducer->name, |
|
|
|
'subject' => '[' . $producer->name . '] Erreur de paiement', |
|
|
|
'content_view_text' => '@common/mail/paymentErrorProducer-text.php', |
|
|
|
'content_view_html' => '@common/mail/paymentErrorProducer-html.php', |
|
|
|
'content_params' => [ |
|
|
|
'amount' => $amount, |
|
|
|
'user' => $user, |
|
|
|
'producer' => $producer, |
|
|
|
'order' => $order, |
|
|
|
'distribution' => $distribution |
|
|
|
] |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|