Introduction
Using these API functions, you can interact with the MplusKASSA order workflow.
Whenever you create an order externally, you have to supply an external order identifier (
extOrderId). You can use this identifier to find the order again.
External order identifiers are unique and therefore cannot be reused.
Notice: Orders are different from table orders, an order can not be changes to a tabel order. Make sure you implement the correct one for your use case.
Contents
- getOrders Retrieve orders
- createOrder Creating a new order
- findOrder Getting an existing order by extOrderId
- getOrder Getting an existing order by orderId
- updateOrder Updating an existing order
- cancelOrder Cancelling an order
- payOrder Paying an order
- deliverOrder Delivering an order
- getDeliveryMethods Get a list of available delivery methods
- getOrderCategories Get a list of available order categories
getOrders Retrieving orders
When you want to synchronize orders from Mplus to another application, it is smart to make use of Sync Markers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. $syncMarker = get_internal_orders_syncmarker(); // this should be 0 the first time you synchronize // Then we call the getOrders() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($orders = $mplusqapiclient->getOrders($syncMarker))) { // Success, we show the number of retrieved orders. exit(sprintf('Retrieved %d orders.', count($orders))); } else { exit('Unable to retrieve orders.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
createOrder Creating a new order
When creating an order, you are always required to attach a relation.
See the relations tutorial to learn how to manage relations through the API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // First we create the array that will hold the new order's data. $order = array( 'extOrderId' => 'ORDER0001359', // any string is allowed, but must be unique 'entryBranchNumber' => 1, // branchNumber must be present in Mplus 'relationNumber' => 681, // relationNumber must be present in Mplus 'employeeNumber' => 999999, // employeeNumber must be present in Mplus 'reference' => 'Bestelling #1359', // an extra optional reference text 'orderCategoryNumber' => 0, // retrieve the available orderCategories through getOrderCategories 'deliveryMethod' => 'OPHALEN', // retrieve the available deliveryMethods through getDeliveryMethods 'deliveryAddress' => array( 'name' => 'Mplus Software', 'contact' => 'Jan de Boer', 'address' => 'Voorstreek 77', 'zipcode' => '8911JL', 'city' => 'Leeuwarden', 'country' => 'Nederland', ), 'invoiceAddress' => array( 'name' => 'Mplus Software', 'contact' => 'Jan de Boer', 'address' => 'Voorstreek 88', 'zipcode' => '8911JL', 'city' => 'Leeuwarden', 'country' => 'Nederland', ), // options are: // (1) VAT-METHOD-INCLUSIVE (VAT included) // (2) VAT-METHOD-EXCLUSIVE (VAT excluded) // (3) VAT-METHOD-SHIFTED (VAT shifted, for international business) 'vatMethod' => 'VAT-METHOD-EXCLUSIVE', 'lineList' => array( array( 'articleNumber' => 14, // articleNumber must be present in Mplus 'data' => array( 'quantity' => 1, 'price' => 1995, // prices are always in cents 'discountPercentage' => 15, // optional discountPercentage 'discountAmount' => 0, // optional discountAmount 'vatCode' => 2, // VAT code ), 'text' => 'Stropdas', ), array( 'articleNumber' => 999, // articleNumber must be present in Mplus 'data' => array( 'quantity' => 1, 'price' => 495, // prices are always in cents 'discountPercentage' => 0, // optional discountPercentage 'discountAmount' => 0, // optional discountAmount 'vatCode' => 2, // VAT code ), 'text' => 'Shipping costs', ), array( 'text' => 'tekstregel', ) ), ); // Then we call the createOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($order_result = $mplusqapiclient->createOrder($order))) { // Success, we show the new order's internal identifier. exit(sprintf('Created new order with id %s.', $order_result['orderId'])); } else { exit('Failure during order creation.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } |
Getting an existing order
There are two ways of retrieving an existing order. The first method is by searching for the external order identifier. The second method is by accessing the order with its internal order identifier.
findOrder Method one: Searching for external order identifier
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we call the findOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($order_result = $mplusqapiclient->findOrder('ORDER0001359'))) { // Success, we show the order's internal identifier. exit(sprintf('Found existing order with id %s.', $order_result['orderId'])); } else { exit('Unable to find order.'); }F } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
getOrder Method two: Getting order by its internal order identifier
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we call the getOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($order_result = $mplusqapiclient->getOrder('001a3cd43892405b9689134b36656063'))) { // Success, we show the order's internal identifier. exit(sprintf('Found existing order with id %s.', $order_result['orderId'])); } else { exit('Unable to find order.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
updateOrder Updating an existing order
Updating an existing order is very similar to creating a new order, except this time you also add the internal order identifier.
That means you must first get the internal order identifier, for example by storing it when you first created the order, or by looking for it using the findOrder() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // First we retrieve the current order details. if (false === ($order = $this--->getOrder('001a3cd43892405b9689134b36656063'))) { // You can also use findOrder and extOrderId exit('Order does not exist.'); } // Then we modify the order array with the updated data. In this case, we change the lineList to: $order['lineList'] => array( array( 'articleNumber' => 14, // articleNumber must be present in Mplus 'data' => array( 'quantity' => 1, 'price' => 1995, // prices are always in cents 'discountPercentage' => 15, // optional discountPercentage 'discountAmount' => 0, // optional discountAmount 'vatCode' => 2, // VAT code ), 'text' => 'Stropdas', ), array( 'articleNumber' => 16, // articleNumber must be present in Mplus 'data' => array( 'quantity' => 2, 'price' => 799, // prices are always in cents 'discountPercentage' => 0, // optional discountPercentage 'discountAmount' => 0, // optional discountAmount 'vatCode' => 2, // VAT code ), 'text' => 'Sokken', ), ); // Then we call the updateOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== $mplusqapiclient->updateOrder($order)) { // Success exit('Order successfully updated.'); } else { exit('Unable to update order.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } |
cancelOrder Cancelling an order
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we initialize some variables $orderId = '001a3cd43892405b9689134b36656063'; // This is the order we're cancelling // Then we call the cancelOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== $mplusqapiclient->cancelOrder($orderId)) { exit('Order successfully cancelled.'); } else { exit('Unable to cancel order.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
payOrder Paying an order
You can use the prepay parameter to signal if the order has been shipped already (false) or has not (true). If prepay is set to true, you will only make a deposit payment to the order, if prepay is set to false, you will also create a packing slip (signifying delivery) and invoice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we initialize some variables $orderId = '001a3cd43892405b9689134b36656063'; // This is the order we're making a payment on $prepay = true; // True means we are making a deposit to this order, False means we are creating an invoice. $payments = array( array( 'method' =--> 'K_WEBSHOP', // Must be defined in the Mplus database 'amount' => 1995, // Equivalent to 19,95 ), ); // Then we call the payOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== $mplusqapiclient->payOrder($orderId, $prepay, $payments)) { exit('Order successfully paid.'); } else { exit('Unable to pay order.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } |
Voor het gebruik van deze call dienen er financiƫle afspraken gemaakt te worden met MplusKASSA.
deliverOrder Delivering an order
Successfully delivering an order creates a packing slip for that order, which can later be invoiced. You can use this to signal that an order has been shipped, but not yet paid.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we initialize some variables $orderId = '001a3cd43892405b9689134b36656063'; // This is the order we're making a payment on // Then we call the deliverOrder() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== $mplusqapiclient->deliverOrder($orderId)) { exit('Order successfully delivered.'); } else { exit('Unable to deliver order.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
getDeliveryMethods Get a list of available delivery methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we call the getDeliveryMethods() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($deliveryMethods = $mplusqapiclient->getDeliveryMethods())) { exit(sprintf('%d delivery methods found.', count($deliveryMethods))); } else { exit('Unable to retrieve delivery methods.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |
getOrderCategories Get a list of available order categories
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!--?php require_once('Mplusqapiclient.php'); $mplusqapiclient = new Mplusqapiclient(); // Initialize the client with your details. // Then we call the getOrderCategories() function wrapped in a try/catch block to intercept any exceptions. try { if (false !== ($orderCategories = $mplusqapiclient->getOrderCategories())) { exit(sprintf('%d order categories found.', count($orderCategories))); } else { exit('Unable to retrieve order categories.'); } } catch (MplusQAPIException $e) { exit($e->getMessage()); } </pre--> |