예제 #1
0
    @Override
    public void onSubscriptionBaseTransition(final EffectiveSubscriptionInternalEvent event) {

      log.info(
          String.format(
              "Got event SubscriptionBaseTransition token = %s, type = %s, remaining = %d ",
              event.getUserToken(),
              event.getTransitionType(),
              event.getRemainingEventsForUserOperation()));
    }
  private void addBillingEventsForSubscription(
      final List<SubscriptionBase> subscriptions,
      final SubscriptionBaseBundle bundle,
      final Account account,
      final InternalCallContext context,
      final DefaultBillingEventSet result) {

    boolean updatedAccountBCD = false;
    for (final SubscriptionBase subscription : subscriptions) {
      for (final EffectiveSubscriptionInternalEvent transition :
          subscriptionApi.getBillingTransitions(subscription, context)) {
        try {
          final int bcdLocal =
              bcdCalculator.calculateBcd(bundle, subscription, transition, account, context);

          if (account.getBillCycleDayLocal() == 0 && !updatedAccountBCD) {
            final MutableAccountData modifiedData = account.toMutableAccountData();
            modifiedData.setBillCycleDayLocal(bcdLocal);
            accountApi.updateAccount(account.getExternalKey(), modifiedData, context);
            updatedAccountBCD = true;
          }

          final BillingEvent event =
              new DefaultBillingEvent(
                  account,
                  transition,
                  subscription,
                  bcdLocal,
                  account.getCurrency(),
                  catalogService.getFullCatalog());
          result.add(event);
        } catch (CatalogApiException e) {
          log.error(
              "Failing to identify catalog components while creating BillingEvent from transition: "
                  + transition.getId().toString(),
              e);
        } catch (Exception e) {
          log.warn("Failed while getting BillingEvent", e);
        }
      }
    }
  }