private int getMaxRetrySizeForFailureType(final FailureType failureType) { if (failureType == FailureType.PAYMENT_FAILURE) { return paymentConfig.getPaymentRetryDays().size(); } else { return paymentConfig.getPluginFailureRetryMaxAttempts(); } } }
@Inject public DefaultPaymentProviderPluginRegistry(final PaymentConfig config) { this.defaultPlugin = config.getDefaultPaymentProvider(); }
protected void installProcessors(final PaymentConfig paymentConfig) { final ExecutorService pluginExecutorService = Executors.newFixedThreadPool(paymentConfig.getPaymentPluginThreadNb(), new ThreadFactory() { @Override public Thread newThread(final Runnable r) { final Thread th = new Thread(r); th.setName(PLUGIN_THREAD_PREFIX + th.getId()); return th; } }); bind(ExecutorService.class).annotatedWith(Names.named(PLUGIN_EXECUTOR_NAMED)).toInstance(pluginExecutorService); bind(PaymentProcessor.class).asEagerSingleton(); bind(RefundProcessor.class).asEagerSingleton(); bind(PaymentMethodProcessor.class).asEagerSingleton(); }
private DateTime getNextRetryDate(final int retryAttempt) { if (retryAttempt > config.getPluginFailureRetryMaxAttempts()) { return null; } int nbSec = config.getPluginFailureRetryStart(); int remainingAttempts = retryAttempt; while (--remainingAttempts > 0) { nbSec = nbSec * config.getPluginFailureRetryMultiplier(); } return clock.getUTCNow().plusSeconds(nbSec); } }
private DateTime getNextRetryDate(final int retryAttempt) { DateTime result = null; final List<Integer> retryDays = config.getPaymentRetryDays(); final int retryCount = retryAttempt - 1; if (retryCount < retryDays.size()) { int retryInDays = 0; final DateTime nextRetryDate = clock.getUTCNow(); try { retryInDays = retryDays.get(retryCount); result = nextRetryDate.plusDays(retryInDays); } catch (NumberFormatException ex) { log.error("Could not get retry day for retry count {}", retryCount); } } return result; }
@Test(groups = "fast") public void testFailedPpluginWithLastRetrySuccess() throws Exception { testSchedulesRetryInternal(paymentConfig.getPluginFailureRetryMaxAttempts(), FailureType.PLUGIN_EXCEPTION); }
@Inject public PaymentProcessor(final OSGIServiceRegistration<PaymentPluginApi> pluginRegistry, final PaymentMethodProcessor paymentMethodProcessor, final AccountInternalApi accountUserApi, final InvoiceInternalApi invoiceApi, final TagInternalApi tagUserApi, final FailedPaymentRetryServiceScheduler failedPaymentRetryService, final PluginFailureRetryServiceScheduler pluginFailureRetryService, final AutoPayRetryServiceScheduler autoPayoffRetryService, final PaymentDao paymentDao, final NonEntityDao nonEntityDao, final PersistentBus eventBus, final Clock clock, final GlobalLocker locker, final PaymentConfig paymentConfig, @Named(PLUGIN_EXECUTOR_NAMED) final ExecutorService executor) { super(pluginRegistry, accountUserApi, eventBus, paymentDao, nonEntityDao, tagUserApi, locker, executor, invoiceApi); this.paymentMethodProcessor = paymentMethodProcessor; this.failedPaymentRetryService = failedPaymentRetryService; this.pluginFailureRetryService = pluginFailureRetryService; this.autoPayoffRetryService = autoPayoffRetryService; this.clock = clock; this.paymentConfig = paymentConfig; final long paymentPluginTimeoutSec = TimeUnit.SECONDS.convert(paymentConfig.getPaymentPluginTimeout().getPeriod(), paymentConfig.getPaymentPluginTimeout().getUnit()); this.paymentPluginDispatcher = new PluginDispatcher<Payment>(paymentPluginTimeoutSec, executor); this.voidPluginDispatcher = new PluginDispatcher<Void>(paymentPluginTimeoutSec, executor); }
if (paymentConfig.isPaymentOff()) { paymentDao.updatePaymentAndAttemptOnCompletion(paymentInput.getId(), PaymentStatus.PAYMENT_SYSTEM_OFF, attemptInput.getRequestedAmount(), account.getCurrency(), attemptInput.getId(), null, null, context);
@Test(groups = "fast") public void testFailedPaymentWithLastRetrySuccess() throws Exception { testSchedulesRetryInternal(paymentConfig.getPaymentRetryDays().size(), FailureType.PAYMENT_FAILURE); }
@Test(groups = "fast") public void testAbortedPlugin() throws Exception { testSchedulesRetryInternal(paymentConfig.getPluginFailureRetryMaxAttempts() + 1, FailureType.PLUGIN_EXCEPTION); }
@Test(groups = "fast") public void testAbortedPayment() throws Exception { testSchedulesRetryInternal(paymentConfig.getPaymentRetryDays().size() + 1, FailureType.PAYMENT_FAILURE); }
private void moveClockForFailureType(final FailureType failureType, final int curFailure) { if (failureType == FailureType.PAYMENT_FAILURE) { final int nbDays = paymentConfig.getPaymentRetryDays().get(curFailure); clock.addDays(nbDays + 1); } else { clock.addDays(1); } }