Skip to content

Latest commit

 

History

History
134 lines (111 loc) · 5.12 KB

README.md

File metadata and controls

134 lines (111 loc) · 5.12 KB

MollieApi

This project allows you to easily add the Mollie payment provider to your application. Mollie has excellent documentation which I highly recommend you read before using this library. Please keep in mind that this is a 3rd party library and I am in no way associated with Mollie.

If you have encounter any issues while using this library or have any feature requests, feel free to open an issue on GitHub.

Getting started

Installing the library

The easiest way to install the Mollie Api library is to use the Nuget Package.

Install-Package Mollie.Api

Example projects

Two example projects are included. A simple console application and a web application that allows you to view, create, pay and refund payments. In order to use these projects you have to set your Mollie API key in the Program.cs/web.config file.

Supported API's

This library currently supports the following API's:

  • Payments API
  • Customers API
  • Mandates API
  • Subscriptions API

Creating a MollieClient object

The MollieClient object allows you to send and receive requests to the Mollie REST webservice.

MollieClient mollieClient = new MollieClient("{your_api_key}");

Payments

Creating a payment

PaymentRequest paymentRequest = new PaymentRequest() {
    Amount = 100,
    Description = "Test payment of the example project",
    RedirectUrl = "http://google.com"
};

PaymentResponse paymentResponse = mollieClient.CreatePaymentAsync(paymentRequest).Result;

If you want to create a payment with a specific paymentmethod, there are seperate classes that allow you to set paymentmethod specific parameters. For example, a bank transfer payment allows you to set the billing e-mail and due date. Have a look at the Mollie create payment documentation for more information.

The full list of payment specific request classes is:

  • BankTransferPaymentRequest
  • CreditCardPaymentRequest
  • IDealPaymentRequest
  • PayPalPaymentRequest
  • SepaDirectDebitRequest

Retrieving a payment by id

PaymentResponse result = this._mollieClient.GetPaymentAsync(paymentResponse.Id).Result;

Keep in mind that some payment methods have specific payment detail values. For example: PayPal payments have reference and customer reference properties. In order to access these properties you have to cast the PaymentResponse to the PayPalPaymentResponse and access the Detail property.

Take a look at the Mollie payment response documentation for a full list of payment methods that have extra detail fields.

The full list of payment specific response classes is:

  • BankTransferPaymentResponse
  • BitcoinPaymentResponse
  • CreditCardPaymentResponse
  • IdealPaymentResponse
  • MisterCashPaymentResponse
  • PayPalPaymentResponse
  • PaySafeCardPaymentResponse
  • PodiumCadeauKaartPaymentResponse
  • SofortPaymentResponse
  • BelfiusPaymentResponse

Retrieving a list off payments

Mollie allows you to set offset and count properties so you can paginate the list. The offset and count parameters are optional. The maximum number of payments you can request in a single roundtrip is 250.

ListResponse<PaymentResponse> response = this._mollieClient.GetPaymentListAsync(offset, count).Result;

Payment methods

Retrieving a list of all payment methods

Mollie allows you to set offset and count properties so you can paginate the list. The offset and count parameters are optional.

ListResponse<PaymentMethodResponse> paymentMethodList = this._mollieClient.GetPaymentMethodListAsync(offset, count).Result;
foreach (PaymentMethodResponse paymentMethod in paymentMethodList.Data) {
  // Your code here
}

Retrieving a single payment method

PaymentMethodResponse paymentMethodResponse = this._mollieClient.GetPaymentMethodAsync(paymentMethod).Result;

Issuer methods

Retrieve issuer list

ListResponse<IssuerResponse> issuerList = this._mollieClient.GetIssuerListAsync().Result;
foreach (IssuerResponse issuer in issuerList.Data) {
    // Your code here
}

Retrieve a single issuer by id

this._mollieClient.GetIssuerAsync(issuerId).Result;

Refund methods

Create a new refund

RefundResponse refundResponse = this._mollieClient.CreateRefund(payment.Id).Result;

Create a partial refund

RefundRequest refundRequest = new RefundRequest() {
    Amount = 50
};
RefundResponse refundResponse = this._mollieClient.CreateRefund(payment.Id, refundRequest).Result;

Retrieve a refund by payment and refund id

RefundResponse refundResponse = this._mollieClient.GetRefund(payment.Id, refundResponse.Id).Result;

Retrieve refund list

Mollie allows you to set offset and count properties so you can paginate the list. The offset and count parameters are optional.

ListResponse<RefundResponse> refundList = this._mollieClient.GetRefundList(payment.Id, offset, count).Result;

Cancel a refund

this._mollieClient.CancelRefund(paymentId, refundId);