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.
The easiest way to install the Mollie Api library is to use the Nuget Package.
Install-Package Mollie.Api
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.
This library currently supports the following API's:
- Payments API
- Customers API
- Mandates API
- Subscriptions API
The MollieClient object allows you to send and receive requests to the Mollie REST webservice.
MollieClient mollieClient = new MollieClient("{your_api_key}");
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
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
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;
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
}
PaymentMethodResponse paymentMethodResponse = this._mollieClient.GetPaymentMethodAsync(paymentMethod).Result;
ListResponse<IssuerResponse> issuerList = this._mollieClient.GetIssuerListAsync().Result;
foreach (IssuerResponse issuer in issuerList.Data) {
// Your code here
}
this._mollieClient.GetIssuerAsync(issuerId).Result;
RefundResponse refundResponse = this._mollieClient.CreateRefund(payment.Id).Result;
RefundRequest refundRequest = new RefundRequest() {
Amount = 50
};
RefundResponse refundResponse = this._mollieClient.CreateRefund(payment.Id, refundRequest).Result;
RefundResponse refundResponse = this._mollieClient.GetRefund(payment.Id, refundResponse.Id).Result;
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;
this._mollieClient.CancelRefund(paymentId, refundId);