diff --git a/Resources/doc/guides/accepting_payments.rst b/Resources/doc/guides/accepting_payments.rst index 4cc38316..0da7e767 100755 --- a/Resources/doc/guides/accepting_payments.rst +++ b/Resources/doc/guides/accepting_payments.rst @@ -25,9 +25,9 @@ Here's the full code for a minimal ``Order`` entity: .. code-block :: php - // src/AppBundle/Entity/Order.php + // src/App/Entity/Order.php - namespace AppBundle\Entity; + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use JMS\Payment\CoreBundle\Entity\PaymentInstruction; @@ -45,10 +45,14 @@ Here's the full code for a minimal ``Order`` entity: */ private $id; - /** @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction") */ + /** + * @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction") + */ private $paymentInstruction; - /** @ORM\Column(type="decimal", precision=10, scale=5) */ + /** + * @ORM\Column(type="decimal", precision=10, scale=5) + */ private $amount; public function __construct($amount) @@ -104,17 +108,17 @@ Go ahead and create the controller: .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php - namespace AppBundle\Controller; + namespace App\Controller; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; - use Symfony\Bundle\FrameworkBundle\Controller\Controller; + use Symfony\Component\Routing\Annotation\Route; + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; /** * @Route("/orders") */ - class OrdersController extends Controller + class OrdersController extends AbstractController { } @@ -128,10 +132,10 @@ Create the ``newAction`` in the ``OrdersController``: .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use AppBundle\Entity\Order; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + use Symfony\Component\Routing\Annotation\Route; /** * @Route("/new/{amount}") @@ -144,9 +148,9 @@ Create the ``newAction`` in the ``OrdersController``: $em->persist($order); $em->flush(); - return $this->redirect($this->generateUrl('app_orders_show', [ - 'id' => $order->getId(), - ])); + return $this->redirectToRoute('app_orders_show', [ + 'orderId' => $order->getId(), + ]); } If you navigate to ``/orders/new/42.24``, a new ``Order`` will be inserted in the database with ``42.24`` as the ``amount`` and you will be redirected to the ``showAction``, which we will create next. @@ -157,29 +161,29 @@ Once the ``Order`` has been created, the next step in our *Checkout* process is .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php - use AppBundle\Entity\Order; + use App\Entity\Order; use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; + use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; /** - * @Route("/{id}/show") - * @Template + * @Route("/{orderId}/show") */ - public function showAction(Request $request, Order $order) + public function showAction($orderId, Request $request, PluginController $ppc) { + $order = $this->getDoctrine()->getManager()->getRepository(Order::class)->find($orderId); + $form = $this->createForm(ChoosePaymentMethodType::class, null, [ 'amount' => $order->getAmount(), 'currency' => 'EUR', ]); - return [ + return $this->render('Orders/show.html.twig', [ 'order' => $order, 'form' => $form->createView(), - ]; + ]); } .. note :: @@ -199,7 +203,7 @@ And the corresponding template: .. code-block :: twig - {# src/AppBundle/Resources/views/Orders/show.html.twig #} + {# templates/Orders/show.html.twig #} Total price: € {{ order.amount }} @@ -227,19 +231,17 @@ Note that no remote calls to the payment backend are made in this action, we're .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php - use AppBundle\Entity\Order; + use App\Entity\Order; use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; + use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; /** - * @Route("/{id}/show") - * @Template + * @Route("/{orderId}/show") */ - public function showAction(Request $request, Order $order) + public function showAction($orderId, Request $request, PluginController $ppc) { $form = $this->createForm(ChoosePaymentMethodType::class, null, [ 'amount' => $order->getAmount(), @@ -249,7 +251,6 @@ Note that no remote calls to the payment backend are made in this action, we're $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $ppc = $this->get('payment.plugin_controller'); $ppc->createPaymentInstruction($instruction = $form->getData()); $order->setPaymentInstruction($instruction); @@ -258,15 +259,15 @@ Note that no remote calls to the payment backend are made in this action, we're $em->persist($order); $em->flush($order); - return $this->redirect($this->generateUrl('app_orders_paymentcreate', [ - 'id' => $order->getId(), - ])); + return $this->redirectToRoute('app_orders_paymentcreate', [ + 'orderId' => $order->getId(), + ]); } - return [ + return $this->render('Orders/show.html.twig', [ 'order' => $order, 'form' => $form->createView(), - ]; + ]); } Depositing money @@ -279,9 +280,12 @@ Let's start by creating a private method in our controller, which will aid us in .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php - private function createPayment($order) + use App\Entity\Order; + use JMS\Payment\CoreBundle\PluginController\PluginController; + + private function createPayment(Order $order, PluginController $ppc) { $instruction = $order->getPaymentInstruction(); $pendingTransaction = $instruction->getPendingTransaction(); @@ -290,7 +294,6 @@ Let's start by creating a private method in our controller, which will aid us in return $pendingTransaction->getPayment(); } - $ppc = $this->get('payment.plugin_controller'); $amount = $instruction->getAmount() - $instruction->getDepositedAmount(); return $ppc->createPayment($instruction->getId(), $amount); @@ -302,26 +305,28 @@ Now we'll call the ``createPayment`` method we implemented in the previous secti .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php - use AppBundle\Entity\Order; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + use App\Entity\Order; + use Symfony\Component\Routing\Annotation\Route; + use JMS\Payment\CoreBundle\PluginController\PluginController; use JMS\Payment\CoreBundle\PluginController\Result; /** - * @Route("/{id}/payment/create") + * @Route("/{orderId}/payment/create") */ - public function paymentCreateAction(Order $order) + public function paymentCreateAction($orderId, PluginController $ppc) { - $payment = $this->createPayment($order); + $order = $this->getDoctrine()->getManager()->getRepository(Order::class)->find($orderId); + + $payment = $this->createPayment($order, $ppc); - $ppc = $this->get('payment.plugin_controller'); $result = $ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount()); if ($result->getStatus() === Result::STATUS_SUCCESS) { - return $this->redirect($this->generateUrl('app_orders_paymentcomplete', [ - 'id' => $order->getId(), - ])); + return $this->redirectToRoute('app_orders_paymentcomplete', [ + 'orderId' => $order->getId(), + ]); } throw $result->getPluginException(); @@ -347,7 +352,7 @@ We would add the following to our action: .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl; use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException; @@ -377,15 +382,15 @@ The last step in out *Checkout* process is to tell the user the payment was succ .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use Symfony\Component\HttpFoundation\Response; - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + use Symfony\Component\Routing\Annotation\Route; /** - * @Route("/{id}/payment/complete") + * @Route("/{orderId}/payment/complete") */ - public function paymentCompleteAction(Order $order) + public function paymentCompleteAction($orderId) { return new Response('Payment complete'); } diff --git a/Resources/doc/guides/overriding_entity_mapping.rst b/Resources/doc/guides/overriding_entity_mapping.rst index 04b2e890..859c5a29 100644 --- a/Resources/doc/guides/overriding_entity_mapping.rst +++ b/Resources/doc/guides/overriding_entity_mapping.rst @@ -16,10 +16,10 @@ Start by copying the mapping files from this bundle to your application: .. code-block :: shell cd my-app - mkdir -p app/Resources/config/JMSPaymentCoreBundle - cp vendor/jms/payment-core-bundle/JMS/Payment/CoreBundle/Resources/config/doctrine/* app/Resources/config/JMSPaymentCoreBundle/ + mkdir -p config/packages/JMSPaymentCoreBundle + cp vendor/jms/payment-core-bundle/JMS/Payment/CoreBundle/Resources/config/doctrine/* config/packages/JMSPaymentCoreBundle/ -You now have a copy of the following mapping files under ``app/Resources/config/JMSPaymentCoreBundle``: +You now have a copy of the following mapping files under ``config/packages/JMSPaymentCoreBundle``: - ``Credit.orm.xml`` - ``FinancialTransaction.orm.xml`` @@ -32,7 +32,7 @@ The next step is to tell Symfony to use your copy of the files instead of the on .. code-block :: yaml - # app/config/config.yml + # config/packages/doctrine.yml doctrine: orm: @@ -40,7 +40,7 @@ The next step is to tell Symfony to use your copy of the files instead of the on mappings: JMSPaymentCoreBundle: type: xml - dir: '%kernel.root_dir%/../app/Resources/config/JMSPaymentCoreBundle' + dir: '%kernel.root_dir%/config/packages/JMSPaymentCoreBundle' prefix: JMS\Payment\CoreBundle\Entity alias: JMSPaymentCoreBundle @@ -50,7 +50,7 @@ Symfony is now using your custom mapping. Taking ``PaymentInstruction.orm.xml`` .. code-block :: xml - + diff --git a/Resources/doc/payment_form.rst b/Resources/doc/payment_form.rst index 9d6983c7..0d67982e 100644 --- a/Resources/doc/payment_form.rst +++ b/Resources/doc/payment_form.rst @@ -15,7 +15,7 @@ When creating the form you need to specify at least the ``amount`` and ``currenc .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -30,7 +30,7 @@ When creating the form you need to specify at least the ``amount`` and ``currenc .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php $form = $this->createForm('jms_choose_payment_method', null, [ 'amount' => '10.42', @@ -49,7 +49,7 @@ Start by creating an empty theme file: .. code-block :: twig - {# src/AppBundle/Resources/views/Orders/theme.html.twig #} + {# templates/Orders/theme.html.twig #} {% extends 'form_div_layout.html.twig' %} @@ -61,9 +61,9 @@ And then reference it from the template where the form is rendered: .. code-block :: twig - {# src/AppBundle/Resources/views/Orders/show.html.twig #} + {# templates/Orders/show.html.twig #} - {% form_theme form 'AppBundle:Orders:theme.html.twig' %} + {% form_theme form 'Orders\theme.html.twig' %} {{ form_start(form) }} {{ form_widget(form) }} @@ -76,7 +76,7 @@ When the form only has one available payment method (either because only one pay .. code-block :: twig - {# src/AppBundle/Resources/views/Orders/theme.html.twig #} + {# templates/Orders/theme.html.twig #} {# Don't render the radio button's label #} {% block _jms_choose_payment_method_method_label %} @@ -103,7 +103,7 @@ The amount (i.e. total price) of the payment. .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -116,7 +116,7 @@ You might want to add extra costs for a specific payment method. You can impleme .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Entity\ExtendedData; use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -144,7 +144,7 @@ The three-letter currency code, i.e. ``EUR`` or ``USD``. .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -165,7 +165,7 @@ As an example, if we would be using the Stripe plugin, we would need to provide .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -185,7 +185,7 @@ If you would be using multiple payment backends, the ``$predefinedData`` array w .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php $predefinedData = [ 'paypal_express_checkout' => [...], @@ -202,7 +202,7 @@ In case you wish to constrain the methods presented to the user, use the ``allow .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -226,7 +226,7 @@ If you wish to set a default payment method, you can use the ``default_method`` .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -248,7 +248,7 @@ For example, to display a select instead of a radio button, set the ``expanded`` .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; @@ -270,7 +270,7 @@ Pass options to each payment method's form type. For example, to hide the main l .. code-block :: php - // src/AppBundle/Controller/OrdersController.php + // src/App/Controller/OrdersController.php use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType; diff --git a/Resources/doc/setup.rst b/Resources/doc/setup.rst index e09d2b0d..75e603aa 100644 --- a/Resources/doc/setup.rst +++ b/Resources/doc/setup.rst @@ -9,20 +9,6 @@ Install with composer: composer require jms/payment-core-bundle -And register the bundle in your ``AppKernel.php``: - -.. code-block :: php - - // app/AppKernel.php - - public function registerBundles() - { - $bundles = array( - // ... - new JMS\Payment\CoreBundle\JMSPaymentCoreBundle(), - ); - } - Configuration ------------- The configuration is as simple as setting an encryption key which will be used for encrypting data. You can generate a random key with the following command: @@ -35,7 +21,7 @@ And then use it in your configuration: .. code-block :: yaml - # app/config/config.yml + # config/packages/payment.yaml jms_payment_core: encryption: secret: output_of_above_command @@ -67,7 +53,7 @@ Or, if you're using migrations: .. code-block :: yaml - # app/config/config.yml + # config/packages/doctrine.yaml doctrine: orm: auto_mapping: true @@ -76,7 +62,7 @@ Or, if you're using migrations: .. code-block :: yaml - # app/config/config.yml + # config/packages/doctrine.yaml doctrine: orm: mappings: @@ -98,26 +84,11 @@ Using the `Paypal plugin ` composer require jms/payment-paypal-bundle -Register it in your ``AppKernel.php``: - -.. code-block :: php - - // app/AppKernel.php - - public function registerBundles() - { - $bundles = array( - // ... - new JMS\Payment\CoreBundle\JMSPaymentCoreBundle(), - new JMS\Payment\PaypalBundle\JMSPaymentPaypalBundle(), - ); - } - And configure it: .. code-block :: yaml - # app/config/config.yml + # config/packages/payment.yaml jms_payment_paypal: username: your api username