Skip to content

Commit be2f9af

Browse files
committed
Add support for CIM GetHostedProfilePage method
1 parent 1163126 commit be2f9af

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed

src/main/java/net/authorize/AuthNetField.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public enum AuthNetField {
8686
ELEMENT_FIRST_NAME("firstName"),
8787
ELEMENT_FIRST_SETTLEMENT_DATE("firstSettlementDate"),
8888
ELEMENT_HAS_RETURNED_ITEMS("hasReturnedItems"),
89+
ELEMENT_HOSTED_PROFILE_SETTINGS("hostedProfileSettings"),
8990
ELEMENT_ID("id"),
9091
ELEMENT_IDS("ids"),
9192
ELEMENT_INCLUDE_STATISTICS("includeStatistics"),
@@ -142,6 +143,9 @@ public enum AuthNetField {
142143
ELEMENT_RETURNED_ITEMS_DATE_UTC("dateUTC"),
143144
ELEMENT_RETURNED_ITEMS_DATE_LOCAL("dateLocal"),
144145
ELEMENT_ROUTING_NUMBER("routingNumber"),
146+
ELEMENT_SETTING("setting"),
147+
ELEMENT_SETTING_NAME("settingName"),
148+
ELEMENT_SETTING_VALUE("settingValue"),
145149
ELEMENT_SETTLE_AMOUNT("settleAmount"),
146150
ELEMENT_SETTLEMENT_STATE("settlementState"),
147151
ELEMENT_SETTLEMENT_TIME_LOCAL("settlementTimeLocal"),
@@ -165,6 +169,7 @@ public enum AuthNetField {
165169
ELEMENT_TAX_EXEMPT("taxExempt"),
166170
ELEMENT_TAXABLE("taxable"),
167171
ELEMENT_TEXT("text"),
172+
ELEMENT_TOKEN("token"),
168173
ELEMENT_TOTAL_OCCURRENCES("totalOccurrences"),
169174
ELEMENT_TRANS_ID("transId"),
170175
ELEMENT_TRANSACTION("transaction"),

src/main/java/net/authorize/cim/Result.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Result<T> extends net.authorize.xml.Result<T> {
3030
protected String refId;
3131
protected ArrayList<String> customerProfileIdList = new ArrayList<String>();
3232
protected CustomerProfile customerProfile;
33+
protected String token;
3334

3435
protected ArrayList<String> customerPaymentProfileIdList = new ArrayList<String>();
3536
protected ArrayList<PaymentProfile> paymentProfileList = new ArrayList<PaymentProfile>();
@@ -62,6 +63,8 @@ public static <T> Result<T> createResult(T object, BasicXmlDocument response) {
6263
case GET_CUSTOMER_SHIPPING_ADDRESS:
6364
result.importShippingAddress(targetTransaction);
6465
break;
66+
case GET_HOSTED_PROFILE_PAGE:
67+
result.importToken(targetTransaction);
6568
default:
6669
break;
6770
}
@@ -117,6 +120,14 @@ private void importCustomerShippingAddressId(Transaction txn) {
117120
}
118121
}
119122

123+
/**
124+
* Import the hosted profile page token.
125+
*/
126+
private void importToken(Transaction txn) {
127+
this.token = getElementText(
128+
txn.getCurrentResponse().getDocument().getDocumentElement(), AuthNetField.ELEMENT_TOKEN.getFieldName());
129+
}
130+
120131
/**
121132
* Import the customer payment profile id (list).
122133
*/
@@ -439,6 +450,13 @@ public ArrayList<DirectResponse> getDirectResponseList() {
439450
public String getRefId() {
440451
return refId;
441452
}
453+
454+
/**
455+
* @return the hosted profile page token
456+
*/
457+
public String getToken() {
458+
return token;
459+
}
442460

443461
/**
444462
* @return the customerPaymentProfileIdList

src/main/java/net/authorize/cim/Transaction.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.authorize.data.cim.CustomerProfile;
1616
import net.authorize.data.cim.PaymentProfile;
1717
import net.authorize.data.cim.PaymentTransaction;
18+
import net.authorize.data.cim.HostedProfileSettingType;
1819
import net.authorize.data.creditcard.CreditCard;
1920
import net.authorize.data.xml.Address;
2021
import net.authorize.data.xml.BankAccount;
@@ -42,6 +43,7 @@ public class Transaction extends net.authorize.Transaction {
4243
private ArrayList<PaymentProfile> paymentProfileList = new ArrayList<PaymentProfile>();
4344
private PaymentTransaction paymentTransaction;
4445
protected Map<String, String> extraOptions = Collections.synchronizedMap(new HashMap<String, String>());
46+
protected Map<HostedProfileSettingType, String> hostedProfileSettings = Collections.synchronizedMap(new HashMap<HostedProfileSettingType, String>());
4547

4648
private ValidationModeType validationMode = ValidationModeType.NONE;
4749
private BasicXmlDocument currentRequest = null;
@@ -691,6 +693,31 @@ private void addExtraOptions(BasicXmlDocument document) {
691693
}
692694
}
693695
}
696+
697+
/**
698+
* Add hosted profile settings to the document.
699+
*
700+
* @param document
701+
*/
702+
private void addHostedProfileSettings(BasicXmlDocument document) {
703+
if(this.hostedProfileSettings != null && this.hostedProfileSettings.size() > 0) {
704+
Element hp_settings_el = document.createElement(AuthNetField.ELEMENT_HOSTED_PROFILE_SETTINGS.getFieldName());
705+
for(HostedProfileSettingType key : hostedProfileSettings.keySet()) {
706+
Element setting_el = document.createElement(AuthNetField.ELEMENT_SETTING.getFieldName());
707+
708+
Element setting_name_el = document.createElement(AuthNetField.ELEMENT_SETTING_NAME.getFieldName());
709+
setting_name_el.appendChild(document.getDocument().createTextNode(key.getValue()));
710+
setting_el.appendChild(setting_name_el);
711+
712+
Element setting_value_el = document.createElement(AuthNetField.ELEMENT_SETTING_VALUE.getFieldName());
713+
setting_value_el.appendChild(document.getDocument().createTextNode(hostedProfileSettings.get(key)));
714+
setting_el.appendChild(setting_value_el);
715+
716+
hp_settings_el.appendChild(setting_el);
717+
}
718+
document.getDocumentElement().appendChild(hp_settings_el);
719+
}
720+
}
694721

695722
/**
696723
* Add the split tender id and status to the document.
@@ -750,6 +777,9 @@ public String toXMLString() {
750777
case GET_CUSTOMER_SHIPPING_ADDRESS :
751778
getCustomerShippingAddress();
752779
break;
780+
case GET_HOSTED_PROFILE_PAGE :
781+
getHostedProfilePage();
782+
break;
753783
case UPDATE_CUSTOMER_PROFILE :
754784
updateCustomerProfile();
755785
break;
@@ -864,6 +894,21 @@ private void getCustomerShippingAddress() {
864894
addCustomerAddressId(document);
865895
currentRequest = document;
866896
}
897+
898+
/**
899+
* Get hosted profile page request.
900+
*/
901+
private void getHostedProfilePage() {
902+
BasicXmlDocument document = new BasicXmlDocument();
903+
document.parseString("<" + TransactionType.GET_HOSTED_PROFILE_PAGE.getValue()
904+
+ " xmlns = \"" + XML_NAMESPACE + "\" />");
905+
906+
addAuthentication(document);
907+
addRefId(document);
908+
addCustomerProfileId(document);
909+
addHostedProfileSettings(document);
910+
currentRequest = document;
911+
}
867912

868913
/**
869914
* Get customer payment profile request.
@@ -1192,4 +1237,26 @@ public void addExtraOption(String key, String value) {
11921237
}
11931238
this.extraOptions.put(key, value);
11941239
}
1240+
1241+
/**
1242+
* Sets the hosted profile settings.
1243+
*
1244+
* @param settings the settings to set
1245+
*/
1246+
public void setHostedProfileSettings(Map<HostedProfileSettingType, String> settings) {
1247+
this.hostedProfileSettings = settings;
1248+
}
1249+
1250+
/**
1251+
* Add hosted profile setting to the hosted profile settings map.
1252+
*
1253+
* @param settingName
1254+
* @param settingValue
1255+
*/
1256+
public void addHostedProfileSetting(HostedProfileSettingType settingName, String settingValue) {
1257+
if(this.hostedProfileSettings == null) {
1258+
this.hostedProfileSettings = Collections.synchronizedMap(new HashMap<HostedProfileSettingType, String>());
1259+
}
1260+
this.hostedProfileSettings.put(settingName, settingValue);
1261+
}
11951262
}

src/main/java/net/authorize/cim/TransactionType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum TransactionType {
1616
GET_CUSTOMER_PROFILE("getCustomerProfileRequest"),
1717
GET_CUSTOMER_PAYMENT_PROFILE("getCustomerPaymentProfileRequest"),
1818
GET_CUSTOMER_SHIPPING_ADDRESS("getCustomerShippingAddressRequest"),
19+
GET_HOSTED_PROFILE_PAGE("getHostedProfilePageRequest"),
1920
UPDATE_CUSTOMER_PROFILE("updateCustomerProfileRequest"),
2021
UPDATE_CUSTOMER_PAYMENT_PROFILE("updateCustomerPaymentProfileRequest"),
2122
UPDATE_CUSTOMER_SHIPPING_ADDRESS("updateCustomerShippingAddressRequest"),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package net.authorize.data.cim;
2+
3+
/**
4+
* Enumeration of CIM hosted profile setting types that are supported by Authorize.Net
5+
*/
6+
public enum HostedProfileSettingType {
7+
HOSTED_PROFILE_RETURN_URL("hostedProfileReturnUrl"),
8+
HOSTED_PROFILE_RETURN_URL_TEXT("hostedProfileReturnUrlText"),
9+
HOSTED_PROFILE_HEADING_BG_COLOR("hostedProfileHeadingBgColor"),
10+
HOSTED_PROFILE_PAGE_BORDER_VISIBLE("hostedProfilePageBorderVisible"),
11+
HOSTED_PROFILE_IFRAME_COMMUNICATOR_URL("hostedProfileIFrameCommunicatorUrl"),
12+
HOSTED_PROFILE_VALIDATION_MODE("hostedProfileValidationMode");
13+
14+
final private String value;
15+
16+
private HostedProfileSettingType(String value) {
17+
this.value = value;
18+
}
19+
20+
/**
21+
* @return the value
22+
*/
23+
public String getValue() {
24+
return value;
25+
}
26+
27+
}

src/test/java/net/authorize/cim/functional_test/CIMTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.authorize.data.OrderItem;
1717
import net.authorize.data.ShippingCharges;
1818
import net.authorize.data.cim.CustomerProfile;
19+
import net.authorize.data.cim.HostedProfileSettingType;
1920
import net.authorize.data.cim.PaymentProfile;
2021
import net.authorize.data.cim.PaymentTransaction;
2122
import net.authorize.data.creditcard.AVSCode;
@@ -515,6 +516,28 @@ public void testGetCustomerShippingAddressRequest() {
515516
Assert.assertEquals(phone, shippingAddress.getPhoneNumber());
516517
Assert.assertEquals(fax, shippingAddress.getFaxNumber());
517518
}
519+
520+
@SuppressWarnings("unchecked")
521+
@Test
522+
public void testGetHostedProfilePageRequest() {
523+
// get a token to access hosted profile pages
524+
net.authorize.cim.Transaction transaction =
525+
merchant.createCIMTransaction(TransactionType.GET_HOSTED_PROFILE_PAGE);
526+
527+
transaction.setRefId(refId);
528+
transaction.setCustomerProfileId(customerId);
529+
transaction.addHostedProfileSetting(HostedProfileSettingType.HOSTED_PROFILE_PAGE_BORDER_VISIBLE, "false");
530+
transaction.addHostedProfileSetting(HostedProfileSettingType.HOSTED_PROFILE_IFRAME_COMMUNICATOR_URL, "http://localhost");
531+
532+
Result<Transaction> result = (Result<Transaction>)merchant.postTransaction(transaction);
533+
534+
Assert.assertNotNull(result);
535+
result.printMessages();
536+
Assert.assertTrue(result.isOk());
537+
Assert.assertNotNull(result.getRefId());
538+
Assert.assertNotNull(result.getToken());
539+
540+
}
518541

519542
@SuppressWarnings("unchecked")
520543
@Test

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy