mpAuthorize

The service performs an authorization for the card data that was approved by the customer and was fetched using the mpValidate service.

The endpoint for the JSON service:

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

Input parameters

Parameter Type Description
merchantId * String, max 36 letters Integration ID from DIBS Admin 2.0.
amount * Integer Amount to authorize in smallest units (eg 100 for 1 EUR) (should include all merchant's additional fees).
clientIp * String, max 39 chars The customers ip address
MAC * String, 64 chars Message Authentication Code. See HMAC Calculation for more information.
merchantId * String, max 36 chars Merchant identification number
orderId * String, max 50 chars The shop’s order number for this particular puchase. It can be seen later when payment is captured, and will in some instances appear on the customer's bank statement (both numerals and letters may be used).
walletSessionId * String Id of the existed wallet card session

*: Always validated by DIBS

Return parameters

ParameterTypeDescription
acquirerString, max 36 charsThe acquirer used for the specific transaction. Only returned for status = ACCEPTED
declineReasonString, max 140 charsreason for decline or failure of the authorization. Will not be returned for successful calls.
status[ACCEPTED, DECLINED, ERROR]Status of the call
transactionIdString, max 36 charsThe ID of the transaction is returned if status is ACCEPTED.

 

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/mpAuthorize">
    <input name="request" value='{
    "merchantId":"12345678",
    "walletSessionId":"efc11c0920e52b005ec42e886589e0ef0d7e770c",
    "amount":"375",
    "orderId":"1441811229307",
    "clientIp":"127.0.0.1",
    "MAC":"a2eaece17672428863b9e5962d9b2a413f3e8d392c5b6b8d13cb8faa45aafe10"}' 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