PHP code example of omnipay / mollie

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

    

omnipay / mollie example snippets


$gateway = \Omnipay\Omnipay::create('Mollie');  
$gateway->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM');

$response = $gateway->purchase(
    [
        "amount" => "10.00",
        "currency" => "EUR",
        "description" => "My first Payment",
        "returnUrl" => "https://webshop.example.org/mollie-return.php"
    ]
)->send();

// Process response
if ($response->isSuccessful()) {

    // Payment was successful
    print_r($response);

} elseif ($response->isRedirect()) {

    // Redirect to offsite payment gateway
    $response->redirect();

} else {

    // Payment failed
    echo $response->getMessage();
}

$response = $gateway->createOrder(
    [
           'amount'       => '1027.99',
            'currency'     => 'EUR',
            'orderNumber'  => '1337',
            'lines'        => [
                [
                    'type' => 'physical',
                    'sku' => '5702016116977',
                    'name' => 'LEGO 42083 Bugatti Chiron',
                    'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
                    'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
                    'quantity' => 2,
                    'vatRate' => '21.00',
                    'unitPrice' => '399.00',
                    'totalAmount' => '698.00',
                    'discountAmount' => '100.00',
                    'vatAmount' => '121.14',
                ],
                [
                    'type' => 'physical',
                    'sku' => '5702015594028',
                    'name' => 'LEGO 42056 Porsche 911 GT3 RS',
                    'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056',
                    'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
                    'quantity' => 1,
                    'vatRate' => '21.00',
                    'unitPrice' => '329.99',
                    'totalAmount' => '329.99',
                    'vatAmount' => '57.27',
                ]
            ],
            'card' => [
                'company' => 'Mollie B.V.',
                'email' => '[email protected]',
                'birthday' => '1958-01-31',
                'billingTitle' => 'Dhr',
                'billingFirstName' => 'Piet',
                'billingLastName' => 'Mondriaan',
                'billingAddress1' => 'Keizersgracht 313',
                'billingCity' => 'Amsterdam',
                'billingPostcode' => '1234AB',
                'billingState' => 'Noord-Holland',
                'billingCountry' => 'NL',
                'billingPhone' => '+31208202070',
                'shippingTitle' => 'Mr',
                'shippingFirstName' => 'Chuck',
                'shippingLastName' => 'Norris',
                'shippingAddress1' => 'Prinsengracht 313',
                'shippingAddress2' => '4th floor',
                'shippingCity' => 'Haarlem',
                'shippingPostcode' => '5678AB',
                'shippingState' => 'Noord-Holland',
                'shippingCountry' => 'NL',
            ],
            'metadata' => [
                'order_id' => '1337',
                'description' => 'Lego cars',
            ],
            'locale' => 'nl_NL',
            'returnUrl'    => 'https://example.org/redirect',
            'notifyUrl'    => 'https://example.org/webhook',
            'paymentMethod' => 'klarnapaylater',
            'billingEmail' => '[email protected]',
    ]
)->send();

// Process response
if ($response->isSuccessful()) {

    // Payment was successful
    print_r($response);

} elseif ($response->isRedirect()) {

    // Redirect to offsite payment gateway
    $response->redirect();

} else {

    // Payment failed
    echo $response->getMessage();
}

$response = $gateway->completeOrder(
    [
        "transactionReference" => "ord_xxxx",
    ]
)->send();

$response = $gateway->createShipment(
    [
        "transactionReference" => "ord_xxx",
        'items' => [
            [
                'id' => 'odl_xxx',
                'quantity' => 1,
            ]
        ]
    ]
)->send();

$response = $gateway->void(["transactionReference" => "ord_xxx"])->send();