MolliePlugin

MolliePlugin

Plugin to enable payments through the Mollie platform. This plugin uses the Payments API from Mollie, not the Orders API.

Requirements

  1. You will need to create a Mollie account and get your apiKey in the dashboard.

  2. Install the Payments plugin and the Mollie client:

    yarn add @vendure/payments-plugin @mollie/api-client

    or

    npm install @vendure/payments-plugin @mollie/api-client

Setup

  1. Add the plugin to your VendureConfig plugins array:
    import { MolliePlugin } from '@vendure/payments-plugin/package/mollie';
    
    // ...
    
    plugins: [
      MolliePlugin.init({ vendureHost: 'https://yourhost.io/' }),
    ]
    
  2. Create a new PaymentMethod in the Admin UI, and select “Mollie payments” as the handler.
  3. Set the Redirect URL. This is the url that is used to redirect the end-user, e.g. https://storefront/order
  4. Set your Mollie apiKey in the API Key field.

Storefront usage

In your storefront you add a payment to an order using the addPaymentToOrder mutation. In this example, our Mollie PaymentMethod was given the code “mollie-payment-method”.

mutation AddPaymentToOrder {
  addPaymentToOrder(input: {
    method: "mollie-payment-method"
    metadata: {}
  }) {
   ...on Order {
     id
     state
     payments {
         id
         metadata
     }
   }
   ...on ErrorResult {
     errorCode
     message
   }
  }
}

The response will have a order.payments.metadata.public.redirectLink in it, which can be used to redirect your customer to the Mollie platform.

After completing payment on the Mollie platform, the user is redirected to the configured redirect url + orderCode: https://storefront/order/CH234X5

Local development

Use something like localtunnel to test on localhost.

npx localtunnel --port 3000 --subdomain my-shop-local-dev
> your url is: https://my-shop-local-dev.loca.lt     <- use this as the vendureHost for local dev.

Signature

class MolliePlugin {
  static static options: MolliePluginOptions;
  static init(options: MolliePluginOptions) => typeof MolliePlugin;
}

Members

options

static property

init

static method
type:
(options: MolliePluginOptions) => typeof MolliePlugin
Initialize the mollie payment plugin

MolliePluginOptions

Configuration options for the Mollie payments plugin.

Signature

interface MolliePluginOptions {
  vendureHost: string;
}

Members

vendureHost

property
type:
string
The host of your storefront application, e.g. 'https://my-shop.com'