private void processEntitlementNotification(final EntitlementNotificationKey key, final UUID tenantId, final InternalCallContext internalCallContext) { final Entitlement entitlement; try { entitlement = entitlementApi.getEntitlementForId(key.getEntitlementId(), internalCallContext.toTenantContext(tenantId)); } catch (final EntitlementApiException e) { log.error("Error retrieving entitlement for id " + key.getEntitlementId(), e); return; } if (!(entitlement instanceof DefaultEntitlement)) { log.error("Entitlement service received an unexpected entitlement class type {}" + entitlement.getClass().getName()); return; } final EntitlementNotificationKeyAction entitlementNotificationKeyAction = key.getEntitlementNotificationKeyAction(); try { if (EntitlementNotificationKeyAction.CHANGE.equals(entitlementNotificationKeyAction) || EntitlementNotificationKeyAction.CANCEL.equals(entitlementNotificationKeyAction)) { ((DefaultEntitlement) entitlement).blockAddOnsIfRequired(key.getEffectiveDate(), internalCallContext.toTenantContext(tenantId), internalCallContext); } else if (EntitlementNotificationKeyAction.PAUSE.equals(entitlementNotificationKeyAction)) { entitlementApi.pause(key.getBundleId(), key.getEffectiveDate().toLocalDate(), internalCallContext.toCallContext(tenantId)); } else if (EntitlementNotificationKeyAction.RESUME.equals(entitlementNotificationKeyAction)) { entitlementApi.resume(key.getBundleId(), key.getEffectiveDate().toLocalDate(), internalCallContext.toCallContext(tenantId)); } } catch (final EntitlementApiException e) { log.error("Error processing event for entitlement {}" + entitlement.getId(), e); } }
for (final Entitlement cur : toBeCancelled) { try { cur.cancelEntitlementWithDateOverrideBillingPolicy(new LocalDate(clock.getUTCNow(), account.getTimeZone()), actionPolicy, context.toCallContext(tenantId)); } catch (EntitlementApiException e) {
final List<PaymentMethodInfoPlugin> pluginPms; try { pluginPms = pluginApi.getPaymentMethods(account.getId(), true, context.toCallContext(tenantId));
pluginApi.deletePaymentMethod(account.getId(), paymentMethodId, context.toCallContext(tenantId)); paymentDao.deletedPaymentMethod(paymentMethodId, context); return null;
@Override public Void doOperation() throws PaymentApiException { final PaymentMethodModelDao paymentMethodModel = paymentDao.getPaymentMethod(paymentMethodId, context); if (paymentMethodModel == null) { throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_METHOD, paymentMethodId); } try { final PaymentPluginApi pluginApi = getPluginApi(paymentMethodId, context); pluginApi.setDefaultPaymentMethod(account.getId(), paymentMethodId, context.toCallContext(tenantId)); accountInternalApi.updatePaymentMethod(account.getId(), paymentMethodId, context); return null; } catch (PaymentPluginApiException e) { throw new PaymentApiException(ErrorCode.PAYMENT_UPD_PAYMENT_METHOD, account.getId(), e.getErrorMessage()); } catch (AccountApiException e) { throw new PaymentApiException(e); } } });
@Override public UUID doOperation() throws PaymentApiException { PaymentMethod pm = null; PaymentPluginApi pluginApi = null; try { pluginApi = getPaymentPluginApi(paymentPluginServiceName); pm = new DefaultPaymentMethod(account.getId(), paymentPluginServiceName, paymentMethodProps); pluginApi.addPaymentMethod(account.getId(), pm.getId(), paymentMethodProps, setDefault, context.toCallContext(tenantId)); final PaymentMethodModelDao pmModel = new PaymentMethodModelDao(pm.getId(), pm.getCreatedDate(), pm.getUpdatedDate(), pm.getAccountId(), pm.getPluginName(), pm.isActive()); paymentDao.insertPaymentMethod(pmModel, context); if (setDefault) { accountInternalApi.updatePaymentMethod(account.getId(), pm.getId(), context); } } catch (PaymentPluginApiException e) { log.warn("Error adding payment method " + pm.getId() + " for plugin " + paymentPluginServiceName, e); // STEPH all errors should also take a pluginName throw new PaymentApiException(ErrorCode.PAYMENT_ADD_PAYMENT_METHOD, account.getId(), e.getErrorMessage()); } catch (AccountApiException e) { throw new PaymentApiException(e); } return pm.getId(); } });
try { paymentPluginInfo = plugin.processPayment(account.getId(), paymentInput.getId(), attemptInput.getPaymentMethodId(), attemptInput.getRequestedAmount(), account.getCurrency(), context.toCallContext(tenantId)); } catch (RuntimeException e) {
final RefundInfoPlugin refundInfoPlugin = plugin.processRefund(account.getId(), paymentId, refundAmount, account.getCurrency(), context.toCallContext(tenantId));