@Test(groups = "slow") public void testUnknownEntriesWithExceptions() throws PaymentApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "minus"; final String transactionExternalKey = "plus"; // Make sure the state as seen by the plugin will be in PaymentPluginStatus.ERROR, which will be // returned later to Janitor mockPaymentProviderPlugin.makeNextPaymentFailWithException(); try { paymentApi.createAuthorization( account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); } catch (PaymentApiException ignore) { } final Payment payment = paymentApi.getPaymentByExternalKey( paymentExternalKey, false, ImmutableList.<PluginProperty>of(), callContext); // Artificially move the transaction status to UNKNOWN final String paymentStateName = paymentSMHelper.getErroredStateForTransaction(TransactionType.AUTHORIZE).toString(); paymentDao.updatePaymentAndTransactionOnCompletion( account.getId(), payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.UNKNOWN, requestedAmount, account.getCurrency(), "foo", "bar", internalCallContext); final List<PaymentTransactionModelDao> paymentTransactionHistoryBeforeJanitor = getPaymentTransactionHistory(transactionExternalKey); Assert.assertEquals(paymentTransactionHistoryBeforeJanitor.size(), 3); clock.addDays(1); try { Thread.sleep(1500); } catch (InterruptedException e) { } // Nothing new happened final List<PaymentTransactionModelDao> paymentTransactionHistoryAfterJanitor = getPaymentTransactionHistory(transactionExternalKey); Assert.assertEquals(paymentTransactionHistoryAfterJanitor.size(), 3); }
public PaymentTransaction getCurrentTransaction() { if (result == null || result.getTransactions() == null) { return null; } return Iterables.tryFind( result.getTransactions(), new Predicate<PaymentTransaction>() { @Override public boolean apply(final PaymentTransaction input) { return ((DefaultPaymentTransaction) input).getAttemptId().equals(attemptId); } }) .orNull(); }
protected Map<UUID, List<InvoicePayment>> getAccountInvoicePayments( final Iterable<Payment> payments, final TenantContext context) throws AnalyticsRefreshException { final InvoicePaymentApi invoicePaymentApi = getInvoicePaymentUserApi(); final Map<UUID, List<InvoicePayment>> allInvoicePaymentsByPaymentId = new HashMap<UUID, List<InvoicePayment>>(); for (final Payment payment : payments) { // Retrieve all invoice payment types (including refunds and chargebacks) for that payment allInvoicePaymentsByPaymentId.put( payment.getId(), invoicePaymentApi.getInvoicePayments(payment.getId(), context)); } return allInvoicePaymentsByPaymentId; }
@Test(groups = "slow") public void testUnknownEntries() throws PaymentApiException, InvoiceApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "qwru"; final String transactionExternalKey = "lkjdsf"; final Payment payment = paymentApi.createAuthorization( account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); // Artificially move the transaction status to UNKNOWN final String paymentStateName = paymentSMHelper.getErroredStateForTransaction(TransactionType.AUTHORIZE).toString(); paymentDao.updatePaymentAndTransactionOnCompletion( account.getId(), payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.UNKNOWN, requestedAmount, account.getCurrency(), "foo", "bar", internalCallContext); // The UnknownPaymentTransactionTask will look for UNKNOWN payment that *just happened* , and // that are not too old (less than 7 days) clock.addDays(1); try { Thread.sleep(1500); } catch (InterruptedException e) { } final Payment updatedPayment = paymentApi.getPayment( payment.getId(), false, ImmutableList.<PluginProperty>of(), callContext); assertEquals( updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); }
@Test(groups = "slow") public void testPendingEntries() throws PaymentApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "jhj44"; final String transactionExternalKey = "4jhjj2"; final Payment payment = paymentApi.createAuthorization( account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); // Artificially move the transaction status to PENDING final String paymentStateName = paymentSMHelper.getPendingStateForTransaction(TransactionType.AUTHORIZE).toString(); paymentDao.updatePaymentAndTransactionOnCompletion( account.getId(), payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.PENDING, requestedAmount, account.getCurrency(), "loup", "chat", internalCallContext); clock.addDays(1); try { Thread.sleep(1500); } catch (InterruptedException e) { } final Payment updatedPayment = paymentApi.getPayment( payment.getId(), false, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals( updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); }
@Test(groups = "slow") public void testCreateSuccessRefundPaymentControlWithItemAdjustments() throws PaymentApiException, InvoiceApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final UUID subscriptionId = UUID.randomUUID(); final UUID bundleId = UUID.randomUUID(); final LocalDate now = clock.getUTCToday(); final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD); final String paymentExternalKey = invoice.getId().toString(); final String transactionExternalKey = "craboom"; final String transactionExternalKey2 = "qwerty"; final InvoiceItem invoiceItem = new MockRecurringInvoiceItem( invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), requestedAmount, new BigDecimal("1.0"), Currency.USD); invoice.addInvoiceItem(invoiceItem); final Payment payment = paymentApi.createPurchaseWithPaymentControl( account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); final List<PluginProperty> refundProperties = new ArrayList<PluginProperty>(); final HashMap<UUID, BigDecimal> uuidBigDecimalHashMap = new HashMap<UUID, BigDecimal>(); uuidBigDecimalHashMap.put(invoiceItem.getId(), new BigDecimal("1.0")); final PluginProperty refundIdsProp = new PluginProperty( InvoicePaymentRoutingPluginApi.PROP_IPCD_REFUND_IDS_WITH_AMOUNT_KEY, uuidBigDecimalHashMap, false); refundProperties.add(refundIdsProp); final Payment payment2 = paymentApi.createRefundWithPaymentControl( account, payment.getId(), null, Currency.USD, transactionExternalKey2, refundProperties, INVOICE_PAYMENT, callContext); assertEquals(payment2.getTransactions().size(), 2); PaymentTransaction refundTransaction = payment2.getTransactions().get(1); assertEquals(refundTransaction.getTransactionType(), TransactionType.REFUND); final List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttempts(paymentExternalKey, internalCallContext); assertEquals(attempts.size(), 2); final PaymentAttemptModelDao refundAttempt = attempts.get(1); assertEquals(refundAttempt.getTransactionType(), TransactionType.REFUND); // Ok now the fun part starts... we modify the attempt state to be 'INIT' and wait the the // Janitor to do its job. paymentDao.updatePaymentAttempt( refundAttempt.getId(), refundAttempt.getTransactionId(), "INIT", internalCallContext); final PaymentAttemptModelDao attempt2 = paymentDao.getPaymentAttempt(refundAttempt.getId(), internalCallContext); assertEquals(attempt2.getStateName(), "INIT"); clock.addDays(1); try { Thread.sleep(1500); } catch (InterruptedException e) { } final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(refundAttempt.getId(), internalCallContext); assertEquals(attempt3.getStateName(), "SUCCESS"); }
@Test(groups = "slow") public void testCreateSuccessPurchaseWithPaymentControl() throws PaymentApiException, InvoiceApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final UUID subscriptionId = UUID.randomUUID(); final UUID bundleId = UUID.randomUUID(); final LocalDate now = clock.getUTCToday(); final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD); final String paymentExternalKey = invoice.getId().toString(); final String transactionExternalKey = "wouf wouf"; invoice.addInvoiceItem( new MockRecurringInvoiceItem( invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), requestedAmount, new BigDecimal("1.0"), Currency.USD)); final Payment payment = paymentApi.createPurchaseWithPaymentControl( account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); assertEquals(payment.getTransactions().size(), 1); assertEquals( payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE); final List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttempts(paymentExternalKey, internalCallContext); assertEquals(attempts.size(), 1); final PaymentAttemptModelDao attempt = attempts.get(0); assertEquals(attempt.getStateName(), "SUCCESS"); // Ok now the fun part starts... we modify the attempt state to be 'INIT' and wait the the // Janitor to do its job. paymentDao.updatePaymentAttempt( attempt.getId(), attempt.getTransactionId(), "INIT", internalCallContext); final PaymentAttemptModelDao attempt2 = paymentDao.getPaymentAttempt(attempt.getId(), internalCallContext); assertEquals(attempt2.getStateName(), "INIT"); clock.addDays(1); try { Thread.sleep(1500); } catch (InterruptedException e) { } final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(attempt.getId(), internalCallContext); assertEquals(attempt3.getStateName(), "SUCCESS"); }