Skip to content

Commit 91fa814

Browse files
gnongsiesrathod
authored andcommitted
Verified pull request #91
1 parent 2f7ed40 commit 91fa814

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-6
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.authorize.data.xml.BankAccount;
1313
import net.authorize.data.xml.Payment;
1414
import net.authorize.util.BasicXmlDocument;
15+
import net.authorize.util.StringUtils;
1516
import net.authorize.util.XmlUtility;
1617

1718
import org.w3c.dom.Element;
@@ -172,8 +173,31 @@ private void addSubscriptionToRequest(BasicXmlDocument document, Subscription su
172173
subscr_el.appendChild(trial_el);
173174
}
174175

175-
addPaymentToSubscription(document, subscription, subscr_el);
176-
addBillingInfoToSubscription(document, subscription, subscr_el);
176+
if (subscription.getProfile() != null &&
177+
StringUtils.isNotEmpty(subscription.getProfile().getCustomerProfileId()) &&
178+
StringUtils.isNotEmpty(subscription.getProfile().getCustomerPaymentProfileId())) {
179+
180+
Element profile = document.createElement(AuthNetField.ELEMENT_PROFILE.getFieldName());
181+
182+
Element customerProfileId = document.createElement(AuthNetField.ELEMENT_CUSTOMER_PROFILE_ID.getFieldName());
183+
customerProfileId.appendChild(document.getDocument().createTextNode(subscription.getProfile().getCustomerProfileId()));
184+
profile.appendChild(customerProfileId);
185+
186+
Element customerPaymentProfileId = document.createElement(AuthNetField.ELEMENT_CUSTOMER_PAYMENT_PROFILE_ID.getFieldName());
187+
customerPaymentProfileId.appendChild(document.getDocument().createTextNode(subscription.getProfile().getCustomerPaymentProfileId()));
188+
profile.appendChild(customerPaymentProfileId);
189+
190+
if (StringUtils.isNotEmpty(subscription.getProfile().getCustomerAddressId())) {
191+
Element customerAddressId = document.createElement(AuthNetField.ELEMENT_CUSTOMER_ADDRESS_ID.getFieldName());
192+
customerAddressId.appendChild(document.getDocument().createTextNode(subscription.getProfile().getCustomerAddressId()));
193+
profile.appendChild(customerAddressId);
194+
}
195+
subscr_el.appendChild(profile);
196+
197+
} else {
198+
addPaymentToSubscription(document, subscription, subscr_el);
199+
addBillingInfoToSubscription(document, subscription, subscr_el);
200+
}
177201
document.getDocumentElement().appendChild(subscr_el);
178202
}
179203

@@ -485,4 +509,4 @@ public String toXMLString() {
485509
return currentRequest.dump();
486510
}
487511

488-
}
512+
}

src/main/java/net/authorize/data/arb/Subscription.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.authorize.data.arb;
1+
package net.authorize.data.arb;
22

33
import java.io.Serializable;
44
import java.math.BigDecimal;
@@ -25,6 +25,7 @@ public class Subscription implements Serializable {
2525
private BigDecimal trial_amount = Transaction.ZERO_AMOUNT;
2626
private Payment payment = null;
2727
private Customer customer;
28+
private Profile profile;
2829
private String refId = null;
2930
private Order order = null;
3031

@@ -80,6 +81,24 @@ public void setCustomer(Customer customer) {
8081
this.customer = customer;
8182
}
8283

84+
/**
85+
* Get the profile container.
86+
*
87+
* @return Profile
88+
*/
89+
public Profile getProfile() {
90+
return profile;
91+
}
92+
93+
/**
94+
* Set the profile container.
95+
*
96+
* @param profile
97+
*/
98+
public void setProfile(Profile profile) {
99+
this.profile = profile;
100+
}
101+
83102
/**
84103
* Get the subscription amount.
85104
*
@@ -200,4 +219,4 @@ public void setOrder(Order order) {
200219
}
201220

202221

203-
}
222+
}

src/test/java/net/authorize/arb/functional_test/ARBTest.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package net.authorize.arb.functional_test;
22

33
import java.math.BigDecimal;
4+
import java.util.Random;
5+
import net.authorize.Environment;
6+
import net.authorize.Merchant;
47

58
import net.authorize.Transaction;
69
import net.authorize.UnitTestData;
710
import net.authorize.arb.Result;
811
import net.authorize.arb.TransactionType;
12+
import net.authorize.data.arb.Profile;
13+
import net.authorize.cim.ValidationModeType;
914
import net.authorize.data.Order;
1015
import net.authorize.data.arb.PaymentSchedule;
1116
import net.authorize.data.arb.Subscription;
@@ -17,8 +22,11 @@
1722
import net.authorize.data.xml.Address;
1823
import net.authorize.data.xml.BankAccount;
1924
import net.authorize.data.xml.Customer;
25+
import net.authorize.data.xml.CustomerType;
2026
import net.authorize.data.xml.Payment;
2127
import net.authorize.util.XmlUtility;
28+
import net.authorize.data.cim.CustomerProfile;
29+
import net.authorize.data.cim.PaymentProfile;
2230

2331
import org.junit.Assert;
2432
import org.junit.Before;
@@ -51,6 +59,7 @@ public void setUp() throws Exception {
5159
credit_card = CreditCard.createCreditCard();
5260
credit_card.setCreditCardNumber(creditCardNumber);
5361
credit_card.setExpirationDate("2029-07");
62+
credit_card.setCardCode("234");
5463

5564
// Create a bank account
5665
bank_account = BankAccount.createBankAccount();
@@ -94,7 +103,7 @@ public void setUp() throws Exception {
94103
subscription.setPayment(Payment.createPayment(credit_card));
95104
subscription.setSchedule(new_schedule);
96105
subscription.setCustomer(customer);
97-
subscription.setAmount(new BigDecimal(6.00));
106+
subscription.setAmount(new BigDecimal(6.00));
98107
subscription.setTrialAmount(Transaction.ZERO_AMOUNT);
99108
subscription.setRefId("REF:" + System.currentTimeMillis());
100109

@@ -204,4 +213,39 @@ private net.authorize.arb.Result<Transaction> createCreditCardSubscription() {
204213

205214
return result;
206215
}
216+
217+
@Test
218+
public void createCimSubscription() throws InterruptedException {
219+
// Create a new subscription request from the subscription object
220+
//
221+
net.authorize.cim.Transaction transactionCim = merchant.createCIMTransaction(net.authorize.cim.TransactionType.CREATE_CUSTOMER_PROFILE);
222+
223+
transactionCim.setRefId("REF:" + System.currentTimeMillis());
224+
225+
CustomerProfile customerProfile = CustomerProfile.createCustomerProfile();
226+
customerProfile.setMerchantCustomerId(Integer.toString(new Random().nextInt(10000)));
227+
transactionCim.setCustomerProfile(customerProfile);
228+
229+
PaymentProfile paymentProfile = PaymentProfile.createPaymentProfile();
230+
paymentProfile.setBillTo(billing_info);
231+
paymentProfile.setCustomerType(CustomerType.INDIVIDUAL);
232+
paymentProfile.addPayment(Payment.createPayment(credit_card));
233+
transactionCim.addPaymentProfile(paymentProfile);
234+
transactionCim.setValidationMode(ValidationModeType.TEST_MODE);
235+
net.authorize.cim.Result<Transaction> resultCim = (net.authorize.cim.Result<Transaction>) merchant.postTransaction(transactionCim);
236+
Profile profile = Profile.createProfile();
237+
profile.setCustomerProfileId(resultCim.getCustomerProfileId());
238+
profile.setCustomerPaymentProfileId(resultCim.getCustomerPaymentProfileIdList().get(0));
239+
240+
subscription.setProfile(profile);
241+
subscription.setPayment(null);
242+
subscription.setCustomer(null);
243+
Thread.sleep(30000); //wait for authorize to create CIM profile
244+
net.authorize.arb.Transaction transaction = merchant.createARBTransaction(TransactionType.CREATE_SUBSCRIPTION, subscription);
245+
net.authorize.arb.Result<Transaction> result = (net.authorize.arb.Result<Transaction>)merchant.postTransaction(transaction);
246+
Assert.assertNotNull(result);
247+
result.printMessages();
248+
Assert.assertTrue(result.isOk());
249+
Assert.assertNotNull(result.getResultSubscriptionId());
250+
}
207251
}

0 commit comments

Comments
 (0)