Installation du module Stripe
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* This class has been generated by TheliaStudio
|
||||
* For more information, see https://github.com/thelia-modules/TheliaStudio
|
||||
*/
|
||||
|
||||
namespace StripePayment\Controller\Base;
|
||||
|
||||
use StripePayment\StripePayment;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use StripePayment\Model\Config\StripePaymentConfigValue;
|
||||
|
||||
/**
|
||||
* Class StripePaymentConfigController
|
||||
* @package StripePayment\Controller\Base
|
||||
* @author TheliaStudio
|
||||
*/
|
||||
class StripePaymentConfigController extends BaseAdminController
|
||||
{
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["stripepayment"], AccessManager::VIEW)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->render("stripepayment-configuration");
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["stripepayment"], AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$baseForm = $this->createForm("stripepayment.configuration");
|
||||
|
||||
$errorMessage = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($baseForm);
|
||||
$data = $form->getData();
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::ENABLED, is_bool($data["enabled"]) ? (int) ($data["enabled"]) : $data["enabled"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::STRIPE_ELEMENT, is_bool($data["stripe_element"]) ? (int) ($data["stripe_element"]) : $data["stripe_element"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::ONE_CLICK_PAYMENT, is_bool($data["one_click_payment"]) ? (int) ($data["one_click_payment"]) : $data["one_click_payment"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::SECRET_KEY, is_bool($data["secret_key"]) ? (int) ($data["secret_key"]) : $data["secret_key"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::PUBLISHABLE_KEY, is_bool($data["publishable_key"]) ? (int) ($data["publishable_key"]) : $data["publishable_key"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::WEBHOOKS_KEY, is_bool($data["webhooks_key"]) ? (int) ($data["webhooks_key"]) : $data["webhooks_key"]);
|
||||
StripePayment::setConfigValue(StripePaymentConfigValue::SECURE_URL, is_bool($data["secure_url"]) ? (int) ($data["secure_url"]) : $data["secure_url"]);
|
||||
} catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$errorMessage = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], [], StripePayment::MESSAGE_DOMAIN);
|
||||
}
|
||||
|
||||
if (null !== $errorMessage) {
|
||||
// Mark the form as with error
|
||||
$baseForm->setErrorMessage($errorMessage);
|
||||
|
||||
// Send the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($baseForm)
|
||||
->setGeneralError($errorMessage)
|
||||
;
|
||||
} else {
|
||||
$this->getParserContext()
|
||||
->set("success", true)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->defaultAction();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user