mpValidate

The mpValidate service is called by the merchant when the consumer returns from the MP site. It verifies the consumer’s request and fetches the card data for the consumer’s chosen payment method. In some cases it also retrieves the shipping address.

The endpoint for the JSON service:

https://api.dibspayment.com/merchant/v1/JSON/Transaction/mpValidate

Input parameters

Parameter Type Description
merchantId * Strin, max 36 letters Integration ID from DIBS Admin 2.0.
walletSessionId * String Id of the existing walled card session returned by the mpInit service.
oAuthVerifier * String An authorization checksum from Masterpass
checkoutResourceUrl * String (URL) An endpoint URL for the Masterpass checkout service.
MAC * String, 64 letters This parameter contains a Message Authentication Code.

*: Always validated by DIBS

Output parameters

Parameter Type Description
cardBrandId String The <BrandId> from the MP checkout resource, e.g. “MC”.
cardBrandName String The <BrandName> from the MP checkout resource, e.g. “MasterCard”. Returned if status = ACCEPTED.
declineReason String Reason for decline or error (Masterpass internal message, if presented, or default satellite error message), null for ACCEPTED status.
maskedCardNumber String A masked card number based on the <AccountNumber>  from the MP checkout resource, e.g. “****-­?****-­?****-­?1234”. It is intended for display to the consumer prior to a final acceptance of the payment.
shippingAddress SimpleContactInfo An optional shipping address. It will only be present if the consumer picked a shipping address during checkout.
status [ACCEPTED, ERROR]  Status of the call. ACCEPTED means that request was processed and the Masterpass information is returned.

 

Code examples

/**
 * Dependencies:
 * Apache-Commons/Commons-Codec for Hex encoding/decoding
 * Codehaus/Jackson for JSON mapping
 */
/**
 * postToDIBS Sends a post to the specified DIBS function
 *
 * @param parameters A Map<String, String> holding the parameters to be parsed to DIBS
 * @param func A String holding the name of the function to be used
 * @return A Map<String, String> holding the parameters returned by DIBS
 */
public Map<String, String> postToDIBS(Map<String, String> parameters, String func) {
  try {
    //Set the endpoint for the chosen function
        String endpoint = null;
        if (func.equals("AuthorizeCard")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/AuthorizeCard";
        } else if (func.equals("AuthorizeTicket")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/AuthorizeTicket";
        } else if (func.equals("CancelTransaction")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/CancelTransaction";
        } else if (func.equals("CaptureTransaction")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/CaptureTransaction";
        } else if (func.equals("CreateTicket")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/CreateTicket";
        } else if (func.equals("RefundTransaction")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/RefundTransaction";
        } else if (func.equals("Ping")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/Ping";
        } else if (func.equals("mpInit")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/mpInit";
        } else if (func.equals("mpValidate")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/mpValidate";
        } else if (func.equals("mpAuthorize")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/mpAuthorize";
        } else if (func.equals("calcFee")) {
            endpoint = "https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/calcFee";
        else {
            System.out.println("Error in postToDIBS(): Given function does not exist");
            return null;
        }

    // Set properties for connection.
    // Connection is not initialized until parameters are posted
    URL url = new URL(endpoint);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    // Initiate output stream for connection and post message
    OutputStream out = connection.getOutputStream();
    out.write("request=".getBytes(Charset.forName("UTF-8")));
    ObjectMapper objectMapper = new ObjectMapper(); // ObjectMapper from the Jackson library
    objectMapper.writeValue(out, parameters);
    out.flush();
    out.close();

    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
      // OK
      @SuppressWarnings("unchecked")
      Map<String, String> response = objectMapper.readValue(connection.getInputStream(), Map.class);
      return response;
    } else {
      // Server returned HTTP error code.
      System.out.println("HTTP error!" + connection.getResponseCode());
      return null;
    }
  } catch (MalformedURLException e) {
    e.printStackTrace();

  } catch (IOException e) {
    e.printStackTrace();
  }
  return parameters;
}
/**
 * Dependencies:
 * Apache-Commons/Commons-Codec for Hex encoding/decoding
 * Codehaus/Jackson for JSON mapping
 */
/**
 * MasterpassFlow initialization. Starts a new Masterpass session using Masterpass JSON services.
 *
 * @param amount The amount of the purchase in smallest unit
 * @param currency The currency either in numeric or string format (e.g. 208/DKK)
 * @param merchantId DIBS Merchant ID / customer number
 * @param slp shipping localiton id parameter
 * @param macKeyHex The secret HMAC key from DIBS Admin
 */
public void MasterpassFlow_mpInit(int amount, String currency, String merchantId, String slp, boolean suppressShippingAddress,
        boolean addFee, boolean isTest, String macKeyHex) {

        // Create JSON object and add parameters
        Map<String, String> parameters = new HashMap();
        parameters.put("amount", String.valueOf(amount));
        parameters.put("currency", currency);
        parameters.put("merchantId", merchantId);
        parameters.put("shippingAddress", getShippingAddressJsonString());
        parameters.put("shippingLocationProfile", slp);
        parameters.put("cartContent", getCartContentList());
        parameters.put("suppressShippingAddress", suppressShippingAddress);
        parameters.put("acceptableCards", "visa,master");
        parameters.put("addFee", addFee);
        parameters.put("test", isTest);

        parameters.put("consumerEmail", "merchantsMail@mail.dk");
        parameters.put("consumerPhone", "112233445566");

        // Add MAC value for request
        parameters.put("MAC", calculateMac(parameters, macKeyHex));

        // Post to the DIBS system and receive response
        Map<String, String> resp = postToDIBS(parameters, "mpInit");

        if (resp.get("status").equals("ACCEPT")) {
        // Initialization accepted. Check resp.get("redirectUrl") to redirect customer to.
        // Save value of resp.get("walletSessionId") to link future actions to current session data (shipping address, cart content etc.)
        // ...
        System.out.println("MpInit accepted. Response:");
        System.out.println(resp.toString());
        } else if (resp.get("status").equals("DECLINE")) {
        // Initialization declined. Check resp.get("declineReason") for more information
        // ...
        System.out.println("MpInit declined. Response:");
        System.out.println(resp.toString());
        } else {
        // An error happened. Check Check resp.get("declineReason") for more information
        // ...
        System.out.println("An error happened during initialization. Response:");
        System.out.println(resp.toString());
        }
}

/**
 * MasterpassFlow validation. Validates and checks out customers data from Masterpass side for existed session.
 *
 * @param merchantId DIBS Merchant ID / customer number
 * @param walletSessionId Valid Masterpass session token.
 * @param oAuthVerifier An authorization checksum from Masterpass request.
 * @param checkoutResourceUrl An endpoint URL for the Masterpass checkout service.
 * @param macKeyHex The secret HMAC key from DIBS Admin
 */
public void MasterpassFlow_mpValidate(String walletSessionId, String merchantId, String oAuthVerifier, String checkoutResourceUrl, String macKeyHex) {

        // Create JSON object and add parameters
        Map<String, String> parameters = new HashMap();
        parameters.put("merchantId", merchantId);
        parameters.put("walletSessionId", walletSessionId);

        // These values supposed to be returned from Masterpass directly.
        parameters.put("oAuthVerifier", oAuthVerifier);
        parameters.put("checkoutResourceUrl", checkoutResourceUrl);

        parameters.put("MAC", calculateMac(parameters, macKeyHex));

        // Post to the DIBS system and receive response
        Map<String, String> resp = postToDIBS(parameters, "mpValidate");

        if (resp.get("status").equals("ACCEPT")) {
        // Validation accepted. Check resp.get("cardBrandId"), resp.get("cardBrandName") and resp.get("maskedCardNumber") for payment's data.
        // Check  resp.get("shippingAddress") for shipping detailes.
        // Check  resp.get("consumerPhone"), resp.get("consumerEmail") for contact detailes.
        // ...
        System.out.println("MpValidate accepted. Response:");
        System.out.println(resp.toString());
        } else if (resp.get("status").equals("DECLINE")) {
        // Validation declined. Check resp.get("declineReason") for more information
        // ...
        System.out.println("MpValidate declined. Response:");
        System.out.println(resp.toString());
        } else {
        // An error happened. Check Check resp.get("declineReason") for more information
        // ...
        System.out.println("An error happened during validation. Response:");
        System.out.println(resp.toString());
        }
}

/**
 * MasterpassFlow fee calculation. Calculates fee for authorizing payment amount.
 *
 * @param merchantId DIBS Merchant ID / customer number
 * @param walletSessionId Valid Masterpass session token.
 * @param amount The future authorizing amount of the purchase (for e.g. initial amount with extra shipping fee) in smallest unit.
 * @param macKeyHex The secret HMAC key from DIBS Admin
 */
public void MasterpassFlow_calcFee(String walletSessionId, String merchantId, int amount, String macKeyHex) {

        // Create JSON object and add parameters
        Map<String, String> parameters = new HashMap();
        parameters.put("merchantId", merchantId);
        parameters.put("walletSessionId", walletSessionId);
        parameters.put("amount", String.valueOf(amount));

        parameters.put("MAC", calculateMac(parameters, macKeyHex));

        // Post to the DIBS system and receive response
        Map<String, String> resp = postToDIBS(parameters, "calcFee");

        if (resp.get("status").equals("ACCEPT")) {
        // Fee calculated. Check resp.get("amount") for the value.
        } else if (resp.get("status").equals("ERROR")) {
        // An error happened. Check Check resp.get("declineReason") for more information
        // ...
        System.out.println("An error happened during fee calculation. Response:");
        System.out.println(resp.toString());
        }
}

/**
 * MasterpassFlow validation. Validates and checks out customers data from Masterpass side for existed session.
 *
 * @param merchantId DIBS Merchant ID / customer number
 * @param walletSessionId Valid Masterpass session token.
 * @param oAuthVerifier An authorization checksum from Masterpass request.
 * @param checkoutResourceUrl An endpoint URL for the Masterpass checkout service.
 * @param macKeyHex The secret HMAC key from DIBS Admin
 */
public void MasterpassFlow_mpAuthorize(String walletSessionId, String merchantId, int amount, String orderId, String clientIp, String macKeyHex) {

        // Create JSON object and add parameters
        Map<String, String> parameters = new HashMap();
        parameters.put("merchantId", merchantId);
        parameters.put("walletSessionId", walletSessionId);
        parameters.put("amount", String.valueOf(amount));
        parameters.put("orderId", orderId);
        parameters.put("clientIp", clientIp);

        parameters.put("MAC", calculateMac(parameters, macKeyHex));

        // Post to the DIBS system and receive response
        Map<String, String> resp = postToDIBS(parameters, "mpAuthorize");

        if (resp.get("status").equals("ACCEPT")) {
        // Authorization accepted. Check resp.get("transactionId") for transaction ID.
        // resp.get("acquirer") will contain short name of acquirer, that has processed payment.
        // ...
        System.out.println("MpAuthorize accepted. Response:");
        System.out.println(resp.toString());
        } else if (resp.get("status").equals("DECLINE")) {
        // Validation declined. Check resp.get("declineReason") for more information
        // ...
        System.out.println("MpAuthorize declined. Response:");
        System.out.println(resp.toString());
        } else {
        // An error happened. Check Check resp.get("declineReason") for more information
        // ...
        System.out.println("An error happened during authorization. Response:");
        System.out.println(resp.toString());
        }
}


private static List getCartContentList() {
        List<Map<String, String>> cartContent = new ArrayList<>();
        Map item = new HashMap();
        item.put("quantity", "2");
        item.put("unitOfMeasure", "psc");
        item.put("description", "Goods description");
        item.put("amount", "100");
        item.put("vatAmount", "100");
        item.put("productId", "123abc");
        item.put("imageUrl", "http://example.dibs.dk/picture.jpg");
        cartContent.add(item);
        return cartContent;
}

private static String getShippingAddressJsonString() {
        Map parameters = new HashMap();
        parameters.put("firstName", "Tony");
        parameters.put("lastName", "Anonymousen");
        parameters.put("address", "home1");
        parameters.put("address2", "home2");
        parameters.put("postalCode", "7777");
        parameters.put("postalPlace", "Lilleby");
        parameters.put("country", "Denmark");
        parameters.put("email", "customerEmail");
        parameters.put("phone", "customerPhone");
        return parameters.toString();
}
<form method="post" action="https://v2.api.dibspayment.com/merchant/v1/JSON/Transaction/mpValidate">
    <input name="request" value='{
    "merchantId":"12345678",
    "walletSessionId":"efc11c0920e52b005ec42e886589e0ef0d7e770c",
    "oAuthVerifier":"9271539cb33be3e80d61c0ab9e721ce575fe73f0",
    "checkoutResourceUrl":"https://sandbox.api.mastercard.com/online/v5/checkout/311411728",
    "MAC":"0c76b7b92f2e40432f51f72a2ea3cc569f86735019a3de75e0e2c6f87c79b0bf"}' type="hidden" />
  <input type="submit">
</form>
Do you have a question or need help?
Follow us
DIBS Payment Services
Stockholm +46 (0)8-527 525 00
Göteborg +46 031-600 800
København +45 7020 3077
Oslo +47 21 55 44 00