Skip to content

08. Order API

Vincent Kok edited this page Jun 7, 2024 · 3 revisions

The Orders API allows you to use Mollie for your order management. Pay after delivery payment methods, such as Klarna Pay later and Klarna Slice it require the Orders API and cannot be used with the Payments API.

Creating a new order

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderRequest orderRequest = new OrderRequest() {
	Amount = new Amount(Currency.EUR, 100.00m),
	OrderNumber = "16738",
	Lines = new List<OrderLineRequest>() {
		new OrderLineRequest() {
			Name = "A box of chocolates",
			Quantity = 1,
			UnitPrice = new Amount(Currency.EUR, 100.00m),
			TotalAmount = new Amount(Currency.EUR, 100.00m),
			VatRate = "21.00",
			VatAmount = new Amount(Currency.EUR, "17.36")
		}
	},
	BillingAddress = new OrderAddressDetails() {
		GivenName = "John",
		FamilyName = "Smit",
		Email = "[email protected]",
		City = "Rotterdam",
		Country = "NL",
		PostalCode = "0000AA",
		Region = "Zuid-Holland",
		StreetAndNumber = "Coolsingel 1"
	},
	RedirectUrl = "http://www.google.nl",
	Locale = Locale.nl_NL
};

OrderResponse result = await orderClient.CreateOrderAsync(orderRequest);

If you want to create a order with a specific payment parameters you can provide a specific payment implementation. For example, a bank transfer payment allows you to set the billing e-mail and due date. Have a look at the Mollie payment specific parameters for more information.

The full list of payment specific parameters classes is:

  • ApplePaySpecificParameters
  • BillieSpecificParameters
  • CreditCardSpecificParameters
  • GiftcardSpecificParameters
  • IDealSpecificParameters
  • KbcSpecificParameters
  • KlarnaSpecificParameters
  • PaySafeCardSpecificParameters
  • SepaDirectDebitSpecificParameters

For example, if you'd want to create a order with bank transfer payment:

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderRequest orderRequest = new OrderRequest() {
	Amount = new Amount(Currency.EUR, 100.00m),
	OrderNumber = "16738",
	Method = PaymentMethod.BankTransfer,
	Payment = new BankTransferSpecificParameters {
		BillingEmail = "[email protected]"
	},
	Lines = new List<OrderLineRequest>() {
		new OrderLineRequest() {
			Name = "A box of chocolates",
			Quantity = 1,
			UnitPrice = new Amount(Currency.EUR, 100.00m),
			TotalAmount = new Amount(Currency.EUR, 100.00m),
			VatRate = "21.00",
			VatAmount = new Amount(Currency.EUR, "17.36")
		}
	},
	BillingAddress = new OrderAddressDetails() {
		GivenName = "John",
		FamilyName = "Smit",
		Email = "[email protected]",
		City = "Rotterdam",
		Country = "NL",
		PostalCode = "0000AA",
		Region = "Zuid-Holland",
		StreetAndNumber = "Coolsingel 1"
	},
	RedirectUrl = "http://www.google.nl",
	Locale = Locale.nl_NL
};

Passing multiple payment methods

It is also possible to pass multiple payment methods when creating a new order. Mollie will then only show the payment methods you've specified when creating the payment request.

OrderRequest orderRequest = new OrderRequest() {
	Amount = new Amount(Currency.EUR, 100.00m),
	OrderNumber = "16738",
	Methods = new List<string>() {
		PaymentMethod.Ideal,
		PaymentMethod.CreditCard,
		PaymentMethod.DirectDebit
	}
	...

Retrieve a order by id

Retrieve a single order by its ID.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderResponse retrievedOrder = await orderClient.GetOrderAsync({orderId});

Update existing order

This endpoint can be used to update the billing and/or shipping address of an order.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderUpdateRequest orderUpdateRequest = new OrderUpdateRequest() {
	OrderNumber = "1337" 
};
OrderResponse updatedOrder = await orderClient.UpdateOrderAsync({orderId}, orderUpdateRequest);

Update order line

This endpoint can be used to update an order line. Only the lines that belong to an order with status created, pending or authorized can be updated.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderLineUpdateRequest updateRequest = new OrderLineUpdateRequest() {
	Name = "A fluffy bear"
};
OrderResponse updatedOrder = await orderClient.UpdateOrderLinesAsync({orderId}, createdOrder.Lines.First().Id, updateRequest);

Manage order lines

Use this endpoint to update, cancel, or add one or more order lines. This endpoint sends a single authorisation request that contains the final order lines and amount to the supplier.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
ManageOrderLinesRequest manageOrderLinesRequest = new ManageOrderLinesRequest() {
	Operations = new List<ManageOrderLinesOperation> {
		new ManageOrderLinesAddOperation() {
			Data = new ManageOrderLinesAddOperationData {
				Name = "new-order-line",
				// Other properties of order line to add
			}
		},
		new ManageOrderLinesUpdateOperation {
			Data = new ManageOrderLinesUpdateOperationData {
				Id = "{yourOrderLineIdToUpdate}",
				Name = "updated-name"
				// ... Other properties you'd like to update
			}
		},
		new ManageOrderLinesCancelOperation {
			Data = new ManagerOrderLinesCancelOperationData {
				Id = "{yourOrderLineIdToCancel}",
				Quantity = 1
			}
		}
	}
};
OrderResponse updatedOrder = await this._orderClient.ManageOrderLinesAsync(createdOrder.Id, manageOrderLinesRequest);

Retrieve list of orders

Retrieve all orders.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
ListResponse<OrderResponse> response = await orderClient.GetOrderListAsync();

It is also possible to specify the sort direction when querying the list of orders. This allows you to paginate the list of orders in ascending or descending order.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
ListResponse<OrderResponse> response = await _orderClient.GetOrderListAsync(from: "order-id", sort: SortDirection.Asc);

Cancel existing order

Cancels an existing order. Take a look at the documentation on this endpoint to see which conditions need to apply before an order can be canceled.

using IOrderClient orderClient = new OrderClient("{yourApiKey}");
 OrderResponse canceledOrder = await orderClient.GetOrderAsync({orderId});

Cancel order lines

This endpoint can be used to cancel one or more order lines that were previously authorized using a pay after delivery payment method. Use the Cancel Order API if you want to cancel the entire order or the remainder of the order.

OrderLineCancellationRequest cancellationRequest = new OrderLineCancellationRequest() {
	Lines = new List<OrderLineDetails>() {
		Id = {orderLineId},
		Quantity = 5,
		Amount = new Amount("EUR", 5)
	}
};
using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderResponse result = await orderClient.CancelOrderLinesAsync({orderId}, cancellationRequest);

Create order payment

An order has an automatically created payment that your customer can use to pay for the order. When the payment expires you can create a new payment for the order using this endpoint.

OrderPaymentRequest orderPaymentRequest = new OrderPaymentRequest() {
	Method = PaymentMethod.Ideal,
	CustomerId = {customerId},
	MandateId = {mandateId}
};
using IOrderClient orderClient = new OrderClient("{yourApiKey}");
OrderResponse result = await orderClient.CreateOrderPaymentAsync({orderId}, orderPaymentRequest);