PHP code example of novalnet / payum

1. Go to this page and download the library: Download novalnet/payum 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/ */

    

novalnet / payum example snippets


...
public function register()
{
    $this->app->resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
        $payumBuilder
        ->addDefaultStorages()
        ->addGatewayFactory('novalnet', function(array $config, GatewayFactoryInterface $coreGatewayFactory) {
            return new \Payum\Novalnet\NovalnetGatewayFactory($config, $coreGatewayFactory);
        })
        ->addGateway('novalnet', [
            'factory' => 'novalnet',
            'payment_access_key' => '###YOUR_PAYMENT_ACCESS_KEY###',
            'signature' => '###YOUR_API_SIGNATURE###',
            'tariff' => '###YOUR_TARIFF_ID###'
        ]);
    });

    $this->app->resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
        $payumBuilder
        ->addDefaultStorages()
        ->addGatewayFactory('novalnet_creditcard', function(array $config, GatewayFactoryInterface $coreGatewayFactory) {
            return new \Payum\Novalnet\NovalnetCreditCardGatewayFactory($config, $coreGatewayFactory);
        })
        ->addGateway('novalnet_creditcard', [
            'factory' => 'novalnet_creditcard',
            'payment_access_key' => '###YOUR_PAYMENT_ACCESS_KEY###',
            'signature' => '###YOUR_API_SIGNATURE###',
            'tariff' => '###YOUR_TARIFF_ID###'
            'sandbox' => false, // (true/false) true = The payment will be processed in the test mode therefore amount for this transaction will not be charged, false = The payment will be processed in the live mode.
            'callback_debug_mode' => false, // (true/false) Please disable this option before setting your shop to LIVE mode, to avoid unauthorized calls from external parties (excl. Novalnet). For LIVE, set the value as false.
            'payment_data' => [
                'action' => 'capture', // (authorize/capture) Capture completes the transaction by transferring the funds from buyer account to merchant account. Authorize verifies payment details and reserves funds to capture it later, giving time for the merchant to decide on the order
                'client_key' => '###YOUR_CLIENT_KEY###', // A public unique key needs linked to your account. It is needed to do the client-side authentication. You can find this credential by logging into your Novalnet Admin Portal
                'enforce_3d' => false, // (true/false) By enabling this option, all payments from cards issued outside the EU will be authenticated via 3DS 2.0 SCA.
                'inline' => true, // (true/false) true = Show Inline Credit card form form, false = Show Credit Card form in multi lines.
                'container' => '', // Customize styles of the Credit Card iframe.
                'input' => '', // Customize styles of the Credit Card iframe input element.
                'label' => '', // Customize styles of the Credit Card iframe label element.
            ],
        ]);
    });
}
...



namespace App\Http\Controllers;

use Payum\LaravelPackage\Controller\PayumController;
use Payum\Core\Model\ArrayObject;

class NovalnetPaymentController extends PayumController
{
    public function doPayment()
    {
        $gatewayName = 'novalnet_creditcard';

        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $details = $storage->create();

        $data['customer'] = [
                'first_name' => 'novalnet',
                'last_name' => 'tester',
                'email' => '[email protected]',
                'customer_no' => '147',
                'billing' => [
                    'street' => 'Feringastraße',
                    'house_no' => '4',
                    'city' => 'Unterföhring',
                    'zip' => '85774',
                    'country_code' => 'DE',
                ]
            ];
        $data['transaction'] = [
                'amount' => '150',
                'currency' => 'EUR',
                'order_no' => '123456',
            ];
        $data['custom'] = [
                'lang' => 'EN'
            ];

        $details['nn_request'] = $data;

        $storage->update($details);

        $notifyToken = $this->getPayum()->getTokenFactory()->createNotifyToken($gatewayName, $details);
        $data['transaction']['hook_url'] = $notifyToken->getTargetUrl();

        $details['nn_request'] = $data;

        $storage->update($details);

        $authorizeToken = $this->getPayum()->getTokenFactory()->createAuthorizeToken($gatewayName, $details, 'payment_done');

        return \Redirect::to($authorizeToken->getTargetUrl());
    }
}




namespace App\Http\Controllers;

use Payum\LaravelPackage\Controller\PayumController;
use Payum\Core\Model\ArrayObject;

class NovalnetRefundController extends PayumController
{
    public function doRefund()
    {
        $gatewayName = 'novalnet';

        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $details = $storage->create();

        $data = ['transaction' => [
                'tid' => '###NOVALNET_TID###',
                'amount' => 'XXX'
            ]
        ];

        $details['nn_request'] = $data;

        $storage->update($details);

        $refundToken = $this->getPayum()->getTokenFactory()->createRefundToken($gatewayName, $details, 'payment_done');

        return \Redirect::to($refundToken->getTargetUrl());
    }
}

bash
composer