@Test(groups = "slow", description = "Test Account update with null values") public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(null, null, null, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final String newAddress1 = UUID.randomUUID().toString(); mutableAccountData.setAddress1(newAddress1); accountUserApi.updateAccount(account.getId(), mutableAccountData, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext); Assert.assertEquals(retrievedAccount.getAddress1(), newAddress1); Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2()); Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getExternalKey(), account.getExternalKey()); Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal()); }
@Test(groups = "slow", description = "Test Account create Parent and Child") public void testCreateParentAndChildAccounts() throws Exception { final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext); final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(parentAccount.getId()); childAccountModel.setIsPaymentDelegatedToParent(true); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); final Account retrievedChildAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertNotNull(retrievedChildAccount.getParentAccountId()); Assert.assertEquals(retrievedChildAccount.getId(), childAccount.getId()); Assert.assertEquals(retrievedChildAccount.getParentAccountId(), parentAccount.getId()); Assert.assertEquals(retrievedChildAccount.isPaymentDelegatedToParent(), childAccount.isPaymentDelegatedToParent()); }
childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext); Assert.assertEquals(childAccount1.getParentAccountId(), parentAccount.getId()); Assert.assertTrue(childAccount1.isPaymentDelegatedToParent()); childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); childAccount2 = accountUserApi.getAccountById(childAccount2.getId(), callContext); Assert.assertEquals(childAccount2.getParentAccountId(), parentAccount.getId()); Assert.assertTrue(childAccount2.isPaymentDelegatedToParent());
accountUserApi.updateAccount(newAccount, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext);
protected LocalDate toLocalDateDefaultToday(final UUID accountId, @Nullable final String inputDate, final TenantContext context) throws AccountApiException { final Account account = accountId != null ? accountUserApi.getAccountById(accountId, context) : null; return toLocalDateDefaultToday(account, inputDate, context); }
@TimedResource @GET @Path("/{invoiceItemId:" + UUID_PATTERN + "}/" + TAGS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve invoice item tags", response = TagJson.class, responseContainer = "List", nickname = "getInvoiceItemTags") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid invoice item id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getTags(@PathParam(ID_PARAM_NAME) final UUID id, @ApiParam(required=true) @QueryParam(QUERY_ACCOUNT_ID) final UUID accountId, @QueryParam(QUERY_TAGS_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException, AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); return super.getTags(account.getId(), id, auditMode, includedDeleted, tenantContext); }
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + OVERDUE) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve overdue state for account", response = OverdueStateJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getOverdueAccount(@PathParam("accountId") final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, OverdueException, OverdueApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final OverdueState overdueState = overdueApi.getOverdueStateFor(account.getId(), tenantContext); return Response.status(Status.OK).entity(new OverdueStateJson(overdueState, paymentConfig)).build(); }
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve an account by id", response = AccountJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getAccount(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); return Response.status(Status.OK).entity(accountJson).build(); }
@TimedResource @GET @Path("/{bundleId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a bundle by id", response = BundleJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found")}) public Response getBundle(@PathParam("bundleId") final UUID bundleId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException { final TenantContext tenantContext = this.context.createTenantContextNoAccountId(request); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, tenantContext); final Account account = accountUserApi.getAccountById(bundle.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext); final BundleJson json = new BundleJson(bundle, account.getCurrency(), accountAuditLogs); return Response.status(Status.OK).entity(json).build(); }
@TimedResource @GET @Path("/{subscriptionId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a subscription by id", response = SubscriptionJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Subscription not found")}) public Response getSubscription(@PathParam("subscriptionId") final UUID subscriptionId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException { final TenantContext context = this.context.createTenantContextNoAccountId(request); final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(subscriptionId, context); final Account account = accountUserApi.getAccountById(subscription.getAccountId(), context); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(subscription.getAccountId(), auditMode.getLevel(), context); final SubscriptionJson json = new SubscriptionJson(subscription, account.getCurrency(), accountAuditLogs); return Response.status(Status.OK).entity(json).build(); }
@TimedResource(name = "getPaymentMethod") @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a payment method by external key", response = PaymentMethodJson.class) @ApiResponses(value = {@ApiResponse(code = 404, message = "Account or payment method not found")}) public Response getPaymentMethodByKey(@ApiParam(required=true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final PaymentMethod paymentMethod = paymentApi.getPaymentMethodByExternalKey(externalKey, includedDeleted, withPluginInfo, pluginProperties, tenantContext); final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext); final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs); return Response.status(Status.OK).entity(json).build(); }
protected Account getAccount(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable { final AccountUserApi accountUserApi = getAccountUserApi(); try { return accountUserApi.getAccountById(accountId, context); } catch (final AccountApiException e) { logService.log(LogService.LOG_WARNING, "Error retrieving account for id " + accountId, e); throw new OSGIServiceNotAvailable(e); } }
@Override public PaymentMethodJson apply(final PaymentMethod paymentMethod) { // Cache audit logs per account if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) { accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext)); } // Lookup the associated account(s) if (accounts.get(paymentMethod.getAccountId()) == null) { final Account account; try { account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext); accounts.put(paymentMethod.getAccountId(), account); } catch (final AccountApiException e) { log.warn("Error retrieving accountId='{}'", paymentMethod.getAccountId(), e); return null; } } return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId())); } },
public Account addTestPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo, final Iterable<PluginProperty> pluginProperties) throws Exception { final UUID pmId = addTestPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME, account, paymentMethodInfo, pluginProperties); // To reflect the payment method id change return accountApi.getAccountById(account.getId(), context); }
protected Account createAccountWithNonOsgiPaymentMethod(final AccountData accountData) throws Exception { final Account account = createAccount(accountData); final PaymentMethodPlugin info = createPaymentMethodPlugin(); paymentApi.addPaymentMethod(account, UUID.randomUUID().toString(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, true, info, PLUGIN_PROPERTIES, callContext); return accountUserApi.getAccountById(account.getId(), callContext); }
protected Account createAccount(final AccountData accountData) throws Exception { final Account account = accountUserApi.createAccount(accountData, callContext); assertNotNull(account); refreshCallContext(account.getId()); return accountUserApi.getAccountById(account.getId(), callContext); }
protected Account getOrCreateAccount(final AccountJson accountJson, final CallContext callContext) throws AccountApiException { // Attempt to retrieve by accountId if specified if (accountJson.getAccountId() != null) { return accountUserApi.getAccountById(accountJson.getAccountId(), callContext); } if (accountJson.getExternalKey() != null) { // Attempt to retrieve by account externalKey, ignore if does not exist so we can create it with the key specified. try { return accountUserApi.getAccountByKey(accountJson.getExternalKey(), callContext); } catch (final AccountApiException ignore) { } } // Finally create if does not exist return accountUserApi.createAccount(accountJson.toAccount(null), callContext); }
private Account getAccountFromSubscriptionJson(final SubscriptionJson entitlementJson, final CallContext callContext) throws SubscriptionApiException, AccountApiException, EntitlementApiException { final UUID accountId; if (entitlementJson.getAccountId() != null) { accountId = entitlementJson.getAccountId(); } else if (entitlementJson.getSubscriptionId() != null) { final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementJson.getSubscriptionId(), callContext); accountId = entitlement.getAccountId(); } else { final SubscriptionBundle subscriptionBundle = subscriptionApi.getSubscriptionBundle(entitlementJson.getBundleId(), callContext); accountId = subscriptionBundle.getAccountId(); } return accountUserApi.getAccountById(accountId, callContext); } }
public Account checkAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws Exception { final Account account = accountApi.getAccountById(accountId, context); // Not all test pass it, since this is always the same test if (accountData != null) { Assert.assertEquals(account.getName(), accountData.getName()); Assert.assertEquals(account.getFirstNameLength(), accountData.getFirstNameLength()); Assert.assertEquals(account.getEmail(), accountData.getEmail()); Assert.assertEquals(account.getPhone(), accountData.getPhone()); Assert.assertEquals(account.getExternalKey(), accountData.getExternalKey()); Assert.assertEquals(account.getBillCycleDayLocal(), accountData.getBillCycleDayLocal()); Assert.assertEquals(account.getCurrency(), accountData.getCurrency()); Assert.assertEquals(account.getTimeZone(), accountData.getTimeZone()); // createWithPaymentMethod will update the paymentMethod //Assert.assertEquals(account.getPaymentMethodId(), accountData.getPaymentMethodId()); } auditChecker.checkAccountCreated(account, context); return account; } }
private Response chargebackReversalPaymentInternal(final PaymentTransactionJson json, @Nullable final UUID paymentId, final List<String> paymentControlPluginNames, final List<String> pluginPropertiesString, final String createdBy, final String reason, final String comment, final UriInfo uriInfo, final HttpServletRequest request) throws PaymentApiException, AccountApiException { verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified"); verifyNonNullOrEmpty(json.getTransactionExternalKey(), "PaymentTransactionJson transactionExternalKey needs to be set"); final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request); final Payment initialPayment = getPaymentByIdOrKey(paymentId, json.getPaymentExternalKey(), pluginProperties, callContext); final Account account = accountUserApi.getAccountById(initialPayment.getAccountId(), callContext); final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames); final Payment payment = paymentApi.createChargebackReversalWithPaymentControl(account, initialPayment.getId(), json.getEffectiveDate(), json.getTransactionExternalKey(), paymentOptions, callContext); return createPaymentResponse(uriInfo, payment, TransactionType.CHARGEBACK, json.getTransactionExternalKey(), request); }