/** * Update an account's billing info * <p> * When new or updated credit card information is updated, the billing information is only saved if the credit card * is valid. If the account has a past due invoice, the outstanding balance will be collected to validate the * billing information. * <p> * If the account does not exist before the API request, the account will be created if the billing information * is valid. * <p> * Please note: this API end-point may be used to import billing information without security codes (CVV). * Recurly recommends requiring CVV from your customers when collecting new or updated billing information. * * @param billingInfo billing info object to create or update * @return the newly created or update billing info object on success, null otherwise */ public BillingInfo createOrUpdateBillingInfo(final BillingInfo billingInfo) { final String accountCode = billingInfo.getAccount().getAccountCode(); // Unset it to avoid confusing Recurly billingInfo.setAccount(null); return doPUT(Account.ACCOUNT_RESOURCE + "/" + accountCode + BillingInfo.BILLING_INFO_RESOURCE, billingInfo, BillingInfo.class); }
@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 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."); } }
@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 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()); } }
final BillingInfo billingInfoData = TestUtils.createRandomBillingInfo(); final Plan planData = TestUtils.createRandomPlan(); billingInfoData.setAccount(null); accountData.setBillingInfo(billingInfoData); try {
final Account accountData = TestUtils.createRandomAccount(); accountData.setBillingInfo(billingInfoData); billingInfoData.setAccount(null); // prevents double-POSTing account data inside billing_info accountData.setCustomFields(accountFields); try {
@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()); } }
/** * Creates a random {@link GiftCard} object for use in Tests given a seed * * @param seed The RNG seed * @return The random {@link GiftCard} object */ public static GiftCard createRandomGiftCard(final int seed) { final GiftCard giftCardData = new GiftCard(); final Account accountData = createRandomAccount(seed); final Delivery deliveryData = createRandomDelivery(seed); final BillingInfo billingInfoData = createRandomBillingInfo(seed); // need to null out account // TODO - account should not be writeable in XML billingInfoData.setAccount(null); accountData.setBillingInfo(billingInfoData); // Gift card product needs to be created on the site with // product code "test_gift_card" giftCardData.setGifterAccount(accountData); giftCardData.setDelivery(deliveryData); giftCardData.setCurrency("USD"); giftCardData.setProductCode("test_gift_card"); giftCardData.setUnitAmountInCents(2000); return giftCardData; }
/** * Creates a random {@link GiftCard} object for use in Tests given a seed * * @param seed The RNG seed * @return The random {@link GiftCard} object */ public static GiftCard createRandomGiftCard(final int seed) { final GiftCard giftCardData = new GiftCard(); final Account accountData = createRandomAccount(seed); final Delivery deliveryData = createRandomDelivery(seed); final BillingInfo billingInfoData = createRandomBillingInfo(seed); // need to null out account // TODO - account should not be writeable in XML billingInfoData.setAccount(null); accountData.setBillingInfo(billingInfoData); // Gift card product needs to be created on the site with // product code "test_gift_card" giftCardData.setGifterAccount(accountData); giftCardData.setDelivery(deliveryData); giftCardData.setCurrency("USD"); giftCardData.setProductCode("test_gift_card"); giftCardData.setUnitAmountInCents(2000); return giftCardData; }
final Account account = recurlyClient.createAccount(accountData); billingInfoData.setAccount(account); final BillingInfo billingInfo = recurlyClient.createOrUpdateBillingInfo(billingInfoData);
@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()); } }
/** * Creates a random {@link com.ning.billing.recurly.model.BillingInfo} object for testing use given a seed * * @param seed The RNG seed * @return The random {@link com.ning.billing.recurly.model.BillingInfo} object */ public static BillingInfo createRandomBillingInfo(final int seed) { final BillingInfo info = new BillingInfo(); info.setAccount(createRandomAccount(seed)); info.setFirstName(randomAlphaNumericString(5, seed)); info.setLastName(randomAlphaNumericString(6, seed)); info.setCompany(randomAlphaNumericString(10, seed)); info.setAddress1(randomAlphaNumericString(10, seed)); info.setAddress2(randomAlphaNumericString(10, seed)); info.setCity(randomAlphaNumericString(10, seed)); info.setState("CA"); info.setZip("94110"); info.setCountry("US"); info.setPhone(randomInteger(8, seed)); info.setVatNumber(randomNumericString(8, seed)); info.setYear(createTestCCYear()); info.setMonth(createTestCCMonth()); info.setNumber(createTestCCNumber()); info.setVerificationValue(createTestCCVerificationNumber()); return info; }
/** * Creates a random {@link com.ning.billing.recurly.model.BillingInfo} object for testing use given a seed * * @param seed The RNG seed * @return The random {@link com.ning.billing.recurly.model.BillingInfo} object */ public static BillingInfo createRandomBillingInfo(final int seed) { final BillingInfo info = new BillingInfo(); info.setAccount(createRandomAccount(seed)); info.setFirstName(randomAlphaNumericString(5, seed)); info.setLastName(randomAlphaNumericString(6, seed)); info.setCompany(randomAlphaNumericString(10, seed)); info.setAddress1(randomAlphaNumericString(10, seed)); info.setAddress2(randomAlphaNumericString(10, seed)); info.setCity(randomAlphaNumericString(10, seed)); info.setState("CA"); info.setZip("94110"); info.setCountry("US"); info.setPhone(randomInteger(8, seed)); info.setVatNumber(randomNumericString(8, seed)); info.setYear(createTestCCYear()); info.setMonth(createTestCCMonth()); info.setNumber(createTestCCNumber()); info.setVerificationValue(createTestCCVerificationNumber()); return info; }