Skip to content

This addon enables Mollie payments on your Lunar storefront when using the Lunar API package.

License

Notifications You must be signed in to change notification settings

pixelpillow/lunar-api-mollie-adapter

Repository files navigation

lunar-api-mollie-adapter

Table of Contents

Description

This package is designed to seamlessly integrate Mollie payments into your Lunar storefront. By leveraging the Lunar API, this adapter makes it easy to accept and manage payments through Mollie, a popular payment service provider.

Whether you're running an e-commerce platform or a subscription service, this adapter will help you handle payments efficiently and securely. With easy installation and configuration, you can have Mollie payments up and running on your Lunar storefront in no time.

Please follow the installation and configuration instructions in the Installation section to get started.

Dependencies

This package depends on the following packages:

Features

  • Multiple payment methods, including iDEAL, credit card, PayPal, Apple Pay, and more
  • Expose Payment methods in the API
  • Expose Payment issuers for ideal payments in the API

Installation

  1. Install this package via composer:
composer require pixelpillow/lunar-api-mollie-adapter
  1. Publish the config file:
php artisan vendor:publish --tag="lunar-api-mollie-adapter-config"
  1. Add your Mollie API key (You can obtain your API key by signing up on the Mollie website.) to the .env file:
MOLLIE_API_KEY=your-api-key
  1. Add the Mollie payment type to the config/lunar/payments.php file:
<?php

return [
    'default' => env('PAYMENTS_TYPE', 'cash-in-hand'),
    'types' => [
        'cash-in-hand' => [
            'driver' => 'offline',
            'authorized' => 'payment-offline',
        ],
        // Add the Mollie payment type here:
        'mollie' => [
            'driver' => 'mollie',
            'authorized' => 'payment-received',
        ],
    ],
];
  1. Manage the redirect on success in your own RedirectOnSuccessUrlGenerator by defining your own generator in the config/lunar-api-mollie-adapter.php file:
<?php

namespace App\Mollie\Generators;

use Dystcz\LunarApi\Domain\Carts\Models\Cart;
use Pixelpillow\LunarApiMollieAdapter\Generators\RedirectOnSuccessUrlGenerator;

class CustomRedirectOnSuccessUrlGenerator extends RedirectOnSuccessUrlGenerator
{
    /**
     * @var Cart
     */
    protected $cart;

    public function __construct(Cart $cart)
    {
        $this->cart = $cart;
    }

    /**
     * Generate the webhook URL.
     */
    public function generate(): string
    {
        $order = $this->cart->orders()->first();

        if (! $order) {
            throw new \Exception('Order not found');
        }

        // Return your own redirect URL here
        return 'https://example.com/checkout/success?order_id=' . $order->id;
    }
}
  1. Manage the redirect on failure in your the RedirectOnFailureUrlGenerator by defining your own generator in the config/lunar-api-mollie-adapter.php file:
<?php

namespace App\Mollie\Generators;

use Dystcz\LunarApi\Domain\Carts\Models\Cart;
use Lunar\Models\Order;
use Pixelpillow\LunarApiMollieAdapter\Generators\RedirectOnSuccessUrlGenerator;

class CustomRedirectOnFailureUrlGenerator extends RedirectOnSuccessUrlGenerator
{
    /**
     * @var Cart
     */
    protected $cart;

    /**
     * @var Order
     */
    protected $order;

    public function __construct(Cart $cart)
    {
        $this->cart = $cart;
    }

    /**
     * Generate the webhook URL.
     */
    public function generate(): string
    {

        $order = $this->cart->orders()->first();

        if (! $order) {
            throw new \Exception('Order not found');
        }

        // Return your own redirect URL here
        return 'https://example.com/checkout/failure?order_id=' . $order->id;
    }
}

Example JSON:API request for creating a Mollie IDEAL paymentIntent

The create-payment-intent url is a signed url can be found in the response of the POST /api/v1/carts/{cart}/-actions/checkout request.

POST api/v1/orders/{order}/-actions/create-payment-intent

{
  "data": {
    "type": "orders",
    "id": 1,
    "attributes": {
      "payment_method": "mollie",
      "meta": {
        "payment_method_type": "ideal",
        "payment_method_issuer": "ideal_ABNANL2A"
      }
    }
  }
}

Example JSON:API request for creating a Mollie Bancontact paymentIntent

The create-payment-intent url is a signed url can be found in the response of the POST /api/v1/carts/{cart}/-actions/checkout request.

POST api/v1/orders/{order}/-actions/create-payment-intent

{
  "data": {
    "type": "orders",
    "id": 1,
    "attributes": {
      "payment_method": "mollie",
      "meta": {
        "payment_method_type": "bancontact"
      }
    }
  }
}

Endpoints

This package extends the Lunar API with the following endpoints:

GET /api/v1/payment-methods

Returns a list of enabled payment methods in the Mollie dashboard. The results are not paginated. See the Mollie API documentation for more information.

Example response:

{
  "jsonapi": {
    "version": "1.0"
  },
  "data": [
    {
      "type": "payment-methods",
      "id": "ideal",
      "attributes": {
        "name": "iDEAL",
        "method_id": "ideal",
        "image": [
          "https://www.mollie.com/external/icons/payment-methods/ideal.png",
          "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png",
          "https://www.mollie.com/external/icons/payment-methods/ideal.svg"
        ]
      },
      "links": {
        "self": "https://api.monoz.test/api/v1/payment-methods/ideal"
      }
    }
  ]
}

POST /api/v1/payment-issuers

Returns a list of available payment issuers for ideal payments, including the issuer ID, issuer name and more. See the Mollie API documentation for more information.

Example response:

{
  "jsonapi": {
    "version": "1.0"
  },
  "data": [
    {
      "type": "payment-issuers",
      "id": "ideal_ABNANL2A",
      "attributes": {
        "resource": "issuer",
        "name": "ABN AMRO",
        "issuer_id": "ideal_ABNANL2A",
        "image": [
          "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A.png",
          "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A%402x.png",
          "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A.svg"
        ]
      },
      "links": {
        "self": "https://api.monoz.test/api/v1/payment-issuers/ideal_ABNANL2A"
      }
    }
  ]
}

Security

If you discover any security related issues, please email security[at]pixelpillow.nl instead of using the issue tracker.

Acknowledgements

License

The MIT License (MIT). Please see License File for more information.

About

This addon enables Mollie payments on your Lunar storefront when using the Lunar API package.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages