示例#1
0
  @Override
  public void captureAuthAmount(PosTransaction transaction) throws Exception {
    String xml =
        StreamUtils.toString(
            MercuryPayProcessor.class.getResourceAsStream(
                "/com/mercurypay/ws/sdk/mercuryPreAuthCapture.xml")); //$NON-NLS-1$
    Ticket ticket = transaction.getTicket();

    // String merchantId = "118725340908147";
    String laneId = "01"; // $NON-NLS-1$
    String invoiceNo = String.valueOf(ticket.getId());
    String amount = String.valueOf(transaction.getAmount());

    xml = xml.replace($merchantId, CardConfig.getMerchantAccount());
    xml = xml.replace($laneId, laneId);
    xml = xml.replace($invoiceNo, invoiceNo);
    xml = xml.replace($refNo, invoiceNo);
    xml = xml.replace($amount, amount);
    xml = xml.replace($authorizeAmount, amount);
    xml = xml.replace("$gratuity", String.valueOf(transaction.getTipsAmount())); // $NON-NLS-1$
    xml = xml.replace("$recordNo", transaction.getCardTransactionId()); // $NON-NLS-1$
    xml = xml.replace("$authCode", transaction.getCardAuthCode()); // $NON-NLS-1$
    xml =
        xml.replace(
            "$AcqRefData", transaction.getProperty("AcqRefData")); // $NON-NLS-1$ //$NON-NLS-2$

    //		System.out.println(xml);

    MercuryWebRequest mpswr =
        new MercuryWebRequest("https://w1.mercurydev.net/ws/ws.asmx"); // $NON-NLS-1$
    mpswr.addParameter(
        "tran",
        xml); // Set WebServices 'tran' parameter to the XML transaction request //$NON-NLS-1$
    mpswr.addParameter(
        "pw", CardConfig.getMerchantPass()); // Set merchant's WebServices password //$NON-NLS-1$
    mpswr.setWebMethodName(
        "CreditTransaction"); // Set WebServices webmethod to selected type //$NON-NLS-1$
    mpswr.setTimeout(10); // Set request timeout to 10 seconds

    String mpsResponse = mpswr.sendRequest();

    MercuryResponse result = new MercuryResponse(mpsResponse);
    if (!result.isApproved()) {
      throw new PosException("Error authorizing transaction."); // $NON-NLS-1$
    }

    transaction.setCardTransactionId(result.getTransactionId());
    transaction.setCardAuthCode(result.getAuthCode());
  }
示例#2
0
  private String doPreAuth(Ticket ticket, String cardTrack, double amount)
      throws IOException, Exception {
    String xml =
        StreamUtils.toString(
            MercuryPayProcessor.class.getResourceAsStream(
                "/com/mercurypay/ws/sdk/mercuryAuth.xml")); //$NON-NLS-1$

    String[] strings = cardTrack.split("\\|"); // $NON-NLS-1$

    // String merchantId = "118725340908147";
    String laneId = "01"; // $NON-NLS-1$
    String tranCode = "PreAuth"; // $NON-NLS-1$
    String invoiceNo = String.valueOf(ticket.getId());
    String amountStrng = NumberUtil.formatNumber(amount);
    String encryptedBlock = strings[3];
    String encryptedKey = strings[9];

    xml = xml.replace($merchantId, CardConfig.getMerchantAccount());
    xml = xml.replace($laneId, laneId);
    xml = xml.replace($tranCode, tranCode);
    xml = xml.replace($invoiceNo, invoiceNo);
    xml = xml.replace($refNo, invoiceNo);
    xml = xml.replace($encryptedBlock, encryptedBlock);
    xml = xml.replace($encryptedKey, encryptedKey);
    xml = xml.replace($amount, amountStrng);
    xml = xml.replace($authorizeAmount, amountStrng);

    System.out.println(xml);

    MercuryWebRequest mpswr =
        new MercuryWebRequest("https://w1.mercurydev.net/ws/ws.asmx"); // $NON-NLS-1$
    mpswr.addParameter(
        "tran",
        xml); // Set WebServices 'tran' parameter to the XML transaction request //$NON-NLS-1$
    mpswr.addParameter(
        "pw", CardConfig.getMerchantPass()); // Set merchant's WebServices password //$NON-NLS-1$
    mpswr.setWebMethodName(
        "CreditTransaction"); // Set WebServices webmethod to selected type //$NON-NLS-1$
    mpswr.setTimeout(10); // Set request timeout to 10 seconds

    String mpsResponse = mpswr.sendRequest();
    return mpsResponse;
  }