Przeglądaj źródła

Problème paiements Bourlingue et Pacotille #1201

master
Guillaume Bourgeois 1 rok temu
rodzic
commit
2e1c9a2110
1 zmienionych plików z 99 dodań i 93 usunięć
  1. +99
    -93
      producer/controllers/CreditController.php

+ 99
- 93
producer/controllers/CreditController.php Wyświetl plik

@@ -210,123 +210,129 @@ class CreditController extends ProducerBaseController
$paymentIntentMetadata = $paymentIntent->metadata;
$amount = $paymentIntent->amount / 100;
$idUser = $paymentIntentMetadata->user_id;
$user = $userManager->findOneUserById($paymentIntentMetadata->user_id);
$idProducer = $paymentIntentMetadata->producer_id;

if (isset($paymentIntentMetadata->order_id)) {
$order = $this->getOrderManager()->findOneOrderById($paymentIntentMetadata->order_id);
$orderManager->initOrder($order);
$pointSale = $this->getPointSaleManager()->findOnePointSaleById($order->id_point_sale);
$distribution = $this->getDistributionManager()->findOneDistributionById($order->id_distribution);
}

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

$creditHistoryExist = CreditHistory::searchOne([
'id_user' => $idUser,
'amount' => $amount,
], [
'conditions' => [
'date > DATE_SUB(NOW(), INTERVAL 1 MINUTE)'
]
]);
if($idUser) {
$user = $userManager->findOneUserById($idUser);

if (!$creditHistoryExist) {
if (isset($paymentIntentMetadata->order_id)) {
$order = $this->getOrderManager()->findOneOrderById($paymentIntentMetadata->order_id);
$orderManager->initOrder($order);
$pointSale = $this->getPointSaleManager()->findOnePointSaleById($order->id_point_sale);
$distribution = $this->getDistributionManager()->findOneDistributionById($order->id_distribution);
}

$creditHistoryManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user);
// Handle the event
switch ($event->type) {
case 'charge.succeeded':

if (isset($order) && $order) {
$creditHistoryExist = CreditHistory::searchOne([
'id_user' => $idUser,
'amount' => $amount,
], [
'conditions' => [
'date > DATE_SUB(NOW(), INTERVAL 1 MINUTE)'
]
]);

$creditHistoryManager->payOrder($order, $user, true);
if (!$creditHistoryExist) {

$creditHistoryManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user);

// client : envoi d'un email de confirmation de paiement
/*\Yii::$app->mailerService->sendFromProducer(
'Confirmation de commande',
'paymentOrderConfirm',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
],
$user->email,
$producer
);*/
if (isset($order) && $order) {

// producteur : mail de confirmation
\Yii::$app->mailerService->sendFromSite(
'Confirmation de commande',
'orderConfirmProducer',
[
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
],
$contactProducer->email
);
} else {
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user);
$creditHistoryManager->payOrder($order, $user, true);

\Yii::$app->mailerService->sendFromProducer(
'Alimentation de votre crédit',
'creditConfirm',
[
'user' => $user,
'userProducer' => $userProducer,
'producer' => $producer,
'amount' => $amount,
],
$user->email,
$producer
);
}
}

break;
// client : envoi d'un email de confirmation de paiement
/*\Yii::$app->mailerService->sendFromProducer(
'Confirmation de commande',
'paymentOrderConfirm',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
],
$user->email,
$producer
);*/

// producteur : mail de confirmation
\Yii::$app->mailerService->sendFromSite(
'Confirmation de commande',
'orderConfirmProducer',
[
'order' => $order,
'pointSale' => $pointSale,
'distribution' => $distribution,
'user' => $user,
'producer' => $producer
],
$contactProducer->email
);
} else {
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user);

\Yii::$app->mailerService->sendFromProducer(
'Alimentation de votre crédit',
'creditConfirm',
[
'user' => $user,
'userProducer' => $userProducer,
'producer' => $producer,
'amount' => $amount,
],
$user->email,
$producer
);
}
}

case 'charge.failed':
break;

// client
\Yii::$app->mailerService->sendFromProducer(
'Erreur de paiement',
'paymentError',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
],
$user->email,
$producer
);
case 'charge.failed':

// producteur
if (isset($order) && $order) {
\Yii::$app->mailerService->sendFromSite(
// client
\Yii::$app->mailerService->sendFromProducer(
'Erreur de paiement',
'paymentErrorProducer',
'paymentError',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
'order' => $order,
'distribution' => $distribution
],
$contactProducer->email,
$user->email,
$producer
);
}

break;
// producteur
if (isset($order) && $order) {
\Yii::$app->mailerService->sendFromSite(
'Erreur de paiement',
'paymentErrorProducer',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
'order' => $order,
'distribution' => $distribution
],
$contactProducer->email,
);
}

// handle other event types
default:
echo 'Received unknown event type ' . $event->type;
break;

// handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}

http_response_code(200);
}
else {
http_response_code(400);
}

http_response_code(200);
die();
}
}

Ładowanie…
Anuluj
Zapisz