@Test(groups = "integration") public void testPagination() throws Exception { System.setProperty(RECURLY_PAGE_SIZE, "1"); final int minNumberOfAccounts = 5; for (int i = 0; i < minNumberOfAccounts; i++) { final Account accountData = TestUtils.createRandomAccount(); recurlyClient.createAccount(accountData); } final Set<String> accountCodes = new HashSet<String>(); Accounts accounts = recurlyClient.getAccounts(); for (int i = 0; i < minNumberOfAccounts; i++) { // If the environment is used, we will have more than the ones we created Assert.assertEquals(accounts.size(), 1); accountCodes.add(accounts.get(0).getAccountCode()); if (i < minNumberOfAccounts - 1) { accounts = accounts.getNext(); } } Assert.assertEquals(accountCodes.size(), minNumberOfAccounts); System.setProperty(RECURLY_PAGE_SIZE, "50"); }
@Test(groups = "integration") public void testGetAccountBalance() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); try { final Account account = recurlyClient.createAccount(accountData); // Create BillingInfo billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.assertNotNull(billingInfo); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); final Adjustment adjustment = new Adjustment(); adjustment.setUnitAmountInCents(150); adjustment.setCurrency(CURRENCY); recurlyClient.createAccountAdjustment(account.getAccountCode(), adjustment); final AccountBalance balance = recurlyClient.getAccountBalance(account.getAccountCode()); Assert.assertEquals(balance.getBalanceInCents().getUnitAmountUSD(), new Integer(150)); Assert.assertEquals(balance.getPastDue(), Boolean.FALSE); } finally { // Clean up recurlyClient.clearBillingInfo(accountData.getAccountCode()); recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testPagination() throws Exception { System.setProperty(RECURLY_PAGE_SIZE, "1"); final int minNumberOfAccounts = 5; for (int i = 0; i < minNumberOfAccounts; i++) { final Account accountData = TestUtils.createRandomAccount(); recurlyClient.createAccount(accountData); } final Set<String> accountCodes = new HashSet<String>(); Accounts accounts = recurlyClient.getAccounts(); for (int i = 0; i < minNumberOfAccounts; i++) { // If the environment is used, we will have more than the ones we created Assert.assertEquals(accounts.size(), 1); accountCodes.add(accounts.get(0).getAccountCode()); if (i < minNumberOfAccounts - 1) { accounts = accounts.getNext(); } } Assert.assertEquals(accountCodes.size(), minNumberOfAccounts); System.setProperty(RECURLY_PAGE_SIZE, "50"); }
@Test(groups = "integration") public void testGetAccountBalance() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); try { final Account account = recurlyClient.createAccount(accountData); // Create BillingInfo billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.assertNotNull(billingInfo); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); final Adjustment adjustment = new Adjustment(); adjustment.setUnitAmountInCents(150); adjustment.setCurrency(CURRENCY); recurlyClient.createAccountAdjustment(account.getAccountCode(), adjustment); final AccountBalance balance = recurlyClient.getAccountBalance(account.getAccountCode()); Assert.assertEquals(balance.getBalanceInCents().getUnitAmountUSD(), new Integer(150)); Assert.assertEquals(balance.getPastDue(), Boolean.FALSE); } finally { // Clean up recurlyClient.clearBillingInfo(accountData.getAccountCode()); recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testGetBillingInfo() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); billingInfoData.setAccount(null); // need to null out test account accountData.setBillingInfo(billingInfoData); try { // Create account and fetch billing info final Account account = recurlyClient.createAccount(accountData); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); Assert.assertEquals(retrievedBillingInfo.getType(), "credit_card"); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
final Account account = recurlyClient.createAccount(accountData);
@Test(groups = "integration") public void testGetBillingInfo() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); billingInfoData.setAccount(null); // need to null out test account accountData.setBillingInfo(billingInfoData); try { // Create account and fetch billing info final Account account = recurlyClient.createAccount(accountData); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); Assert.assertEquals(retrievedBillingInfo.getType(), "credit_card"); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testCreateAccountWithBadBillingInfo() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); // See http://docs.recurly.com/payment-gateways/test billingInfoData.setNumber("4000-0000-0000-0093"); try { final Account account = recurlyClient.createAccount(accountData); billingInfoData.setAccount(account); recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.fail("Should have thrown transaction exception"); } catch (TransactionErrorException e) { Assert.assertEquals(e.getErrors().getTransactionError().getErrorCode(), "fraud_ip_address"); Assert.assertEquals(e.getErrors().getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions."); Assert.assertEquals(e.getErrors().getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support."); } }
@Test(groups = "integration", description = "See https://github.com/killbilling/recurly-java-library/issues/21") public void testGetEmptySubscriptions() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); try { // Create a user final Account account = recurlyClient.createAccount(accountData); // Create BillingInfo billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.assertNotNull(billingInfo); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); final Subscriptions subs = recurlyClient.getAccountSubscriptions(accountData.getAccountCode(), "active"); Assert.assertEquals(subs.size(), 0); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration", description = "See https://github.com/killbilling/recurly-java-library/issues/21") public void testGetEmptySubscriptions() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); try { // Create a user final Account account = recurlyClient.createAccount(accountData); // Create BillingInfo billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.assertNotNull(billingInfo); final BillingInfo retrievedBillingInfo = recurlyClient.getBillingInfo(account.getAccountCode()); Assert.assertNotNull(retrievedBillingInfo); final Subscriptions subs = recurlyClient.getAccountSubscriptions(accountData.getAccountCode(), "active"); Assert.assertEquals(subs.size(), 0); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testCreateAccountWithBadBillingInfo() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); // See http://docs.recurly.com/payment-gateways/test billingInfoData.setNumber("4000-0000-0000-0093"); try { final Account account = recurlyClient.createAccount(accountData); billingInfoData.setAccount(account); recurlyClient.createOrUpdateBillingInfo(billingInfoData); Assert.fail("Should have thrown transaction exception"); } catch (TransactionErrorException e) { Assert.assertEquals(e.getErrors().getTransactionError().getErrorCode(), "fraud_ip_address"); Assert.assertEquals(e.getErrors().getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions."); Assert.assertEquals(e.getErrors().getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support."); } }
final Account account = recurlyClient.createAccount(accountData);
@Test(groups = "integration") public void testShippingAddressesOnAccount() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final ShippingAddress shippingAddress1 = TestUtils.createRandomShippingAddress(); final ShippingAddress shippingAddress2 = TestUtils.createRandomShippingAddress(); final ShippingAddresses shippingAddressesData = new ShippingAddresses(); try { shippingAddressesData.add(shippingAddress1); shippingAddressesData.add(shippingAddress2); accountData.setShippingAddresses(shippingAddressesData); final Account account = recurlyClient.createAccount(accountData); ShippingAddresses shippingAddresses = recurlyClient.getAccountShippingAddresses(account.getAccountCode()); Assert.assertEquals(shippingAddresses.size(), 2); } finally { recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testShippingAddressesOnAccount() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final ShippingAddress shippingAddress1 = TestUtils.createRandomShippingAddress(); final ShippingAddress shippingAddress2 = TestUtils.createRandomShippingAddress(); final ShippingAddresses shippingAddressesData = new ShippingAddresses(); try { shippingAddressesData.add(shippingAddress1); shippingAddressesData.add(shippingAddress2); accountData.setShippingAddresses(shippingAddressesData); final Account account = recurlyClient.createAccount(accountData); ShippingAddresses shippingAddresses = recurlyClient.getAccountShippingAddresses(account.getAccountCode()); Assert.assertEquals(shippingAddresses.size(), 2); } finally { recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testGetSiteSubscriptions() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); final Plan planData = TestUtils.createRandomPlan(); try { final Account account = recurlyClient.createAccount(accountData); billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); final Plan plan = recurlyClient.createPlan(planData); final Subscription subscriptionData = new Subscription(); subscriptionData.setPlanCode(plan.getPlanCode()); subscriptionData.setAccount(accountData); subscriptionData.setCurrency(CURRENCY); subscriptionData.setUnitAmountInCents(1242); subscriptionData.setRemainingBillingCycles(1); // makes sure we have at least one subscription recurlyClient.createSubscription(subscriptionData); // make sure we return more than one subscription Assert.assertTrue(recurlyClient.getSubscriptions().size() > 0); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
@Test(groups = "integration") public void testGetSiteSubscriptions() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); final Plan planData = TestUtils.createRandomPlan(); try { final Account account = recurlyClient.createAccount(accountData); billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData); final Plan plan = recurlyClient.createPlan(planData); final Subscription subscriptionData = new Subscription(); subscriptionData.setPlanCode(plan.getPlanCode()); subscriptionData.setAccount(accountData); subscriptionData.setCurrency(CURRENCY); subscriptionData.setUnitAmountInCents(1242); subscriptionData.setRemainingBillingCycles(1); // makes sure we have at least one subscription recurlyClient.createSubscription(subscriptionData); // make sure we return more than one subscription Assert.assertTrue(recurlyClient.getSubscriptions().size() > 0); } finally { // Close the account recurlyClient.closeAccount(accountData.getAccountCode()); } }
final Account account = recurlyClient.createAccount(accountData); final Plan plan = recurlyClient.createPlan(planData); final Coupon coupon = recurlyClient.createCoupon(couponData);
final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); try { final Account account = recurlyClient.createAccount(accountData);
@Test(groups = "integration") public void testShippingAddressesOnSubscription() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final Plan planData = TestUtils.createRandomPlan(CURRENCY); final ShippingAddress shippingAddressData = TestUtils.createRandomShippingAddress(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); billingInfoData.setAccount(null); // null out random account fixture accountData.setBillingInfo(billingInfoData); // add the billing info to account data try { final Account account = recurlyClient.createAccount(accountData); final Plan plan = recurlyClient.createPlan(planData); // Subscribe the user to the plan final Subscription subscriptionData = new Subscription(); // set our shipping address subscriptionData.setShippingAddress(shippingAddressData); // set our sub data subscriptionData.setPlanCode(plan.getPlanCode()); subscriptionData.setCurrency(CURRENCY); subscriptionData.setUnitAmountInCents(1242); // attach the account final Account existingAccount = new Account(); existingAccount.setAccountCode(account.getAccountCode()); subscriptionData.setAccount(existingAccount); final Subscription subscription = recurlyClient.createSubscription(subscriptionData); Assert.assertNotNull(subscription.getHref()); } finally { recurlyClient.closeAccount(accountData.getAccountCode()); recurlyClient.deletePlan(planData.getPlanCode()); } }
@Test(groups = "integration") public void testShippingAddressesOnSubscription() throws Exception { final Account accountData = TestUtils.createRandomAccount(); final Plan planData = TestUtils.createRandomPlan(CURRENCY); final ShippingAddress shippingAddressData = TestUtils.createRandomShippingAddress(); final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); billingInfoData.setAccount(null); // null out random account fixture accountData.setBillingInfo(billingInfoData); // add the billing info to account data try { final Account account = recurlyClient.createAccount(accountData); final Plan plan = recurlyClient.createPlan(planData); // Subscribe the user to the plan final Subscription subscriptionData = new Subscription(); // set our shipping address subscriptionData.setShippingAddress(shippingAddressData); // set our sub data subscriptionData.setPlanCode(plan.getPlanCode()); subscriptionData.setCurrency(CURRENCY); subscriptionData.setUnitAmountInCents(1242); // attach the account final Account existingAccount = new Account(); existingAccount.setAccountCode(account.getAccountCode()); subscriptionData.setAccount(existingAccount); final Subscription subscription = recurlyClient.createSubscription(subscriptionData); Assert.assertNotNull(subscription.getHref()); } finally { recurlyClient.closeAccount(accountData.getAccountCode()); recurlyClient.deletePlan(planData.getPlanCode()); } }