In get it started we showed you how to configure gateways in the Symfony config.yml file. Though it covers most of the cases sometimes you may want to configure gateways in the backend. For example you will be able to change a gateway credentials, add or delete a gateway.
PayumBundle comes with Sonata Admin bundle support out of the box, but you can totally do it manually.
Configure
First we have to create an entity where we store information about a gateway. The model must implement Payum\Core\Model\GatewayConfigInterface.
Note: In this chapter we show how to use Doctrine ORM entities. There are other supported storages.
Once you have configured everything doctrine, payum and sonata admin go to /admin/dashboard. There you have to see a Gateways section. Try to add a gateway there.
Let's say you created a gateway with name paypal. Here we will show you how to use it.
<?php// src/Acme/PaymentBundle/Controller/PaymentController.phpnamespaceAcme\PaymentBundle\Controller;classPaymentControllerextendsController{publicfunctionprepareAction() {// If you have linked a gateway config to your user, you can simply use: $gatewayName =$this->getUser()->getGatewayConfig()->getGatewayName(); $storage =$this->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment'); $payment = $storage->create(); $payment->setNumber(uniqid()); $payment->setCurrencyCode('EUR'); $payment->setTotalAmount(123); // 1.23 EUR $payment->setDescription('A description'); $payment->setClientId('anId'); $payment->setClientEmail('foo@example.com'); $storage->update($payment); $captureToken =$this->get('payum')->getTokenFactory()->createCaptureToken( $gatewayName, $payment,'done'// the route to redirect after capture);return$this->redirect($captureToken->getTargetUrl()); }}
Note: If you configured a gateway in config.yml and in the backend with same name. Backend one will be used.
Supporting Payum
Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider: