Browse Source

[Global] Système de feature flag #1385

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
5aba135f8a
19 changed files with 367 additions and 157 deletions
  1. +13
    -1
      backend/controllers/FeatureAdminController.php
  2. +10
    -1
      backend/views/feature-admin/index.php
  3. +8
    -1
      backend/views/feature-admin/update.php
  4. +24
    -15
      backend/views/producer/update.php
  5. +7
    -1
      backend/web/js/backend.js
  6. +5
    -0
      common/logic/AbstractRepository.php
  7. +1
    -0
      common/logic/Feature/Feature/Model/Feature.php
  8. +8
    -1
      common/logic/Feature/Feature/Repository/FeatureRepository.php
  9. +8
    -0
      common/logic/Feature/Feature/Repository/FeatureRepositoryQuery.php
  10. +1
    -0
      common/logic/Feature/Feature/Service/FeatureDefinition.php
  11. +2
    -1
      composer.json
  12. +104
    -2
      composer.lock
  13. +1
    -0
      console/commands/ImportFeaturesController.php
  14. +25
    -0
      console/migrations/m231113_073008_add_column_feature_position.php
  15. +4
    -1
      frontend/controllers/SiteController.php
  16. +7
    -6
      frontend/views/site/_prices_producer.php
  17. +4
    -1
      frontend/views/site/service.php
  18. +131
    -125
      producer/controllers/CreditController.php
  19. +4
    -1
      producer/views/credit/history.php

+ 13
- 1
backend/controllers/FeatureAdminController.php View File

public function actionIndex() public function actionIndex()
{ {
$featureModule = $this->getFeatureModule(); $featureModule = $this->getFeatureModule();
$dataProviderFeatures = $featureModule->getRepository()->queryAll()->getDataProvider(100);
$dataProviderFeatures = $featureModule->getRepository()->queryDefaultAll()->getDataProvider(100);


return $this->render('index', [ return $this->render('index', [
'producerCurrent' => $this->getProducerCurrent(), 'producerCurrent' => $this->getProducerCurrent(),
} }
} }


public function actionPosition()
{
$array = \Yii::$app->request->post('array');
$positionArray = json_decode(stripslashes($array));

foreach ($positionArray as $id => $position) {
$feature = $this->findModel($id);
$feature->position = $position;
$feature->save();
}
}

protected function findModel($id) protected function findModel($id)
{ {
$featureModule = $this->getFeatureModule(); $featureModule = $this->getFeatureModule();

+ 10
- 1
backend/views/feature-admin/index.php View File

<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProviderFeatures, 'dataProvider' => $dataProviderFeatures,
'columns' => [ 'columns' => [
[
'attribute' => 'position',
'headerOptions' => ['class' => 'position'],
'format' => 'raw',
'filter' => '',
'value' => function ($model) {
return '<a class="btn-position btn btn-default" href="javascript:void(0);"><span class="glyphicon glyphicon-resize-vertical"></span></a>';
}
],
'name', 'name',
[ [
'attribute' => 'status', 'attribute' => 'status',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) { 'value' => function ($model) {
if($model->is_paid_feature && $model->price) { if($model->is_paid_feature && $model->price) {
return Price::format($model->price);
return Price::format($model->price, 0);
} }


return ''; return '';

+ 8
- 1
backend/views/feature-admin/update.php View File

<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'status')->radioList([1 => 'Oui', 0 => 'Non']) ?> <?= $form->field($model, 'status')->radioList([1 => 'Oui', 0 => 'Non']) ?>
<?= $form->field($model, 'name') ?> <?= $form->field($model, 'name') ?>
<?= $form->field($model, 'description')->textarea(['rows' => '4']) ; ?>
<?= $form->field($model, 'description')->widget(letyii\tinymce\Tinymce::class, [
'options' => [
'id' => 'testid',
],
'configs' => [ // Read more: https://www.tiny.cloud/docs/tinymce/6/full-featured-open-source-demo/
'plugins' => 'preview importcss searchreplace autolink autosave save directionality code visualblocks visualchars fullscreen image link media template codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap quickbars emoticons accordion' ,
]
]) ; ?>
<?= $form->field($model, 'only_for_selected_producers')->radioList([1 => 'Oui', 0 => 'Non']) ?> <?= $form->field($model, 'only_for_selected_producers')->radioList([1 => 'Oui', 0 => 'Non']) ?>
<?= $form->field($model, 'is_paid_feature')->radioList([1 => 'Oui', 0 => 'Non']) ?> <?= $form->field($model, 'is_paid_feature')->radioList([1 => 'Oui', 0 => 'Non']) ?>
<?= $form->field($model, 'price') ?> <?= $form->field($model, 'price') ?>

+ 24
- 15
backend/views/producer/update.php View File

use common\helpers\Dropdown; use common\helpers\Dropdown;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Module\DistributionModule; use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\Feature\Feature\Model\Feature;
use common\logic\Feature\Feature\Module\FeatureModule;
use common\logic\User\User\Module\UserModule; use common\logic\User\User\Module\UserModule;
use common\logic\User\UserGroup\Module\UserGroupModule; use common\logic\User\UserGroup\Module\UserGroupModule;
use yii\helpers\Html; use yii\helpers\Html;
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$userGroupModule = UserGroupModule::getInstance(); $userGroupModule = UserGroupModule::getInstance();
$distributionExportManager = DistributionModule::getInstance()->getExportManager(); $distributionExportManager = DistributionModule::getInstance()->getExportManager();
$featureManager = FeatureModule::getInstance()->getManager();


$userCurrent = GlobalParam::getCurrentUser(); $userCurrent = GlobalParam::getCurrentUser();


<?= $form->field($model, 'option_check_by_default_prevent_user_credit') <?= $form->field($model, 'option_check_by_default_prevent_user_credit')
->dropDownList(Dropdown::noYesChoices()); ?> ->dropDownList(Dropdown::noYesChoices()); ?>


<h4>Paiement en ligne</h4>
<?= $form->field($model, 'online_payment')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_online_payment_minimum_amount')
->hint('Valeur par défaut si non défini : ' . Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT . ' €')
->textInput(); ?>
<?= $form->field($model, 'option_stripe_mode_test')->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_online_payment_type')
->dropDownList([
'credit' => 'Alimentation du crédit',
'order' => 'Paiement à la commande',
], []); ?>
<?= $form->field($model, 'option_stripe_public_key')->textInput(); ?>
<?= $form->field($model, 'option_stripe_private_key')->textInput(); ?>
<?= $form->field($model, 'option_stripe_endpoint_secret')->textInput(); ?>
<?php if($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)): ?>
<h4>Paiement en ligne</h4>
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<?= $form->field($model, 'online_payment')
->dropDownList(Dropdown::noYesChoices()); ?>

<?= $form->field($model, 'option_stripe_mode_test')->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_online_payment_type')
->dropDownList([
'credit' => 'Alimentation du crédit',
'order' => 'Paiement à la commande',
], []); ?>
<?= $form->field($model, 'option_stripe_public_key')->textInput(); ?>
<?= $form->field($model, 'option_stripe_private_key')->textInput(); ?>
<?= $form->field($model, 'option_stripe_endpoint_secret')->textInput(); ?>
<?php endif; ?>

<?= $form->field($model, 'option_online_payment_minimum_amount')
->hint('Valeur par défaut si non défini : ' . Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT . ' €')
->textInput(); ?>
<?php endif; ?>
</div> </div>
</div> </div>



+ 7
- 1
backend/web/js/backend.js View File

.then(function (response) { .then(function (response) {
appAlerts.alertResponse(response); appAlerts.alertResponse(response);
}); });
})
});

opendistrib_sortable_list(
'.feature-admin-index',
'.btn-position',
'feature-admin/position'
);
} }


function opendistrib_datepicker() { function opendistrib_datepicker() {

+ 5
- 0
common/logic/AbstractRepository.php View File

{ {
return $this->createQuery(); return $this->createQuery();
} }

public function queryDefaultAll()
{
return $this->createDefaultQuery();
}
} }

+ 1
- 0
common/logic/Feature/Feature/Model/Feature.php View File

{ {
const ALIAS_CONTACT = 'contact'; const ALIAS_CONTACT = 'contact';
const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import'; const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import';
const ALIAS_ONLINE_PAYMENT = 'online_payment';


/** /**
* @inheritdoc * @inheritdoc

+ 8
- 1
common/logic/Feature/Feature/Repository/FeatureRepository.php View File

return [ return [
self::WITH => ['featureProducers'], self::WITH => ['featureProducers'],
self::JOIN_WITH => [], self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ORDER_BY => 'position ASC',
self::ATTRIBUTE_ID_PRODUCER => '' self::ATTRIBUTE_ID_PRODUCER => ''
]; ];
} }
->filterByAlias($alias) ->filterByAlias($alias)
->findOne(); ->findOne();
} }

public function findPaidFeatures(): array
{
return $this->createQuery()
->filterIsPaidFeature()
->find();
}
} }

+ 8
- 0
common/logic/Feature/Feature/Repository/FeatureRepositoryQuery.php View File

$this->andWhere(['alias' => $alias]); $this->andWhere(['alias' => $alias]);
return $this; return $this;
} }

public function filterIsPaidFeature(): self
{
$this->andWhere(['is_paid_feature' => true]);
return $this;
}


} }

+ 1
- 0
common/logic/Feature/Feature/Service/FeatureDefinition.php View File

return [ return [
Feature::ALIAS_CONTACT => $this->buildFeatureArray('Formulaire de contact', true, false), Feature::ALIAS_CONTACT => $this->buildFeatureArray('Formulaire de contact', true, false),
Feature::ALIAS_PRODUCT_PRICE_IMPORT => $this->buildFeatureArray('Produits : import prix', true, false), Feature::ALIAS_PRODUCT_PRICE_IMPORT => $this->buildFeatureArray('Produits : import prix', true, false),
Feature::ALIAS_ONLINE_PAYMENT => $this->buildFeatureArray('Paiement en ligne', true, false),
]; ];
} }



+ 2
- 1
composer.json View File

"weluse/yii2-mailjet": "^0.2.0", "weluse/yii2-mailjet": "^0.2.0",
"ext-json": "*", "ext-json": "*",
"ext-curl": "*", "ext-curl": "*",
"yiisoft/yii2-twig": "^2.4"
"yiisoft/yii2-twig": "^2.4",
"letyii/yii2-tinymce": "dev-master"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-codeception": "*", "yiisoft/yii2-codeception": "*",

+ 104
- 2
composer.lock View File

"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a8cbf9ba6bfa2f0b47fba2344732ac95",
"content-hash": "95e88fd70427210dc0d1edd79d17cce1",
"packages": [ "packages": [
{ {
"name": "2amigos/yii2-chartjs-widget", "name": "2amigos/yii2-chartjs-widget",
], ],
"time": "2022-09-19T18:31:07+00:00" "time": "2022-09-19T18:31:07+00:00"
}, },
{
"name": "letyii/yii2-tinymce",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/letyii/yii2-tinymce.git",
"reference": "861873f30d9e16f76239ae827f2848879f66f78f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/letyii/yii2-tinymce/zipball/861873f30d9e16f76239ae827f2848879f66f78f",
"reference": "861873f30d9e16f76239ae827f2848879f66f78f",
"shasum": ""
},
"require": {
"php": ">=5.4",
"tinymce/tinymce": ">=4",
"yiisoft/yii2": "*"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"letyii\\tinymce\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "TinyMce for yii2 textarea",
"homepage": "https://github.com/letyii/yii2-tinymce",
"keywords": [
"tinymce",
"yii2"
],
"support": {
"issues": "https://github.com/letyii/yii2-tinymce/issues",
"source": "https://github.com/letyii/yii2-tinymce/tree/master"
},
"time": "2015-07-08T08:11:14+00:00"
},
{ {
"name": "linslin/yii2-curl", "name": "linslin/yii2-curl",
"version": "1.5.0", "version": "1.5.0",
], ],
"time": "2022-11-03T14:55:06+00:00" "time": "2022-11-03T14:55:06+00:00"
}, },
{
"name": "tinymce/tinymce",
"version": "6.7.2",
"source": {
"type": "git",
"url": "https://github.com/tinymce/tinymce-dist.git",
"reference": "a4c139bde17a4e8b2e84d225020cd5acc24a728a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tinymce/tinymce-dist/zipball/a4c139bde17a4e8b2e84d225020cd5acc24a728a",
"reference": "a4c139bde17a4e8b2e84d225020cd5acc24a728a",
"shasum": ""
},
"type": "component",
"extra": {
"component": {
"scripts": [
"tinymce.js",
"plugins/*/plugin.js",
"themes/*/theme.js",
"models/*/model.js",
"icons/*/icons.js"
],
"files": [
"tinymce.min.js",
"plugins/*/plugin.min.js",
"themes/*/theme.min.js",
"models/*/model.min.js",
"skins/**",
"icons/*/icons.min.js"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT-only"
],
"description": "Web based JavaScript HTML WYSIWYG editor control.",
"homepage": "https://www.tiny.cloud/",
"keywords": [
"contenteditable",
"editing",
"html",
"javascript",
"rich editor",
"rich text",
"rich text editor",
"richtext",
"rte",
"text",
"tinymce",
"wysiwyg"
],
"support": {
"source": "https://github.com/tinymce/tinymce-dist/tree/6.7.2"
},
"time": "2023-10-25T06:42:18+00:00"
},
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.7.1", "version": "v3.7.1",
"stability-flags": { "stability-flags": {
"kartik-v/yii2-mpdf": 20, "kartik-v/yii2-mpdf": 20,
"c006/yii2-paypal-ipn": 20, "c006/yii2-paypal-ipn": 20,
"yurkinx/yii2-image": 20
"yurkinx/yii2-image": 20,
"letyii/yii2-tinymce": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,

+ 1
- 0
console/commands/ImportFeaturesController.php View File



class ImportFeaturesController extends Controller class ImportFeaturesController extends Controller
{ {
// ./yii import-features/index
public function actionIndex() public function actionIndex()
{ {
$featureModule = FeatureModule::getInstance(); $featureModule = FeatureModule::getInstance();

+ 25
- 0
console/migrations/m231113_073008_add_column_feature_position.php View File

<?php

use yii\db\Migration;

/**
* Class m231113_073008_add_column_feature_position
*/
class m231113_073008_add_column_feature_position extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('feature', 'position', $this->integer()->notNull()->defaultValue(0));
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('feature', 'position');
}
}

+ 4
- 1
frontend/controllers/SiteController.php View File



public function actionService() public function actionService()
{ {
$paidFeaturesArray = $this->getFeatureModule()->getRepository()->findPaidFeatures();

return $this->render('service', [ return $this->render('service', [
'producerDemoAccount' => $this->getProducerModule()->findOneProducerDemoAccount(), 'producerDemoAccount' => $this->getProducerModule()->findOneProducerDemoAccount(),
'dataProviderPrices' => $this->getDataProviderPrices()
'dataProviderPrices' => $this->getDataProviderPrices(),
'paidFeaturesArray' => $paidFeaturesArray
]); ]);
} }



+ 7
- 6
frontend/views/site/_prices_producer.php View File

* termes. * termes.
*/ */


use common\helpers\Price;
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\Html;


?> ?>


</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($paidFeaturesArray as $paidFeature): ?>
<tr> <tr>
<td> <td>
<strong>Paiement en ligne</strong><br>
<p>Le paiement en ligne permet à vos clients d'alimenter leur crédit (compte prépayé en ligne) par carte bancaire.<br>
Le logiciel fonctionne avec la plateforme <a href="https://stripe.com/fr">Stripe</a> pour accepter les paiements.<br>
<a href="https://stripe.com/fr/pricing">Voir les tarifs Stripe</a>
</p>
<div><strong><?= Html::encode($paidFeature->name) ?></strong></div>
<div><?= $paidFeature->description ?></div>
</td> </td>
<td>120 €</td>
<td><?= Price::format($paidFeature->price, 0) ?></td>
</tr> </tr>
<?php endforeach; ?>
</tbody> </tbody>
</table> </table>



+ 4
- 1
frontend/views/site/service.php View File

</h2> </h2>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?= $this->render('_prices_producer', ['dataProviderPrices' => $dataProviderPrices]); ?>
<?= $this->render('_prices_producer', [
'dataProviderPrices' => $dataProviderPrices,
'paidFeaturesArray' => $paidFeaturesArray
]); ?>
</div> </div>
</div> </div>



+ 131
- 125
producer/controllers/CreditController.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\logic\Feature\Feature\Model\Feature;
use common\logic\Payment\Model\Payment; use common\logic\Payment\Model\Payment;
use producer\models\CreditForm; use producer\models\CreditForm;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;


public function actionAdd() public function actionAdd()
{ {
$featureManager = $this->getFeatureModule()->getManager();
$producer = $this->getProducerCurrent(); $producer = $this->getProducerCurrent();
if (\Yii::$app->user->isGuest) { if (\Yii::$app->user->isGuest) {
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id])); return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
} }


if ($producer->online_payment || $producer->option_stripe_mode_test) {
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)
&& ($producer->online_payment || $producer->option_stripe_mode_test)) {


$creditForm = new CreditForm; $creditForm = new CreditForm;


'product_data' => [ 'product_data' => [
'name' => 'Alimentation crédit', 'name' => 'Alimentation crédit',
], ],
'unit_amount' => (float) $creditForm->amount * 100,
'unit_amount' => (float)$creditForm->amount * 100,
], ],
'quantity' => 1, 'quantity' => 1,
] ]
$paymentManager = $this->getPaymentModule(); $paymentManager = $this->getPaymentModule();
$producerModule = $this->getProducerModule(); $producerModule = $this->getProducerModule();
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$producer = $this->getProducerCurrent();
$contactProducer = $producerModule->getMainContact($producer);

$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];

try {
$event = \Stripe\Webhook::constructEvent(
$payload,
$sig_header,
$producerModule->getPrivateKeyEndpointStripe($producer)
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
$featureManager = $this->getFeatureModule()->getManager();


$paymentIntent = $event->data->object;
$paymentIntentMetadata = $paymentIntent->metadata;
$amount = $paymentIntent->amount / 100;
$idUser = $paymentIntentMetadata->user_id;
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT)) {
$producer = $this->getProducerCurrent();
$contactProducer = $producerModule->getMainContact($producer);


if($idUser) {
$user = $userModule->findOneUserById($idUser);
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];


if (isset($paymentIntentMetadata->order_id)) {
$order = $this->getOrderModule()->findOneOrderById($paymentIntentMetadata->order_id);
$orderModule->initOrder($order);
$pointSale = $this->getPointSaleModule()->findOnePointSaleById($order->id_point_sale);
$distribution = $this-> getDistributionModule()->findOneDistributionById($order->id_distribution);
try {
$event = \Stripe\Webhook::constructEvent(
$payload,
$sig_header,
$producerModule->getPrivateKeyEndpointStripe($producer)
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
} }


// Handle the event
switch ($event->type) {
case 'charge.succeeded':
$paymentIntent = $event->data->object;
$paymentIntentMetadata = $paymentIntent->metadata;
$amount = $paymentIntent->amount / 100;
$idUser = $paymentIntentMetadata->user_id;


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


if (!$paymentExist) {
if (isset($paymentIntentMetadata->order_id)) {
$order = $this->getOrderModule()->findOneOrderById($paymentIntentMetadata->order_id);
$orderModule->initOrder($order);
$pointSale = $this->getPointSaleModule()->findOnePointSaleById($order->id_point_sale);
$distribution = $this->getDistributionModule()->findOneDistributionById($order->id_distribution);
}


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


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

if (!$paymentExist) {

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

if (isset($order) && $order) {

$paymentManager->payOrder($order, MeanPayment::CREDIT_CARD, $user, true);


// 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->getUserProducerModule()->findOneUserProducer($user);

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


$paymentManager->payOrder($order, MeanPayment::CREDIT_CARD, $user, true);
break;


case 'charge.failed':


// 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
);*/
// client
\Yii::$app->mailerService->sendFromProducer(
'Erreur de paiement',
'paymentError',
[
'amount' => $amount,
'user' => $user,
'producer' => $producer,
],
$user->email,
$producer
);


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

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

break;

case 'charge.failed':

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


// 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,
);
}
break;


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


// handle other event types
default:
echo 'Received unknown event type ' . $event->type;
http_response_code(200);
} else {
http_response_code(200);
} }

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


die(); die();

+ 4
- 1
producer/views/credit/history.php View File

* termes. * termes.
*/ */


use common\logic\Feature\Feature\Model\Feature;
use common\logic\Feature\Feature\Module\FeatureModule;
use common\logic\Payment\Module\PaymentModule; use common\logic\Payment\Module\PaymentModule;
use yii\grid\GridView; use yii\grid\GridView;


$paymentManager = PaymentModule::getInstance(); $paymentManager = PaymentModule::getInstance();
$featureManager = FeatureModule::getInstance();
$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); $this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>');
$this->setPageTitle('Crédit'); $this->setPageTitle('Crédit');


if ($this->context->getProducerCurrent()->online_payment) {
if ($featureManager->isEnabled(Feature::ALIAS_ONLINE_PAYMENT) && $this->context->getProducerCurrent()->online_payment) {
$this->addButton( $this->addButton(
[ [
'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte', 'label' => '<span class="glyphicon glyphicon-credit-card"></span> Créditer mon compte',

Loading…
Cancel
Save