Payum
Source🩷 Sponsor
  • Payum docs
  • Get started
  • Instant payment notification
  • ISO4217 or Currency Details
  • The Architecture
  • Your order integration
  • Supported Gateways
  • Storages
  • Debugging
  • Logging
  • Event Dispatcher
  • Configure gateways in backend
  • Working with sensitive information
  • Encrypt gateway configs stored in database
  • Mask credit card number
  • Develop a custom Payum gateway
  • Troubleshooting
  • Frameworks and e-commerce integration.
  • Payum vs Omnipay
  • How to contribute from sub repository
  • Examples
    • Paypal: Create Gateway
    • Paypal: Redirects
    • Handle redirect
    • Get Status
    • Stripe Js: Create gateway
    • Capture Payment
    • Get Http Reponse
    • Capture Credit Card
    • Authorise script
    • Capture Script
    • Done Script
    • index
    • Notify script
    • Payout Script
    • Refund script
  • Authorize-NET
    • AIM
      • Authorize.Net AIM: Get started
  • Be2Bill
    • Be2Bill Direct
    • Be2Bill Offsite
  • jms-payment-bridge
    • Get Started
  • Klarna
    • Checkout
      • Klarna Checkout: Get Started
    • Invoice
      • Klarna Invoice: Get Started
  • Laravel
    • Get Started
    • Blade Templating
    • Eloquent Storage
    • Payment done controller
    • Store gateway config in database
    • Examples
  • Offline
    • Get Started
  • Payex
    • Get Started
  • Paypal
    • Express Checkout
      • Get Started
      • Authorize order
      • Authorize token custom query parameters
      • Cancel recurring payment
      • Confirm order step
      • Recurring Payments Basics
    • IPN
      • Get Started
    • Masspay
      • Get Started
    • Pro Checkout
      • Get Started
    • Pro Hosted
      • Get Started
    • REST
      • Get Started
      • Credit Card Purchase
  • Silex
    • Get Started
    • Payment Done Controller
  • Sofort
    • Get Started
    • Disable Notifications
  • Stripe
    • Checkout
    • Direct
    • Stripe.js
    • Raw Capture
    • Store card and use later
    • Subscription Billing
  • Symfony
    • Get started
    • Authorize Payment
    • Configure payment in backend
    • Console commands
    • Container tags
    • Custom Action
    • Custom API usage
    • Creating custom view for payment page
    • Custom purchase examples
    • Debugging
    • Encrypt gateway configs stored in database
    • ISO4217 or Currency Details
    • Purchase done action
    • Refund Payment
    • Sandbox
    • Storages
    • Configuration Reference
    • Custom Purchase Examples
      • Authorize.NET AIM
      • Be2Bill onsite
      • Be2Bill Credit Card
      • Klarna Checkout
      • Klarna Invoice
      • Payex
      • Paypal Express Checkout
      • Paypal Pro Checkout
      • Paypal via Omnipay
      • Stripe checkout
      • Stripe.js
      • Stripe via Omnipay
Powered by GitBook
On this page
Edit on GitHub
  1. Symfony

Creating custom view for payment page

Sometimes you may want to integrate the payment page into your own checkout/payment flow so it "blends" with other pages.

In such case you will most likely need to pass some extra data (arrays and/or objects) to the templating engine / payum controller.

For example - you may want to show some extra order details on the payment page so passing the "order" object would be a good idea.

In order to achieve that you must replace the default payum templates with your own and add the extra data to the data that is sent to the payum controller responsible for rendering the payment page.

Edit your payum configuration file and add your templates configuration:

    gateways:
        [...]
        your_gateway:
            [...]
            payum.template.layout: 'MyBundle:Default:myLayout.html.twig'
            payum.template.obtain_token: 'MyBundle:Default:payment.html.twig'

"myLayout.html.twig" will be most likely the main layout template for your site (or checkout).

The easiest way to create your own version of the "payment.html.twig" template is to make a copy of the original gateway template. For example - the template for Stripe_js can be found here (if you installed the package):

[...]/vendor/payum/stripe/Payum/Stripe/Resources/views/Action/obtain_checkout_token.html

...so just copy it to payment.html.twig and add all the extra content you need there.

The next step is creating an extension that will add your data to the data used when the view is created.

<?php
 
namespace MyBundle\Extension;
  
use Payum\Core\Extension\ExtensionInterface;
use Payum\Core\Extension\Context;
use Payum\Core\Request\RenderTemplate;
  
class PayumOrderExtension implements ExtensionInterface
{
    protected $data = [];

    public function __construct(array $data)
    {
        $this->data = $data;
    }

    public function onPreExecute(Context $context)
    {
        $request = $context->getRequest();
        if ($request instanceof RenderTemplate)
        {
            $request->addParameter('data', $this->data);
        }
    }
   [...]
}

Finally you need to add your data in controller:

<?php
    
    [...]
    
    /**
     * @Route(
     *     "/someorder/{orderUid}/payment",
     *     name = "someorder_payment",
     *     requirements = { "orderUid" = "^[A-Z0-9]+$" }
     * )
     */
    public function someorderPaymentAction(Request $request, $orderUid)
    {
        [...]
  
        $order = /* get your order from database ? */
  
        $payum = $this->get('payum');
  
        $gateway = $payum->getGateway('your_gateway');
 
        /** add $order and whatever else you may need to data */
        $gateway->addExtension(new PayumOrderExtension(
               array(
                   'order'         => $order,
                   'other_stuff'   => 'hi',
                   [...]
               )
            )
        );
  
        $storage = $payum->getStorage('[...]\OrderPayment');
        
        $payment = $storage->create();
        [...]
        $storage->update($payment);

        $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
            $order->getPaymentMethod(),
            $payment,
            'order_confirmation', /* your order confirmation route */
            array('orderUid' => $order->getUid())
        );

        $gateway->execute(new Capture($captureToken));

You should now be able to have your customized payment page...


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:

PreviousCustom API usageNextCustom purchase examples

Last updated 1 year ago

Become a sponsor