@Test public void testGetHtmlForm() throws Exception { final Map<String, String> params = new HashMap<>(); params.put(AuthorizeNetSimPaymentGatewayImpl.AN_POST_URL, "http: params.put(AuthorizeNetSimPaymentGatewayImpl.AN_CANCEL_URL, "http: params.put(AuthorizeNetSimPaymentGatewayImpl.AN_RETURN_POLICY_URL, "http: params.put(AuthorizeNetSimPaymentGatewayImpl.AN_TEST_REQUEST, "FALSE"); params.put(AuthorizeNetSimPaymentGatewayImpl.AN_MD5_HASH_KEY, "Simon"); params.put(AuthorizeNetSimPaymentGatewayImpl.AN_API_LOGIN_ID, "login1"); params.put(AuthorizeNetSimPaymentGatewayImpl.AN_TRANSACTION_KEY, "key1"); final Fingerprint[] fingerprint = new Fingerprint[1]; final AuthorizeNetSimPaymentGatewayImpl gatewayImpl = new AuthorizeNetSimPaymentGatewayImpl() { @Override public String getParameterValue(String valueLabel) { if (params.containsKey(valueLabel)) { return params.get(valueLabel); } return ""; } @Override protected Fingerprint getFingerprint(final String orderReference, final String apiLoginId, final String txKey, final String amountString, final String currency) { if (fingerprint[0] == null) { fingerprint[0] = super.getFingerprint(orderReference, apiLoginId, txKey, amountString, currency); } return fingerprint[0]; } }; String htmlFormPart = gatewayImpl.getHtmlForm( "holder name", "en", BigDecimal.TEN.setScale(2), "USD", "234-1324-1324-1324sdf-sdf", createTestPayment(false) ); assertEquals("<input type='hidden' name='x_login' value='login1'>\n" + "<input type='hidden' name='x_fp_sequence' value='" + fingerprint[0].getSequence() + "'>\n" + "<input type='hidden' name='x_fp_timestamp' value='" + fingerprint[0].getTimeStamp() + "'>\n" + "<input type='hidden' name='x_fp_hash' value='" + fingerprint[0].getFingerprintHash() + "'>\n" + "<input type='hidden' name='x_version' value='3.1'>\n" + "<input type='hidden' name='x_method' value='CC'>\n" + "<input type='hidden' name='x_type' value='AUTH_CAPTURE'>\n" + "<input type='hidden' name='x_amount' value='10.00'>\n" + "<input type='hidden' name='x_currency_code' value='USD'>\n" + "<input type='hidden' name='x_show_form' value='payment_form'>\n" + "<input type='hidden' name='x_test_request' value='FALSE'>\n" + "<input type='hidden' name='x_line_item' value='code2<|>name2<|><|>1<|>10<|>0'>\n" + "<input type='hidden' name='x_cust_id' value='bob@doe.com'>\n" + "<input type='hidden' name='x_invoice_num' value='234132413241324sdfsd'>\n" + "<input type='hidden' name='x_po_num' value='234-1324-1324-1324sdf-sdf'>\n" + "<input type='hidden' name='x_description' value='code2 x 1, bob@doe.com, 1234'>\n" + "<input type='hidden' name='x_cancel_url' value='http: "<input type='hidden' name='x_return_policy_url' value='http: "<input type='hidden' name='orderGuid' value='234-1324-1324-1324sdf-sdf'>\n" + "<input type='hidden' name='x_return_policy_url' value='http: htmlFormPart); htmlFormPart = gatewayImpl.getHtmlForm( "holder name", "en", BigDecimal.TEN.setScale(2), "EUR", "234-1324-1324-1324abc-abc", createTestPayment(true) ); assertEquals("<input type='hidden' name='x_login' value='login1'>\n" + "<input type='hidden' name='x_fp_sequence' value='" + fingerprint[0].getSequence() + "'>\n" + "<input type='hidden' name='x_fp_timestamp' value='" + fingerprint[0].getTimeStamp() + "'>\n" + "<input type='hidden' name='x_fp_hash' value='" + fingerprint[0].getFingerprintHash() + "'>\n" + "<input type='hidden' name='x_version' value='3.1'>\n" + "<input type='hidden' name='x_method' value='CC'>\n" + "<input type='hidden' name='x_type' value='AUTH_CAPTURE'>\n" + "<input type='hidden' name='x_amount' value='10.00'>\n" + "<input type='hidden' name='x_currency_code' value='EUR'>\n" + "<input type='hidden' name='x_show_form' value='payment_form'>\n" + "<input type='hidden' name='x_test_request' value='FALSE'>\n" + "<input type='hidden' name='x_line_item' value='code2<|>name2<|><|>1<|>10<|>0'>\n" + "<input type='hidden' name='x_address' value='123, In the middle of'>\n" + "<input type='hidden' name='x_city' value='Nowhere'>\n" + "<input type='hidden' name='x_state' value='NA'>\n" + "<input type='hidden' name='x_zip' value='NA1 NA1'>\n" + "<input type='hidden' name='x_country' value='NA'>\n" + "<input type='hidden' name='x_phone' value='123412341234'>\n" + "<input type='hidden' name='x_email' value='bob@doe.com'>\n" + "<input type='hidden' name='x_cust_id' value='bob@doe.com'>\n" + "<input type='hidden' name='x_ship_to_address' value='324, In the middle of'>\n" + "<input type='hidden' name='x_ship_to_city' value='Nowhere'>\n" + "<input type='hidden' name='x_ship_to_state' value='NA'>\n" + "<input type='hidden' name='x_ship_to_zip' value='NA2 NA2'>\n" + "<input type='hidden' name='x_ship_to_country' value='NA'>\n" + "<input type='hidden' name='x_invoice_num' value='234132413241324abcab'>\n" + "<input type='hidden' name='x_po_num' value='234-1324-1324-1324abc-abc'>\n" + "<input type='hidden' name='x_description' value='code2 x 1, bob@doe.com, 1234'>\n" + "<input type='hidden' name='x_cancel_url' value='http: "<input type='hidden' name='x_return_policy_url' value='http: "<input type='hidden' name='orderGuid' value='234-1324-1324-1324abc-abc'>\n" + "<input type='hidden' name='x_return_policy_url' value='http: htmlFormPart); }
@Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { final String apiLoginId = getParameterValue(AN_API_LOGIN_ID); final String key = getParameterValue(AN_TRANSACTION_KEY); final String amountString = "" + amount; final Fingerprint fingerprint = getFingerprint(orderReference, apiLoginId, key, amountString, currencyCode); final long x_fp_sequence = fingerprint.getSequence(); final long x_fp_timestamp = fingerprint.getTimeStamp(); final String x_fp_hash = fingerprint.getFingerprintHash(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getHiddenField("x_login", apiLoginId)); stringBuilder.append(getHiddenField("x_fp_sequence", String.valueOf(x_fp_sequence))); stringBuilder.append(getHiddenField("x_fp_timestamp", String.valueOf(x_fp_timestamp))); stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash)); stringBuilder.append(getHiddenField("x_version", "3.1")); stringBuilder.append(getHiddenField("x_method", "CC")); stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE")); stringBuilder.append(getHiddenField("x_amount", amountString)); stringBuilder.append(getHiddenField("x_currency_code", currencyCode)); stringBuilder.append(getHiddenField("x_show_form", "payment_form")); setParameterIfNotNull(stringBuilder, "x_test_request", AN_TEST_REQUEST); if (CollectionUtils.isNotEmpty(payment.getOrderItems())) { for (final PaymentLine line : payment.getOrderItems()) { if (line.isShipment()) { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); setValueIfNotNull(stringBuilder, "x_freight", name + "<|>" + name + "<|>" + line.getUnitPrice().toPlainString()); } else { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); String code = line.getSkuCode().length() > ITEMSKU ? line.getSkuCode().substring(0, ITEMSKU - 1) + "~" : line.getSkuCode(); setValueIfNotNull(stringBuilder, "x_line_item", code + "<|>" + name + "<|><|>" + line.getQuantity().toPlainString() + "<|>" + line.getUnitPrice().toPlainString() + "<|>0"); } } } final PaymentAddress address = payment.getBillingAddress(); if (address != null) { setValueIfNotNull(stringBuilder, "x_first_name", address.getFirstname()); setValueIfNotNull(stringBuilder, "x_last_name", address.getLastname()); setValueIfNotNull(stringBuilder, "x_address", getAddressLines(address)); setValueIfNotNull(stringBuilder, "x_city", address.getCity()); setValueIfNotNull(stringBuilder, "x_state", address.getStateCode()); setValueIfNotNull(stringBuilder, "x_zip", address.getPostcode()); setValueIfNotNull(stringBuilder, "x_country", address.getCountryCode()); setValueIfNotNull(stringBuilder, "x_phone", address.getPhone1()); setValueIfNotNull(stringBuilder, "x_email", payment.getBillingEmail()); } stringBuilder.append(getHiddenField("x_cust_id", payment.getBillingEmail())); final PaymentAddress shipTo = payment.getShippingAddress(); if (shipTo != null) { setValueIfNotNull(stringBuilder, "x_ship_to_first_name", shipTo.getFirstname()); setValueIfNotNull(stringBuilder, "x_ship_to_last_name", shipTo.getLastname()); setValueIfNotNull(stringBuilder, "x_ship_to_address", getAddressLines(shipTo)); setValueIfNotNull(stringBuilder, "x_ship_to_city", shipTo.getCity()); setValueIfNotNull(stringBuilder, "x_ship_to_state", shipTo.getStateCode()); setValueIfNotNull(stringBuilder, "x_ship_to_zip", shipTo.getPostcode()); setValueIfNotNull(stringBuilder, "x_ship_to_country", shipTo.getCountryCode()); } stringBuilder.append(getHiddenField("x_invoice_num", StringUtils.substring(orderReference.replace("-", ""), 0, 20))); stringBuilder.append(getHiddenField("x_po_num", orderReference)); stringBuilder.append(getHiddenField("x_description", getDescription(payment))); final String relayUrl = getParameterValue(AN_RELAY_RESPONSE_URL); if (StringUtils.isNotBlank(relayUrl)) { stringBuilder.append(getHiddenField("x_relay_url", relayUrl)); stringBuilder.append(getHiddenField("x_relay_response", "TRUE")); } else { setParameterIfNotNull(stringBuilder, "x_receipt_link_url", AN_ORDER_RECEIPT_URL); } setParameterIfNotNull(stringBuilder, "x_cancel_url", AN_CANCEL_URL); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); stringBuilder.append(getHiddenField(ORDER_GUID, orderReference)); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); setParameterIfNotNull(stringBuilder, "x_header_html_payment_form", AN_STYLE_HEADER_HTML); setParameterIfNotNull(stringBuilder, "x_header2_html_payment_form", AN_STYLE_HEADER2_HTML); setParameterIfNotNull(stringBuilder, "x_footer_html_payment_form", AN_STYLE_FOOTER_HTML); setParameterIfNotNull(stringBuilder, "x_footer2_html_payment_form", AN_STYLE_FOOTER2_HTML); setParameterIfNotNull(stringBuilder, "x_color_background", AN_STYLE_BGCOLOR); setParameterIfNotNull(stringBuilder, "x_color_link", AN_STYLE_LINKCOLOR); setParameterIfNotNull(stringBuilder, "x_color_text", AN_STYLE_TEXTCOLOR); setParameterIfNotNull(stringBuilder, "x_logo_url", AN_STYLE_LOGOURL); setParameterIfNotNull(stringBuilder, "x_background_url", AN_STYLE_BGURL); setParameterIfNotNull(stringBuilder, "x_font_family", AN_STYLE_FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_font_size", AN_STYLE_FONTSIZE); setParameterIfNotNull(stringBuilder, "x_sectionhead1_color_text", AN_STYLE_SECTION1COLOR); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_family", AN_STYLE_SECTION1FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_size", AN_STYLE_SECTION1FONTSIZE); return stringBuilder.toString(); }
AuthorizeNetSimPaymentGatewayImpl extends AbstractAuthorizeNetPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { final String apiLoginId = getParameterValue(AN_API_LOGIN_ID); final String key = getParameterValue(AN_TRANSACTION_KEY); final String amountString = "" + amount; final Fingerprint fingerprint = getFingerprint(orderReference, apiLoginId, key, amountString, currencyCode); final long x_fp_sequence = fingerprint.getSequence(); final long x_fp_timestamp = fingerprint.getTimeStamp(); final String x_fp_hash = fingerprint.getFingerprintHash(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getHiddenField("x_login", apiLoginId)); stringBuilder.append(getHiddenField("x_fp_sequence", String.valueOf(x_fp_sequence))); stringBuilder.append(getHiddenField("x_fp_timestamp", String.valueOf(x_fp_timestamp))); stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash)); stringBuilder.append(getHiddenField("x_version", "3.1")); stringBuilder.append(getHiddenField("x_method", "CC")); stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE")); stringBuilder.append(getHiddenField("x_amount", amountString)); stringBuilder.append(getHiddenField("x_currency_code", currencyCode)); stringBuilder.append(getHiddenField("x_show_form", "payment_form")); setParameterIfNotNull(stringBuilder, "x_test_request", AN_TEST_REQUEST); if (CollectionUtils.isNotEmpty(payment.getOrderItems())) { for (final PaymentLine line : payment.getOrderItems()) { if (line.isShipment()) { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); setValueIfNotNull(stringBuilder, "x_freight", name + "<|>" + name + "<|>" + line.getUnitPrice().toPlainString()); } else { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); String code = line.getSkuCode().length() > ITEMSKU ? line.getSkuCode().substring(0, ITEMSKU - 1) + "~" : line.getSkuCode(); setValueIfNotNull(stringBuilder, "x_line_item", code + "<|>" + name + "<|><|>" + line.getQuantity().toPlainString() + "<|>" + line.getUnitPrice().toPlainString() + "<|>0"); } } } final PaymentAddress address = payment.getBillingAddress(); if (address != null) { setValueIfNotNull(stringBuilder, "x_first_name", address.getFirstname()); setValueIfNotNull(stringBuilder, "x_last_name", address.getLastname()); setValueIfNotNull(stringBuilder, "x_address", getAddressLines(address)); setValueIfNotNull(stringBuilder, "x_city", address.getCity()); setValueIfNotNull(stringBuilder, "x_state", address.getStateCode()); setValueIfNotNull(stringBuilder, "x_zip", address.getPostcode()); setValueIfNotNull(stringBuilder, "x_country", address.getCountryCode()); setValueIfNotNull(stringBuilder, "x_phone", address.getPhone1()); setValueIfNotNull(stringBuilder, "x_email", payment.getBillingEmail()); } stringBuilder.append(getHiddenField("x_cust_id", payment.getBillingEmail())); final PaymentAddress shipTo = payment.getShippingAddress(); if (shipTo != null) { setValueIfNotNull(stringBuilder, "x_ship_to_first_name", shipTo.getFirstname()); setValueIfNotNull(stringBuilder, "x_ship_to_last_name", shipTo.getLastname()); setValueIfNotNull(stringBuilder, "x_ship_to_address", getAddressLines(shipTo)); setValueIfNotNull(stringBuilder, "x_ship_to_city", shipTo.getCity()); setValueIfNotNull(stringBuilder, "x_ship_to_state", shipTo.getStateCode()); setValueIfNotNull(stringBuilder, "x_ship_to_zip", shipTo.getPostcode()); setValueIfNotNull(stringBuilder, "x_ship_to_country", shipTo.getCountryCode()); } stringBuilder.append(getHiddenField("x_invoice_num", StringUtils.substring(orderReference.replace("-", ""), 0, 20))); stringBuilder.append(getHiddenField("x_po_num", orderReference)); stringBuilder.append(getHiddenField("x_description", getDescription(payment))); final String relayUrl = getParameterValue(AN_RELAY_RESPONSE_URL); if (StringUtils.isNotBlank(relayUrl)) { stringBuilder.append(getHiddenField("x_relay_url", relayUrl)); stringBuilder.append(getHiddenField("x_relay_response", "TRUE")); } else { setParameterIfNotNull(stringBuilder, "x_receipt_link_url", AN_ORDER_RECEIPT_URL); } setParameterIfNotNull(stringBuilder, "x_cancel_url", AN_CANCEL_URL); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); stringBuilder.append(getHiddenField(ORDER_GUID, orderReference)); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); setParameterIfNotNull(stringBuilder, "x_header_html_payment_form", AN_STYLE_HEADER_HTML); setParameterIfNotNull(stringBuilder, "x_header2_html_payment_form", AN_STYLE_HEADER2_HTML); setParameterIfNotNull(stringBuilder, "x_footer_html_payment_form", AN_STYLE_FOOTER_HTML); setParameterIfNotNull(stringBuilder, "x_footer2_html_payment_form", AN_STYLE_FOOTER2_HTML); setParameterIfNotNull(stringBuilder, "x_color_background", AN_STYLE_BGCOLOR); setParameterIfNotNull(stringBuilder, "x_color_link", AN_STYLE_LINKCOLOR); setParameterIfNotNull(stringBuilder, "x_color_text", AN_STYLE_TEXTCOLOR); setParameterIfNotNull(stringBuilder, "x_logo_url", AN_STYLE_LOGOURL); setParameterIfNotNull(stringBuilder, "x_background_url", AN_STYLE_BGURL); setParameterIfNotNull(stringBuilder, "x_font_family", AN_STYLE_FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_font_size", AN_STYLE_FONTSIZE); setParameterIfNotNull(stringBuilder, "x_sectionhead1_color_text", AN_STYLE_SECTION1COLOR); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_family", AN_STYLE_SECTION1FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_size", AN_STYLE_SECTION1FONTSIZE); return stringBuilder.toString(); } }
AuthorizeNetSimPaymentGatewayImpl extends AbstractAuthorizeNetPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { final String apiLoginId = getParameterValue(AN_API_LOGIN_ID); final String key = getParameterValue(AN_TRANSACTION_KEY); final String amountString = "" + amount; final Fingerprint fingerprint = getFingerprint(orderReference, apiLoginId, key, amountString, currencyCode); final long x_fp_sequence = fingerprint.getSequence(); final long x_fp_timestamp = fingerprint.getTimeStamp(); final String x_fp_hash = fingerprint.getFingerprintHash(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getHiddenField("x_login", apiLoginId)); stringBuilder.append(getHiddenField("x_fp_sequence", String.valueOf(x_fp_sequence))); stringBuilder.append(getHiddenField("x_fp_timestamp", String.valueOf(x_fp_timestamp))); stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash)); stringBuilder.append(getHiddenField("x_version", "3.1")); stringBuilder.append(getHiddenField("x_method", "CC")); stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE")); stringBuilder.append(getHiddenField("x_amount", amountString)); stringBuilder.append(getHiddenField("x_currency_code", currencyCode)); stringBuilder.append(getHiddenField("x_show_form", "payment_form")); setParameterIfNotNull(stringBuilder, "x_test_request", AN_TEST_REQUEST); if (CollectionUtils.isNotEmpty(payment.getOrderItems())) { for (final PaymentLine line : payment.getOrderItems()) { if (line.isShipment()) { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); setValueIfNotNull(stringBuilder, "x_freight", name + "<|>" + name + "<|>" + line.getUnitPrice().toPlainString()); } else { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); String code = line.getSkuCode().length() > ITEMSKU ? line.getSkuCode().substring(0, ITEMSKU - 1) + "~" : line.getSkuCode(); setValueIfNotNull(stringBuilder, "x_line_item", code + "<|>" + name + "<|><|>" + line.getQuantity().toPlainString() + "<|>" + line.getUnitPrice().toPlainString() + "<|>0"); } } } final PaymentAddress address = payment.getBillingAddress(); if (address != null) { setValueIfNotNull(stringBuilder, "x_first_name", address.getFirstname()); setValueIfNotNull(stringBuilder, "x_last_name", address.getLastname()); setValueIfNotNull(stringBuilder, "x_address", getAddressLines(address)); setValueIfNotNull(stringBuilder, "x_city", address.getCity()); setValueIfNotNull(stringBuilder, "x_state", address.getStateCode()); setValueIfNotNull(stringBuilder, "x_zip", address.getPostcode()); setValueIfNotNull(stringBuilder, "x_country", address.getCountryCode()); setValueIfNotNull(stringBuilder, "x_phone", address.getPhone1()); setValueIfNotNull(stringBuilder, "x_email", payment.getBillingEmail()); } stringBuilder.append(getHiddenField("x_cust_id", payment.getBillingEmail())); final PaymentAddress shipTo = payment.getShippingAddress(); if (shipTo != null) { setValueIfNotNull(stringBuilder, "x_ship_to_first_name", shipTo.getFirstname()); setValueIfNotNull(stringBuilder, "x_ship_to_last_name", shipTo.getLastname()); setValueIfNotNull(stringBuilder, "x_ship_to_address", getAddressLines(shipTo)); setValueIfNotNull(stringBuilder, "x_ship_to_city", shipTo.getCity()); setValueIfNotNull(stringBuilder, "x_ship_to_state", shipTo.getStateCode()); setValueIfNotNull(stringBuilder, "x_ship_to_zip", shipTo.getPostcode()); setValueIfNotNull(stringBuilder, "x_ship_to_country", shipTo.getCountryCode()); } stringBuilder.append(getHiddenField("x_invoice_num", StringUtils.substring(orderReference.replace("-", ""), 0, 20))); stringBuilder.append(getHiddenField("x_po_num", orderReference)); stringBuilder.append(getHiddenField("x_description", getDescription(payment))); final String relayUrl = getParameterValue(AN_RELAY_RESPONSE_URL); if (StringUtils.isNotBlank(relayUrl)) { stringBuilder.append(getHiddenField("x_relay_url", relayUrl)); stringBuilder.append(getHiddenField("x_relay_response", "TRUE")); } else { setParameterIfNotNull(stringBuilder, "x_receipt_link_url", AN_ORDER_RECEIPT_URL); } setParameterIfNotNull(stringBuilder, "x_cancel_url", AN_CANCEL_URL); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); stringBuilder.append(getHiddenField(ORDER_GUID, orderReference)); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); setParameterIfNotNull(stringBuilder, "x_header_html_payment_form", AN_STYLE_HEADER_HTML); setParameterIfNotNull(stringBuilder, "x_header2_html_payment_form", AN_STYLE_HEADER2_HTML); setParameterIfNotNull(stringBuilder, "x_footer_html_payment_form", AN_STYLE_FOOTER_HTML); setParameterIfNotNull(stringBuilder, "x_footer2_html_payment_form", AN_STYLE_FOOTER2_HTML); setParameterIfNotNull(stringBuilder, "x_color_background", AN_STYLE_BGCOLOR); setParameterIfNotNull(stringBuilder, "x_color_link", AN_STYLE_LINKCOLOR); setParameterIfNotNull(stringBuilder, "x_color_text", AN_STYLE_TEXTCOLOR); setParameterIfNotNull(stringBuilder, "x_logo_url", AN_STYLE_LOGOURL); setParameterIfNotNull(stringBuilder, "x_background_url", AN_STYLE_BGURL); setParameterIfNotNull(stringBuilder, "x_font_family", AN_STYLE_FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_font_size", AN_STYLE_FONTSIZE); setParameterIfNotNull(stringBuilder, "x_sectionhead1_color_text", AN_STYLE_SECTION1COLOR); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_family", AN_STYLE_SECTION1FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_size", AN_STYLE_SECTION1FONTSIZE); return stringBuilder.toString(); }  }
AuthorizeNetSimPaymentGatewayImpl extends AbstractAuthorizeNetPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { final String apiLoginId = getParameterValue(AN_API_LOGIN_ID); final String key = getParameterValue(AN_TRANSACTION_KEY); final String amountString = "" + amount; final Fingerprint fingerprint = getFingerprint(orderReference, apiLoginId, key, amountString, currencyCode); final long x_fp_sequence = fingerprint.getSequence(); final long x_fp_timestamp = fingerprint.getTimeStamp(); final String x_fp_hash = fingerprint.getFingerprintHash(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getHiddenField("x_login", apiLoginId)); stringBuilder.append(getHiddenField("x_fp_sequence", String.valueOf(x_fp_sequence))); stringBuilder.append(getHiddenField("x_fp_timestamp", String.valueOf(x_fp_timestamp))); stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash)); stringBuilder.append(getHiddenField("x_version", "3.1")); stringBuilder.append(getHiddenField("x_method", "CC")); stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE")); stringBuilder.append(getHiddenField("x_amount", amountString)); stringBuilder.append(getHiddenField("x_currency_code", currencyCode)); stringBuilder.append(getHiddenField("x_show_form", "payment_form")); setParameterIfNotNull(stringBuilder, "x_test_request", AN_TEST_REQUEST); if (CollectionUtils.isNotEmpty(payment.getOrderItems())) { for (final PaymentLine line : payment.getOrderItems()) { if (line.isShipment()) { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); setValueIfNotNull(stringBuilder, "x_freight", name + "<|>" + name + "<|>" + line.getUnitPrice().toPlainString()); } else { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); String code = line.getSkuCode().length() > ITEMSKU ? line.getSkuCode().substring(0, ITEMSKU - 1) + "~" : line.getSkuCode(); setValueIfNotNull(stringBuilder, "x_line_item", code + "<|>" + name + "<|><|>" + line.getQuantity().toPlainString() + "<|>" + line.getUnitPrice().toPlainString() + "<|>0"); } } } final PaymentAddress address = payment.getBillingAddress(); if (address != null) { setValueIfNotNull(stringBuilder, "x_first_name", address.getFirstname()); setValueIfNotNull(stringBuilder, "x_last_name", address.getLastname()); setValueIfNotNull(stringBuilder, "x_address", getAddressLines(address)); setValueIfNotNull(stringBuilder, "x_city", address.getCity()); setValueIfNotNull(stringBuilder, "x_state", address.getStateCode()); setValueIfNotNull(stringBuilder, "x_zip", address.getPostcode()); setValueIfNotNull(stringBuilder, "x_country", address.getCountryCode()); setValueIfNotNull(stringBuilder, "x_phone", address.getPhone1()); setValueIfNotNull(stringBuilder, "x_email", payment.getBillingEmail()); } stringBuilder.append(getHiddenField("x_cust_id", payment.getBillingEmail())); final PaymentAddress shipTo = payment.getShippingAddress(); if (shipTo != null) { setValueIfNotNull(stringBuilder, "x_ship_to_first_name", shipTo.getFirstname()); setValueIfNotNull(stringBuilder, "x_ship_to_last_name", shipTo.getLastname()); setValueIfNotNull(stringBuilder, "x_ship_to_address", getAddressLines(shipTo)); setValueIfNotNull(stringBuilder, "x_ship_to_city", shipTo.getCity()); setValueIfNotNull(stringBuilder, "x_ship_to_state", shipTo.getStateCode()); setValueIfNotNull(stringBuilder, "x_ship_to_zip", shipTo.getPostcode()); setValueIfNotNull(stringBuilder, "x_ship_to_country", shipTo.getCountryCode()); } stringBuilder.append(getHiddenField("x_invoice_num", StringUtils.substring(orderReference.replace("-", ""), 0, 20))); stringBuilder.append(getHiddenField("x_po_num", orderReference)); stringBuilder.append(getHiddenField("x_description", getDescription(payment))); final String relayUrl = getParameterValue(AN_RELAY_RESPONSE_URL); if (StringUtils.isNotBlank(relayUrl)) { stringBuilder.append(getHiddenField("x_relay_url", relayUrl)); stringBuilder.append(getHiddenField("x_relay_response", "TRUE")); } else { setParameterIfNotNull(stringBuilder, "x_receipt_link_url", AN_ORDER_RECEIPT_URL); } setParameterIfNotNull(stringBuilder, "x_cancel_url", AN_CANCEL_URL); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); stringBuilder.append(getHiddenField(ORDER_GUID, orderReference)); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); setParameterIfNotNull(stringBuilder, "x_header_html_payment_form", AN_STYLE_HEADER_HTML); setParameterIfNotNull(stringBuilder, "x_header2_html_payment_form", AN_STYLE_HEADER2_HTML); setParameterIfNotNull(stringBuilder, "x_footer_html_payment_form", AN_STYLE_FOOTER_HTML); setParameterIfNotNull(stringBuilder, "x_footer2_html_payment_form", AN_STYLE_FOOTER2_HTML); setParameterIfNotNull(stringBuilder, "x_color_background", AN_STYLE_BGCOLOR); setParameterIfNotNull(stringBuilder, "x_color_link", AN_STYLE_LINKCOLOR); setParameterIfNotNull(stringBuilder, "x_color_text", AN_STYLE_TEXTCOLOR); setParameterIfNotNull(stringBuilder, "x_logo_url", AN_STYLE_LOGOURL); setParameterIfNotNull(stringBuilder, "x_background_url", AN_STYLE_BGURL); setParameterIfNotNull(stringBuilder, "x_font_family", AN_STYLE_FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_font_size", AN_STYLE_FONTSIZE); setParameterIfNotNull(stringBuilder, "x_sectionhead1_color_text", AN_STYLE_SECTION1COLOR); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_family", AN_STYLE_SECTION1FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_size", AN_STYLE_SECTION1FONTSIZE); return stringBuilder.toString(); }  @Override PaymentGatewayFeature getPaymentGatewayFeatures(); @Override String getPostActionUrl(); @Override String getSubmitButton(final String locale); @Override Payment authorizeCapture(final Payment payment, final boolean forceProcessing); @Override Payment authorize(final Payment paymentIn, final boolean forceProcessing); @Override Payment reverseAuthorization(final Payment paymentIn, final boolean forceProcessing); @Override Payment capture(final Payment paymentIn, final boolean forceProcessing); @Override Payment voidCapture(final Payment paymentIn, final boolean forceProcessing); @Override Payment refund(final Payment paymentIn, final boolean forceProcessing); @Override void preProcess(final Payment payment, final Callback callback, final String processorOperation); @Override void postProcess(final Payment payment, final Callback callback, final String processorOperation); @Override Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing); @Override CallbackAware.CallbackResult getExternalCallbackResult(final Map<String, String> callbackResult,
                                                                  final boolean forceProcessing); @Override String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount,
                              final String currencyCode, final String orderReference, final Payment payment); @Override Payment createPaymentPrototype(final String operation,
                                          final Map privateCallBackParameters,
                                          boolean forceProcessing); }
AuthorizeNetSimPaymentGatewayImpl extends AbstractAuthorizeNetPaymentGatewayImpl implements PaymentGatewayExternalForm, CallbackAware { @Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { final String apiLoginId = getParameterValue(AN_API_LOGIN_ID); final String key = getParameterValue(AN_TRANSACTION_KEY); final String amountString = "" + amount; final Fingerprint fingerprint = getFingerprint(orderReference, apiLoginId, key, amountString, currencyCode); final long x_fp_sequence = fingerprint.getSequence(); final long x_fp_timestamp = fingerprint.getTimeStamp(); final String x_fp_hash = fingerprint.getFingerprintHash(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(getHiddenField("x_login", apiLoginId)); stringBuilder.append(getHiddenField("x_fp_sequence", String.valueOf(x_fp_sequence))); stringBuilder.append(getHiddenField("x_fp_timestamp", String.valueOf(x_fp_timestamp))); stringBuilder.append(getHiddenField("x_fp_hash", x_fp_hash)); stringBuilder.append(getHiddenField("x_version", "3.1")); stringBuilder.append(getHiddenField("x_method", "CC")); stringBuilder.append(getHiddenField("x_type", "AUTH_CAPTURE")); stringBuilder.append(getHiddenField("x_amount", amountString)); stringBuilder.append(getHiddenField("x_currency_code", currencyCode)); stringBuilder.append(getHiddenField("x_show_form", "payment_form")); setParameterIfNotNull(stringBuilder, "x_test_request", AN_TEST_REQUEST); if (CollectionUtils.isNotEmpty(payment.getOrderItems())) { for (final PaymentLine line : payment.getOrderItems()) { if (line.isShipment()) { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); setValueIfNotNull(stringBuilder, "x_freight", name + "<|>" + name + "<|>" + line.getUnitPrice().toPlainString()); } else { String name = line.getSkuName().length() > ITEMNAME ? line.getSkuName().substring(0, ITEMNAME - 1) + "~" : line.getSkuName(); String code = line.getSkuCode().length() > ITEMSKU ? line.getSkuCode().substring(0, ITEMSKU - 1) + "~" : line.getSkuCode(); setValueIfNotNull(stringBuilder, "x_line_item", code + "<|>" + name + "<|><|>" + line.getQuantity().toPlainString() + "<|>" + line.getUnitPrice().toPlainString() + "<|>0"); } } } final PaymentAddress address = payment.getBillingAddress(); if (address != null) { setValueIfNotNull(stringBuilder, "x_first_name", address.getFirstname()); setValueIfNotNull(stringBuilder, "x_last_name", address.getLastname()); setValueIfNotNull(stringBuilder, "x_address", getAddressLines(address)); setValueIfNotNull(stringBuilder, "x_city", address.getCity()); setValueIfNotNull(stringBuilder, "x_state", address.getStateCode()); setValueIfNotNull(stringBuilder, "x_zip", address.getPostcode()); setValueIfNotNull(stringBuilder, "x_country", address.getCountryCode()); setValueIfNotNull(stringBuilder, "x_phone", address.getPhone1()); setValueIfNotNull(stringBuilder, "x_email", payment.getBillingEmail()); } stringBuilder.append(getHiddenField("x_cust_id", payment.getBillingEmail())); final PaymentAddress shipTo = payment.getShippingAddress(); if (shipTo != null) { setValueIfNotNull(stringBuilder, "x_ship_to_first_name", shipTo.getFirstname()); setValueIfNotNull(stringBuilder, "x_ship_to_last_name", shipTo.getLastname()); setValueIfNotNull(stringBuilder, "x_ship_to_address", getAddressLines(shipTo)); setValueIfNotNull(stringBuilder, "x_ship_to_city", shipTo.getCity()); setValueIfNotNull(stringBuilder, "x_ship_to_state", shipTo.getStateCode()); setValueIfNotNull(stringBuilder, "x_ship_to_zip", shipTo.getPostcode()); setValueIfNotNull(stringBuilder, "x_ship_to_country", shipTo.getCountryCode()); } stringBuilder.append(getHiddenField("x_invoice_num", StringUtils.substring(orderReference.replace("-", ""), 0, 20))); stringBuilder.append(getHiddenField("x_po_num", orderReference)); stringBuilder.append(getHiddenField("x_description", getDescription(payment))); final String relayUrl = getParameterValue(AN_RELAY_RESPONSE_URL); if (StringUtils.isNotBlank(relayUrl)) { stringBuilder.append(getHiddenField("x_relay_url", relayUrl)); stringBuilder.append(getHiddenField("x_relay_response", "TRUE")); } else { setParameterIfNotNull(stringBuilder, "x_receipt_link_url", AN_ORDER_RECEIPT_URL); } setParameterIfNotNull(stringBuilder, "x_cancel_url", AN_CANCEL_URL); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); stringBuilder.append(getHiddenField(ORDER_GUID, orderReference)); setParameterIfNotNull(stringBuilder, "x_return_policy_url", AN_RETURN_POLICY_URL); setParameterIfNotNull(stringBuilder, "x_header_html_payment_form", AN_STYLE_HEADER_HTML); setParameterIfNotNull(stringBuilder, "x_header2_html_payment_form", AN_STYLE_HEADER2_HTML); setParameterIfNotNull(stringBuilder, "x_footer_html_payment_form", AN_STYLE_FOOTER_HTML); setParameterIfNotNull(stringBuilder, "x_footer2_html_payment_form", AN_STYLE_FOOTER2_HTML); setParameterIfNotNull(stringBuilder, "x_color_background", AN_STYLE_BGCOLOR); setParameterIfNotNull(stringBuilder, "x_color_link", AN_STYLE_LINKCOLOR); setParameterIfNotNull(stringBuilder, "x_color_text", AN_STYLE_TEXTCOLOR); setParameterIfNotNull(stringBuilder, "x_logo_url", AN_STYLE_LOGOURL); setParameterIfNotNull(stringBuilder, "x_background_url", AN_STYLE_BGURL); setParameterIfNotNull(stringBuilder, "x_font_family", AN_STYLE_FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_font_size", AN_STYLE_FONTSIZE); setParameterIfNotNull(stringBuilder, "x_sectionhead1_color_text", AN_STYLE_SECTION1COLOR); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_family", AN_STYLE_SECTION1FONTFAMILY); setParameterIfNotNull(stringBuilder, "x_sectionhead1_font_size", AN_STYLE_SECTION1FONTSIZE); return stringBuilder.toString(); }  @Override PaymentGatewayFeature getPaymentGatewayFeatures(); @Override String getPostActionUrl(); @Override String getSubmitButton(final String locale); @Override Payment authorizeCapture(final Payment payment, final boolean forceProcessing); @Override Payment authorize(final Payment paymentIn, final boolean forceProcessing); @Override Payment reverseAuthorization(final Payment paymentIn, final boolean forceProcessing); @Override Payment capture(final Payment paymentIn, final boolean forceProcessing); @Override Payment voidCapture(final Payment paymentIn, final boolean forceProcessing); @Override Payment refund(final Payment paymentIn, final boolean forceProcessing); @Override void preProcess(final Payment payment, final Callback callback, final String processorOperation); @Override void postProcess(final Payment payment, final Callback callback, final String processorOperation); @Override Callback convertToCallback(final Map privateCallBackParameters, final boolean forceProcessing); @Override CallbackAware.CallbackResult getExternalCallbackResult(final Map<String, String> callbackResult,
                                                                  final boolean forceProcessing); @Override String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount,
                              final String currencyCode, final String orderReference, final Payment payment); @Override Payment createPaymentPrototype(final String operation,
                                          final Map privateCallBackParameters,
                                          boolean forceProcessing);  }