PHP code example of mollie / laravel-mollie

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

    

mollie / laravel-mollie example snippets


MOLLIE_KEY=test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

use Mollie\Laravel\Facades\Mollie;

public function preparePayment()
{
    $payment = Mollie::api()->payments->create([
        "amount" => [
            "currency" => "EUR",
            "value" => "10.00" // You must send the correct number of decimals, thus we enforce the use of strings
        ],
        "description" => "Order #12345",
        "redirectUrl" => route('order.success'),
        "webhookUrl" => route('webhooks.mollie'),
        "metadata" => [
            "order_id" => "12345",
        ],
    ]);

    // redirect customer to Mollie checkout page
    return redirect($payment->getCheckoutUrl(), 303);
}

/**
 * After the customer has completed the transaction,
 * you can fetch, check and process the payment.
 * This logic typically goes into the controller handling the inbound webhook request.
 * See the webhook docs in /docs and on mollie.com for more information.
 */
public function handleWebhookNotification(Request $request) {
    $paymentId = $request->input('id');
    $payment = Mollie::api()->payments->get($paymentId);

    if ($payment->isPaid())
    {
        echo 'Payment received.';
        // Do your thing ...
    }
}