PHP code example of pimcore / payment-provider-hobex

1. Go to this page and download the library: Download pimcore/payment-provider-hobex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pimcore / payment-provider-hobex example snippets


  /**
     * Payment step of the checkout.
     * This is where the payment widget is initialized and displayed.
     * @Route("/checkout/payment")
     * @param Request $request
     */
    public function payment(Request $request, Factory $factory) {
        $cartManager = $factory->getCartManager();
        $orderManager = $factory->getOrderManager();

        $cart = $cartManager->getCartByName('cart');
        $checkoutManager = Factory::getInstance()->getCheckoutManager($cart);

        $order = $orderManager->getOrCreateOrderFromCart($cart);       

        $requestConfig = new HobexRequest();
        $requestConfig
            ->setShopperResultUrl($this->generateUrl('app_webshop_payment_result'))
            ->setLocale('de')
        ;
        
        /** @var SnippetResponse $paymentInitResponse */
        $paymentInitResponse = $checkoutManager->startOrderPaymentWithPaymentProvider($requestConfig);

        return $this->renderTemplate('Webshop/Checkout/payment.html.twig', [
            'cart' => $cart,
            'order' => $order,
            'renderedForm' => $paymentInitResponse->getSnippet()
        ]);
    }
    
    /**
     * Final step of the example payment checkout.
     * This is called then the payment succeeded and the order got confirmed.
     * @Route("/checkout/success")
     * @param Request $request
     */
    public function success(Request $request) {
        // needs some implementation. Typically a success page is rendered.
    }

    /**
     * In the payment controller the response from Hobex payments is handled.
     * This action is typically called when the payment succeeded. 
     * @Route("/checkout/payment/result")
     * @param Request $request
     */
    public function result(Request $request, Factory $factory) {

        $cartManager = $factory->getCartManager();
        $orderManager = $factory->getOrderManager();

        $paymentProvider = Factory::getInstance()->getPaymentManager()->getProvider("hobex_testprovider");

        $order = Factory::getInstance()->getCommitOrderProcessor()->handlePaymentResponseAndCommitOrderPayment(
            $request->query->all(),
            $paymentProvider
        );

        if ($order->getOrderState() == AbstractOrder::ORDER_STATE_COMMITTED) {
            return $this->redirectToRoute('app_webshop_checkout_success');
        } else {           
            $errorMessage = 'Something wrent wrong with the payment: '.$order->getLastPaymentInfo()->getMessage());
            // error handling ...
            return $this->redirectToRoute('app_webshop_checkout_step1');
        }

    }

    /**
     * In the payment controller the webhook response from Hobex payments is handled.
     * @Route("/checkout/payment/webhook")
     * @param Request $request
     */
    public function webhookAction(Request $request){
        $paymentProvider = Factory::getInstance()->getPaymentManager()->getProvider("hobex_testprovider");
        $order = Factory::getInstance()->getCommitOrderProcessor()->handlePaymentResponseAndCommitOrderPayment(
                ['base64Content' => $request->getContent(), 'authTag' => $request->headers->get('x-authentication-tag'),
                 'initVector' => $request->headers->get('x-initialization-vector')],
                $paymentProvider
            );
        return new Response('ok',200);

    }

bash
php bin/console pimcore:bundle:enable PimcorePaymentProviderHobexBundle
php bin/console pimcore:bundle:install PimcorePaymentProviderHobexBundle