|
|
|
|
|
|
|
|
public function actionStripeVerification() |
|
|
public function actionStripeVerification() |
|
|
{ |
|
|
{ |
|
|
$producer = $this->getProducer(); |
|
|
$producer = $this->getProducer(); |
|
|
|
|
|
$contactProducer = $producer->getMainContact(); |
|
|
|
|
|
|
|
|
$payload = @file_get_contents('php://input'); |
|
|
$payload = @file_get_contents('php://input'); |
|
|
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE']; |
|
|
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE']; |
|
|
|
|
|
|
|
|
$user = User::findOne($paymentIntentMetadata->user_id); |
|
|
$user = User::findOne($paymentIntentMetadata->user_id); |
|
|
$idProducer = $paymentIntentMetadata->producer_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 |
|
|
// Handle the event |
|
|
switch ($event->type) { |
|
|
switch ($event->type) { |
|
|
case 'charge.succeeded': |
|
|
case 'charge.succeeded': |
|
|
|
|
|
|
|
|
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD; |
|
|
$creditHistory->mean_payment = MeanPayment::CREDIT_CARD; |
|
|
$creditHistory->save(); |
|
|
$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 { |
|
|
else { |
|
|
// envoi d'un email de confirmation |
|
|
// envoi d'un email de confirmation |
|
|
|
|
|
|
|
|
]) |
|
|
]) |
|
|
->one(); |
|
|
->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; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'charge.failed': |
|
|
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; |
|
|
break; |
|
|
|
|
|
|