|
1 | 1 | package net.authorize.arb.functional_test; |
2 | 2 |
|
3 | 3 | import java.math.BigDecimal; |
| 4 | +import java.util.Random; |
| 5 | +import net.authorize.Environment; |
| 6 | +import net.authorize.Merchant; |
4 | 7 |
|
5 | 8 | import net.authorize.Transaction; |
6 | 9 | import net.authorize.UnitTestData; |
7 | 10 | import net.authorize.arb.Result; |
8 | 11 | import net.authorize.arb.TransactionType; |
| 12 | +import net.authorize.data.arb.Profile; |
| 13 | +import net.authorize.cim.ValidationModeType; |
9 | 14 | import net.authorize.data.Order; |
10 | 15 | import net.authorize.data.arb.PaymentSchedule; |
11 | 16 | import net.authorize.data.arb.Subscription; |
|
17 | 22 | import net.authorize.data.xml.Address; |
18 | 23 | import net.authorize.data.xml.BankAccount; |
19 | 24 | import net.authorize.data.xml.Customer; |
| 25 | +import net.authorize.data.xml.CustomerType; |
20 | 26 | import net.authorize.data.xml.Payment; |
21 | 27 | import net.authorize.util.XmlUtility; |
| 28 | +import net.authorize.data.cim.CustomerProfile; |
| 29 | +import net.authorize.data.cim.PaymentProfile; |
22 | 30 |
|
23 | 31 | import org.junit.Assert; |
24 | 32 | import org.junit.Before; |
@@ -51,6 +59,7 @@ public void setUp() throws Exception { |
51 | 59 | credit_card = CreditCard.createCreditCard(); |
52 | 60 | credit_card.setCreditCardNumber(creditCardNumber); |
53 | 61 | credit_card.setExpirationDate("2029-07"); |
| 62 | + credit_card.setCardCode("234"); |
54 | 63 |
|
55 | 64 | // Create a bank account |
56 | 65 | bank_account = BankAccount.createBankAccount(); |
@@ -94,7 +103,7 @@ public void setUp() throws Exception { |
94 | 103 | subscription.setPayment(Payment.createPayment(credit_card)); |
95 | 104 | subscription.setSchedule(new_schedule); |
96 | 105 | subscription.setCustomer(customer); |
97 | | - subscription.setAmount(new BigDecimal(6.00)); |
| 106 | + subscription.setAmount(new BigDecimal(6.00)); |
98 | 107 | subscription.setTrialAmount(Transaction.ZERO_AMOUNT); |
99 | 108 | subscription.setRefId("REF:" + System.currentTimeMillis()); |
100 | 109 |
|
@@ -204,4 +213,39 @@ private net.authorize.arb.Result<Transaction> createCreditCardSubscription() { |
204 | 213 |
|
205 | 214 | return result; |
206 | 215 | } |
| 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 | + } |
207 | 251 | } |
0 commit comments