Giter VIP home page Giter VIP logo

mollieapi.net's Introduction

Mollie API client for ASP.NET

Accepting iDEAL, Apple Pay, Bancontact, SOFORT Banking, Creditcard, SEPA Bank transfer, SEPA Direct debit, PayPal, Belfius Direct Net, KBC/CBC, paysafecard, ING Home'Pay, Giftcards, Giropay, EPS and Przelewy24 online payments without fixed monthly costs or any punishing registration procedures. Just use the Mollie API to receive payments directly on your website or easily refund transactions to your customers.

Build and Test Nuget Nuget

Requirements

To use the Mollie API client, the following things are required:

  • Get yourself a free Mollie account. No sign up costs.
  • Now you're ready to use the Mollie API client in test mode.
  • Follow a few steps to enable payment methods in live mode, and let us handle the rest.

Nuget Installation

By far the easiest way to install the Mollie API client is to use the Nuget Package.

Install-Package MollieApi

The version of the API client corresponds to the version of the API it implements.

How to receive payments

To successfully receive a payment, these steps should be implemented:

  1. Use the Mollie API client to create a payment with the requested amount, currency, description and optionally, a payment method. It is important to specify a unique redirect URL where the customer is supposed to return to after the payment is completed.

  2. Immediately after the payment is completed, the platform will send an asynchronous request to the configured webhook to allow the payment details to be retrieved, so you know when exactly to start processing the customer's order.

  3. The customer returns, and should be satisfied to see that the order was paid and is now being processed.

Find the full documentation online on docs.mollie.com.

Getting started

Initializing the Mollie API client, and setting your API key.

var mollie = new MollieApiClient();
mollie.SetApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");

Creating a new payment.

var payment = await mollie.Payments.Create(new Payment
{
	Amount = new Amount
	{
		Currency = "EUR",
		Value = "10.00"
	},
	Description = "My first API payment",
	RedirectUrl = new Uri("https://webshop.example.org/order/12345/"),
	WebhookUrl = new Uri("https://webshop.example.org/mollie-webhook/")
});

After creation, the payment id is available in the payment.Id property. You should store this id with your order.

After storing the payment id you can send the customer to the checkout using the payment.GetCheckoutUrl().

Response.Redirect(payment.GetCheckoutUrl(), true);

Retrieving payments

We can use the payment.Id to retrieve a payment and check if the payment IsPaid.

var payment = await mollie.Payments.Get(payment.Id);
if (payment.IsPaid())
{
	Console.WriteLine("Payment received.");
}

Or retrieve a collection of payments.

var payments = mollie.Payments.Page(); 

Payment webhook

When the status of a payment changes the WebhookUrl we specified in the creation of the payment will be called.
There we can use the id from the POST parameters to check te status and act upon that.

Multicurrency

Since 2.0 it is now possible to create non-EUR payments for your customers. A full list of available currencies can be found in the documentation.

var payment = await mollie.Payments.Create(new Payment
{
	Amount = new Amount
	{
		Currency = "USD",
		Value = "10.00"
	},
	Description = "Order #12345",
	RedirectUrl = new Uri("https://webshop.example.org/order/12345/"),
	WebhookUrl = new Uri("https://webshop.example.org/mollie-webhook/")
});

After creation, the SettlementAmount will contain the EUR amount that will be settled on your account.

Fully integrated iDEAL payments

If you want to fully integrate iDEAL payments in your web site, some additional steps are required. First, you need to retrieve the list of issuers (banks) that support iDEAL and have your customer pick the issuer he/she wants to use for the payment.

Retrieve the iDEAL method and include the issuers

var parameters = new Dictionary<string, string>
{
	{ "include", "issuers" }
};
var method = await mollie.Methods.Get(PaymentMethod.IDEAL, parameters);

method.Issuers will be a list of objects. Use the property Id of this object in the API call, and the property Name for displaying the issuer to your customer.

Create a payment with the selected issuer:

var payment = await mollie.Payments.Create(new Payment
{
	Amount = new Amount
	{
		Currency = "EUR",
		Value = "10.00"
	},
	Description = "My first API payment",
	RedirectUrl = new Uri("https://webshop.example.org/order/12345/"),
	WebhookUrl = new Uri("https://webshop.example.org/mollie-webhook/"),
	Method = PaymentMethod.IDEAL,
	Issuer = "ideal_INGBNL2A"
});

The Links property of the payment object will contain an object Checkout with a Href property, which is a URL that points directly to the online banking environment of the selected issuer. A short way of retrieving this URL can be achieved by using the payment.GetCheckoutUrl().

Refunding payments

The API also supports refunding payments. Note that there is no confirmation and that all refunds are immediate and definitive. Refunds are supported for all methods except for paysafecard and gift cards.

var payment = await mollie.Payments.Get(payment.Id);

// Refund € 2 of this payment
var refund = await mollie.PaymentRefunds.CreateFor(payment, new Refund
{
	Amount = new Amount
	{
		Currency = "EUR",
		Value = "2.00"
	}
});

API documentation

If you wish to learn more about the API, please visit the Mollie Developer Portal. API Documentation is available in English.

Want to help make the API client even better?

Want to help make the API client even better? Create a pull request.

License

MIT (Massachusetts Institute of Technology) License. Copyright (c) 2020, Rob Janssen

mollieapi.net's People

Stargazers

Albert Vos avatar Jan van Overbeek avatar

Watchers

James Cloos avatar Rob Janssen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.