PHP code example of pimcore / payment-provider-mpay24-seamless

1. Go to this page and download the library: Download pimcore/payment-provider-mpay24-seamless 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-mpay24-seamless example snippets

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

...
//important: if payment is active, then keep payment state and do not allow parallel payment!
if ($this->checkoutManager->hasActivePayment() && $this->cart->isCartReadOnly()) {
    return $this->redirectToRoute('app_shop_cart_list');
}
$paymentInfo = $this->checkoutManager->startOrderPayment();
$payment = $this->checkoutManager->getPayment();
$paymentFormAsString =
    $payment->initPayment(
        $this->cart->getPriceCalculator()->getGrandTotal(),
        [
            'request' => $request,
            'paymentInfo' => $paymentInfo
        ]
);
$order = $this->checkoutManager->getOrder();
$order->setOrderState("");//important to unlock order payment, as order can be locked
$order->save(['versionInfo' => 'Clear state, because payment is not locked yet.']);

$this->view->paymentFormAsString = $paymentFormAsString;

...
<section>
    <h2>Select Payment:</h2>
    <?=$paymentFormAsString;



namespace AppBundle\Controller\Shop;

use AppBundle\Controller\AbstractController;
use AppBundle\Ecommerce\OrderManager\OrderManager;
use AppBundle\Service;
use AppBundle\TraitAware\TraitLoggerAware;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractOrder;
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\Payment\Mpay24Seamless;
use Pimcore\Model\Element\Note;
use Pimcore\Tool;
use Pimcore\Translation\Translator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Routing\Annotation\Route;

class PaymentController extends AbstractController\AbstractFrontendController
{

    use TraitLoggerAware; //initializes getLogger() functionality

    /**
     * @Route("/{_prefix}/checkout/payment/start",  /** @var OrderManager $orderManager */
                $orderManager = $factory->getOrderManager();
                $order = $orderManager->getOrCreateOrderFromCart($serviceShop->getCart());
                $factory->getCommitOrderProcessor()->commitOrder($order);
                return $this->redirectToCheckoutSuccessPage($order);
            } else {
                $baseUrl = Tool::getHostUrl();
                $paymentParams = [
                    'request' => $request,
                    'order' => $checkoutManager->getOrder(),
                    'paymentInfo' => $checkoutManager->getOrder()->getPaymentInfo()->get(0),
                    'successURL' => $baseUrl . $router->generate('app_shop_payment_response', ['type' => 'success', 'elementsclientauth'=>'disabled']),
                    'errorURL' => $baseUrl . $router->generate('app_shop_payment_response', ['type' => 'error', 'elementsclientauth'=>'disabled']),
                    'confirmationURL' => $baseUrl . $router->generate('app_shop_payment_response', ['type' => 'confirmation', 'elementsclientauth'=>'disabled']),
                ];
                //either redirect to paypal, etc. or to internal (error) URL
                list($redirectUrl, $errorText) = $payment->getInitPaymentRedirectUrl($paymentParams);
                if ($errorText) {
                    $this->addFlash('error', [$errorText]);
                    //save note for debugging
                    $order = $checkoutManager->getOrder();
                    $note = new Note();
                    $note->setElement($order);
                    $note->setType("user_payment_denied");
                    $note->setTitle($errorText);
                    $note->setUser(0);
                    $note->save();

                    return $this->redirectToRoute('app_shop_checkout_start');
                }
                return new RedirectResponse($redirectUrl);
            }
        }
    }

    private function redirectToCheckoutSuccessPage(AbstractOrder $order) {
        $factory = \Pimcore\Bundle\EcommerceFrameworkBundle\Factory::getInstance();
        $orderManager = $factory->getOrderManager();
        $encryptedOrderNumber = $orderManager->getEncryptedOrderNumber($order);
        return $this->redirectToRoute('app_shop_checkout_success', ['o' => $encryptedOrderNumber]);
    }

    /**
     * @Route("/{_prefix}/checkout/payment/mpay-response/{type}",