@Test(groups = "slow") public void testSimpleAuthCaptureWithInvalidPaymentId() throws Exception { final BigDecimal requestedAmount = new BigDecimal("80.0091"); final Payment initialPayment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.createCapture(account, UUID.randomUUID(), requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Expected capture to fail..."); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_NO_SUCH_PAYMENT.getCode()); final Payment latestPayment = paymentApi.getPayment(initialPayment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(latestPayment, initialPayment); } }
@Test(groups = "slow") public void testCreateAuthPendingWithControlCompleteNoControl() throws PaymentApiException { final String paymentTransactionExternalKey = UUID.randomUUID().toString(); final BigDecimal requestedAmount = BigDecimal.TEN; final Iterable<PluginProperty> pendingPluginProperties = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PENDING, false)); Payment payment = paymentApi.createAuthorizationWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), paymentTransactionExternalKey, pendingPluginProperties, PAYMENT_OPTIONS, callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getTransactions().size(), 1); Assert.assertNotNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); verifyOnSuccess(payment.getId(), payment.getExternalKey(), payment.getTransactions().get(0).getId(), payment.getTransactions().get(0).getExternalKey(), requestedAmount, Currency.USD); payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), payment.getId(), requestedAmount, payment.getCurrency(), null,payment.getExternalKey(), payment.getTransactions().get(0).getExternalKey(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getTransactions().size(), 1); Assert.assertNotNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); Assert.assertEquals(payment.getTransactions().get(0).getExternalKey(), paymentTransactionExternalKey); }
final Iterable<PluginProperty> pendingPluginProperties = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.UNDEFINED, false)); Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), paymentTransactionExternalKey, pendingPluginProperties, callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0);
@Test(groups = "slow") public void testSimpleAuthCaptureWithInvalidCurrency() throws Exception { final BigDecimal requestedAmount = new BigDecimal("80.0091"); final Payment initialPayment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.createCapture(account, initialPayment.getId(), requestedAmount, Currency.AMD, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Expected capture to fail..."); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_PARAMETER.getCode()); final Payment latestPayment = paymentApi.getPayment(initialPayment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(latestPayment, initialPayment); } }
@Test(groups = "slow") public void testCreateAuthPendingNoControlCompleteWithControl() throws PaymentApiException { final String paymentTransactionExternalKey = UUID.randomUUID().toString(); final BigDecimal requestedAmount = BigDecimal.TEN; final Iterable<PluginProperty> pendingPluginProperties = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PENDING, false)); Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), paymentTransactionExternalKey, pendingPluginProperties, callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getTransactions().size(), 1); Assert.assertNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); payment = paymentApi.createAuthorizationWithPaymentControl(account, payment.getPaymentMethodId(), payment.getId(), requestedAmount, payment.getCurrency(), null,payment.getExternalKey(), payment.getTransactions().get(0).getExternalKey(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getTransactions().size(), 1); Assert.assertNotNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); Assert.assertEquals(payment.getTransactions().get(0).getExternalKey(), paymentTransactionExternalKey); verifyPriorAndOnSuccess(payment.getId(), payment.getExternalKey(), payment.getTransactions().get(0).getId(), payment.getTransactions().get(0).getExternalKey(), requestedAmount, Currency.USD); }
@Override public Payment execute() throws Throwable { // Shouldn't happen in practice, but it's just to verify the behavior assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RO_ALLOWED); final BigDecimal requestedAmount = BigDecimal.TEN; testListener.pushExpectedEvent(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus(); // Thread switch, RW by default assertEquals(mockPaymentProviderPlugin.getLastThreadState(), THREAD_STATE.RW_ONLY); // Switched to RW, because of RW DAO call assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RW_ONLY); return payment; } });
payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), payment.getId(), requestedAmount, payment.getCurrency(), null,payment.getExternalKey(), payment.getTransactions().get(0).getExternalKey(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail();
@Test(groups = "slow") public void testCreateAuthNoControlCaptureWithControl() throws PaymentApiException { final BigDecimal requestedAmount = BigDecimal.TEN; Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); Assert.assertEquals(payment.getTransactions().size(), 1); Assert.assertNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); payment = paymentApi.createCaptureWithPaymentControl(account, payment.getId(), payment.getAuthAmount(), payment.getCurrency(), null,UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0); Assert.assertEquals(payment.getCapturedAmount().compareTo(requestedAmount), 0); Assert.assertEquals(payment.getTransactions().size(), 2); Assert.assertNull(((DefaultPaymentTransaction) payment.getTransactions().get(0)).getAttemptId()); Assert.assertNotNull(((DefaultPaymentTransaction) payment.getTransactions().get(1)).getAttemptId()); verifyOnSuccessForFollowOnTransaction(payment.getId(), payment.getExternalKey(), payment.getTransactions().get(1).getId(), payment.getTransactions().get(1).getExternalKey(), requestedAmount, Currency.USD); }
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/551") public void testFixPaymentTransactionStateNoPaymentTransactionInfoPlugin() throws PaymentApiException { final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); final PaymentModelDao paymentModelDao = paymentDao.getPayment(payment.getId(), internalCallContext); final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(payment.getTransactions().get(0).getId(), internalCallContext); Assert.assertEquals(paymentModelDao.getStateName(), "AUTH_SUCCESS"); Assert.assertEquals(paymentModelDao.getLastSuccessStateName(), "AUTH_SUCCESS"); Assert.assertEquals(paymentTransactionModelDao.getTransactionStatus(), TransactionStatus.SUCCESS); Assert.assertEquals(paymentTransactionModelDao.getProcessedAmount().compareTo(BigDecimal.TEN), 0); Assert.assertEquals(paymentTransactionModelDao.getProcessedCurrency(), Currency.EUR); Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorCode(), ""); Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorMsg(), ""); try { // Since no transaction status is passed, PaymentTransactionInfoPlugin should be set adminPaymentApi.fixPaymentTransactionState(payment, Mockito.mock(DefaultPaymentTransaction.class), null, null, "AUTH_ERRORED", ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_PARAMETER.getCode()); } }
final BigDecimal requestedAmount = BigDecimal.TEN; Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0);
final BigDecimal requestedAmount = BigDecimal.TEN; Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0);
final BigDecimal requestedAmount = BigDecimal.TEN; Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0);
@Test(groups = "slow") public void testInvalidTransitionAfterFailure() throws PaymentApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "krapo"; final String transactionExternalKey = "grenouye"; final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.EUR, null,paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); // Hack the Database to make it look like it was a failure paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, "AUTH_ERRORED", null, payment.getTransactions().get(0).getId(), TransactionStatus.PLUGIN_FAILURE, null, null, null, null, internalCallContext); final PaymentSqlDao paymentSqlDao = dbi.onDemand(PaymentSqlDao.class); paymentSqlDao.updateLastSuccessPaymentStateName(payment.getId().toString(), "AUTH_ERRORED", null, internalCallContext); try { paymentApi.createCapture(account, payment.getId(), requestedAmount, Currency.EUR, null, "tetard", ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Unexpected success"); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_OPERATION.getCode()); } }
final BigDecimal requestedAmount = BigDecimal.TEN; Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null,UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payment.getAuthAmount().compareTo(requestedAmount), 0);
final String transactionExternalKey4 = "sioux4"; final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, authAmount, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext);
try { testListener.pushExpectedEvent(NextEvent.PAYMENT_PLUGIN_ERROR); paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); } catch (PaymentApiException ignore) {
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus();
@Test(groups = "slow") public void testUnknownEntries() throws PaymentApiException, InvoiceApiException, EventBusException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "qwru"; final String transactionExternalKey = "lkjdsf"; testListener.pushExpectedEvent(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus(); // Artificially move the transaction status to UNKNOWN final String paymentStateName = paymentSMHelper.getErroredStateForTransaction(TransactionType.AUTHORIZE).toString(); testListener.pushExpectedEvent(NextEvent.PAYMENT_PLUGIN_ERROR); paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.UNKNOWN, requestedAmount, account.getCurrency(), "foo", "bar", internalCallContext); testListener.assertListenerStatus(); // Move clock for notification to be processed testListener.pushExpectedEvent(NextEvent.PAYMENT); clock.addDeltaFromReality(5 * 60 * 1000); assertNotificationsCompleted(internalCallContext, 5); testListener.assertListenerStatus(); final Payment updatedPayment = paymentApi.getPayment(payment.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); }
@Test(groups = "slow") public void testPendingEntries() throws PaymentApiException, EventBusException, NoSuchNotificationQueue { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "jhj44"; final String transactionExternalKey = "4jhjj2"; testListener.pushExpectedEvent(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus(); // Artificially move the transaction status to PENDING final String paymentStateName = paymentSMHelper.getPendingStateForTransaction(TransactionType.AUTHORIZE).toString(); testListener.pushExpectedEvent(NextEvent.PAYMENT); paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.PENDING, requestedAmount, account.getCurrency(), "loup", "chat", internalCallContext); testListener.assertListenerStatus(); // Move clock for notification to be processed ((default config is set for one hour) testListener.pushExpectedEvent(NextEvent.PAYMENT); clock.addDeltaFromReality(1000 * (3600 + 1)); assertNotificationsCompleted(internalCallContext, 5); testListener.assertListenerStatus(); final Payment updatedPayment = paymentApi.getPayment(payment.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); }
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus();