if ($pointSale->load(\Yii::$app->request->post()) && $pointSale->save()) { | if ($pointSale->load(\Yii::$app->request->post()) && $pointSale->save()) { | ||||
$pointSaleModule->updatePointSalePointProduction($pointSale); | $pointSaleModule->updatePointSalePointProduction($pointSale); | ||||
$pointSaleModule->processRestrictedAccess($pointSale); | $pointSaleModule->processRestrictedAccess($pointSale); | ||||
$this->initPaymentMethodOnsiteByCreditFunctioning($pointSale); | |||||
$this->initPaymentMethodsByCreditFunctioning($pointSale); | |||||
$distributionModule->addPointSaleIncomingDistributions($pointSale); | $distributionModule->addPointSaleIncomingDistributions($pointSale); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
$pointSaleModule->updatePointSalePointProduction($model); | $pointSaleModule->updatePointSalePointProduction($model); | ||||
$pointSaleModule->processRestrictedAccess($model); | $pointSaleModule->processRestrictedAccess($model); | ||||
$this->initPaymentMethodOnsiteByCreditFunctioning($model); | |||||
$this->initPaymentMethodsByCreditFunctioning($model); | |||||
$distributionModule->addPointSaleIncomingDistributions($model); | $distributionModule->addPointSaleIncomingDistributions($model); | ||||
$this->setFlash('success', 'Point de vente modifié.'); | $this->setFlash('success', 'Point de vente modifié.'); | ||||
public function initPaymentMethodOnsiteByCreditFunctioning(PointSale $pointSale) | public function initPaymentMethodOnsiteByCreditFunctioning(PointSale $pointSale) | ||||
{ | { | ||||
if($this->getPointSaleModule()->getBuilder()->initPaymentMethodOnsiteByCreditFunctioning($pointSale)) { | |||||
if($this->getPointSaleModule()->getBuilder()->initPaymentMethodsByCreditFunctioning($pointSale)) { | |||||
$this->addFlash('info', 'Le paiement sur place a été ajusté par rapport au fonctionnement de la cagnotte.'); | $this->addFlash('info', 'Le paiement sur place a été ajusté par rapport au fonctionnement de la cagnotte.'); | ||||
} | } | ||||
} | } |
->dropDownList(Dropdown::noYesChoices()); ?> | ->dropDownList(Dropdown::noYesChoices()); ?> | ||||
<?= $form->field($model, 'option_stripe_mode_test')->dropDownList(Dropdown::noYesChoices()); ?> | <?= $form->field($model, 'option_stripe_mode_test')->dropDownList(Dropdown::noYesChoices()); ?> | ||||
<?= $form->field($model, 'option_online_payment_type') | |||||
<?php /*$form->field($model, 'option_online_payment_type') | |||||
->dropDownList([ | ->dropDownList([ | ||||
'credit' => 'Alimentation de la cagnotte', | 'credit' => 'Alimentation de la cagnotte', | ||||
'order' => 'Paiement à la commande', | 'order' => 'Paiement à la commande', | ||||
], []); ?> | |||||
], []);*/ ?> | |||||
<?= $form->field($model, 'option_stripe_public_key')->textInput(); ?> | <?= $form->field($model, 'option_stripe_public_key')->textInput(); ?> | ||||
<?= $form->field($model, 'option_stripe_private_key')->textInput(); ?> | <?= $form->field($model, 'option_stripe_private_key')->textInput(); ?> | ||||
<?= $form->field($model, 'option_stripe_endpoint_secret')->textInput(); ?> | <?= $form->field($model, 'option_stripe_endpoint_secret')->textInput(); ?> |
use domain\Producer\Producer\ProducerModule; | use domain\Producer\Producer\ProducerModule; | ||||
use yii\console\Controller; | use yii\console\Controller; | ||||
class InitPointSaleCreditFunctioningFromSettingsController extends Controller | |||||
class InitPointSalePaymentMethodsFromSettingsController extends Controller | |||||
{ | { | ||||
// ./yii init-point-sale-credit-functioning-from-settings/index | |||||
// ./yii init-point-sale-payment-methods-from-settings/index | |||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$producerModule = ProducerModule::getInstance(); | $producerModule = ProducerModule::getInstance(); | ||||
\Yii::$app->logic->setProducerContext($producer); | \Yii::$app->logic->setProducerContext($producer); | ||||
$pointSaleArray = $pointSaleModule->getRepository()->findPointSales(); | $pointSaleArray = $pointSaleModule->getRepository()->findPointSales(); | ||||
$creditFunctioningProducer = $producerModule->getConfig('credit_functioning'); | $creditFunctioningProducer = $producerModule->getConfig('credit_functioning'); | ||||
$isOnlinePaymentActiveAndTypeOrder = $producerModule->isOnlinePaymentActiveAndTypeOrder($producer, false); | |||||
foreach($pointSaleArray as $pointSale) { | foreach($pointSaleArray as $pointSale) { | ||||
if($pointSale->payment_method_credit && !$pointSale->credit_functioning) { | if($pointSale->payment_method_credit && !$pointSale->credit_functioning) { | ||||
$pointSale->credit_functioning = $creditFunctioningProducer; | $pointSale->credit_functioning = $creditFunctioningProducer; | ||||
if($pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | if($pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { | ||||
$pointSale->payment_method_onsite = 1; | |||||
$pointSale->payment_method_onsite = true; | |||||
} | } | ||||
$pointSale->save(); | $pointSale->save(); | ||||
echo 'Point de vente "'.$pointSale->name. '" configuré sur "'.$pointSale->credit_functioning.'"'."\n"; | echo 'Point de vente "'.$pointSale->name. '" configuré sur "'.$pointSale->credit_functioning.'"'."\n"; | ||||
} | } | ||||
$return = $pointSaleModule->getBuilder()->initPaymentMethodsByCreditFunctioning($pointSale); | |||||
if($return) { | |||||
echo 'Point de vente "'.$pointSale->name. '" : modes de paiements adaptés'."\n"; | |||||
} | |||||
if($isOnlinePaymentActiveAndTypeOrder) { | |||||
$pointSale->payment_method_online = true; | |||||
$pointSale->save(); | |||||
echo 'Point de vente "'.$pointSale->name. '" : paiement en ligne activé'."\n"; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
return $this->userPointSaleBuilder->createUserPointSaleIfNotExist($user, $pointSale); | return $this->userPointSaleBuilder->createUserPointSaleIfNotExist($user, $pointSale); | ||||
} | } | ||||
public function initPaymentMethodOnsiteByCreditFunctioning(PointSale $pointSale): bool | |||||
public function initPaymentMethodsByCreditFunctioning(PointSale $pointSale): bool | |||||
{ | { | ||||
if($pointSale->payment_method_credit) { | if($pointSale->payment_method_credit) { | ||||
if($pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && !$pointSale->payment_method_onsite) { | if($pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_OPTIONAL && !$pointSale->payment_method_onsite) { |
return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | return $this->getPrivateKeyStripe($this->getFilenamePrivateKeyEndpointStripe($producer)); | ||||
} | } | ||||
public function isOnlinePaymentActive(Producer $producer): bool | |||||
public function isOnlinePaymentActive(Producer $producer, bool $checkModeTest = true): bool | |||||
{ | { | ||||
return $producer->online_payment | |||||
|| ($producer->option_stripe_mode_test | |||||
$return = $producer->online_payment; | |||||
if($checkModeTest) { | |||||
$return = $return | |||||
|| ($producer->option_stripe_mode_test | |||||
&& !\Yii::$app->user->isGuest | && !\Yii::$app->user->isGuest | ||||
&& \Yii::$app->user->identity->status > 10); | && \Yii::$app->user->identity->status > 10); | ||||
} | |||||
return (bool) $return; | |||||
} | } | ||||
public function isOnlinePaymentActiveAndTypeOrder(Producer $producer): bool | |||||
public function isOnlinePaymentActiveAndTypeOrder(Producer $producer, bool $checkModeTest = true): bool | |||||
{ | { | ||||
return $this->isOnlinePaymentActive($producer) | |||||
return $this->isOnlinePaymentActive($producer, $checkModeTest) | |||||
&& $producer->option_online_payment_type == 'order'; | && $producer->option_online_payment_type == 'order'; | ||||
} | } | ||||