Note: Where payum/offline is a payum gateway, you can for example change it to payum/paypal-express-checkout-nvp or payum/stripe. Look atsupported gatewaysto find out what you can use.
Note: Use payum/payum if you want to install all gateways at once.
When using Symfony Flex, the bundle should automatically be added to the bundle config.
If that did not happen, or if you are not using Symfony Flex, then enable the bundle in the config
First we need two entities: Token and Payment.
The token entity is used to protect your payments, while the payment entity stores all your payment information.
Note: In this chapter we show how to use Doctrine ORM entities. There are other supported storages.
After setting up the payment, the user will be redirected to doneAction(). You can read more about it in its dedicated chapter. doneAction() is always called, no matter if the payment was successful or not. Here we may check the payment status, update the model, dispatch events and so on.
<?php// src/Acme/PaymentBundle/Controller/PaymentController.phpnamespaceAcme\PaymentBundle\Controller;usePayum\Core\Request\GetHumanStatus;useSymfony\Component\HttpFoundation\Request;useSymfony\Component\HttpFoundation\JsonResponse;classPaymentControllerextendsController{/** * @Route("/payment-done", name="payum_payment_done") */publicfunctiondoneAction(Request $request,Payum $payum) { $token = $payum->getHttpRequestVerifier()->verify($request); $gateway = $payum->getGateway($token->getGatewayName());// You can invalidate the token, so that the URL cannot be requested any more:// $payum->getHttpRequestVerifier()->invalidate($token);// Once you have the token, you can get the payment entity from the storage directly. // $identity = $token->getDetails();// $payment = $payum->getStorage($identity->getClass())->find($identity);// Or Payum can fetch the entity for you while executing a request (preferred). $gateway->execute($status =newGetHumanStatus($token)); $payment = $status->getFirstModel();// Now you have order and payment statusreturnnewJsonResponse(array('status'=> $status->getValue(),'payment'=>array('total_amount'=> $payment->getTotalAmount(),'currency_code'=> $payment->getCurrencyCode(),'details'=> $payment->getDetails(), ), )); }}
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: