public static List<PluginProperty> buildPluginProperties(@Nullable final Map<String, Object> data) { final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.<PluginProperty>builder(); if (data != null) { for (final String key : data.keySet()) { final PluginProperty property = new PluginProperty(key, data.get(key), false); propertiesBuilder.add(property); } } return propertiesBuilder.build(); } }
public PluginProperty toPluginProperty() { return new PluginProperty(key, value, isUpdatable); }
protected List<PluginProperty> propertiesToList(final Map<String, String> propertiesMap) { final List<PluginProperty> properties = new LinkedList<PluginProperty>(); for (final String key : propertiesMap.keySet()) { final PluginProperty property = new PluginProperty(key, propertiesMap.get(key), false); properties.add(property); } return properties; }
public static List<PluginProperty> buildPluginProperties(@Nullable final Map<String, Object> data) { final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.<PluginProperty>builder(); if (data != null) { for (final String key : data.keySet()) { final PluginProperty property = new PluginProperty(key, data.get(key), false); propertiesBuilder.add(property); } } return propertiesBuilder.build(); } }
public static List<PluginProperty> buildPluginProperties(@Nullable final Map data) { final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.builder(); if (data != null) { for (final Object key : data.keySet()) { if (key != null) { final PluginProperty property = new PluginProperty(key.toString(), data.get(key), false); propertiesBuilder.add(property); } } } return propertiesBuilder.build(); } }
protected Iterable<PluginProperty> extractPluginProperties(@Nullable final Iterable<String> pluginProperties, final PluginProperty... additionalProperties) { final Collection<PluginProperty> properties = new LinkedList<PluginProperty>(); if (pluginProperties == null) { return properties; } for (final String pluginProperty : pluginProperties) { final List<String> property = ImmutableList.<String>copyOf(pluginProperty.split("=")); // Skip entries for which there is no value if (property.size() == 1) { continue; } final String key = property.get(0); // Should we URL decode the value? String value = Joiner.on("=").join(property.subList(1, property.size())); if (pluginProperty.endsWith("=")) { value += "="; } properties.add(new PluginProperty(key, value, false)); } for (final PluginProperty cur : additionalProperties) { properties.add(cur); } return properties; }
@Override public List<PluginProperty> getProperties() { final PluginProperty prop = new PluginProperty("whatever", "cool", Boolean.TRUE); final List<PluginProperty> res = new ArrayList<PluginProperty>(); res.add(prop); return res; } }
@Test(groups = "fast") public void testEqualsForPluginProperty() throws Exception { final String key = UUID.randomUUID().toString(); final Object value = UUID.randomUUID(); final boolean updatable = false; final PluginProperty kvInfo = new PluginProperty(key, value, updatable); Assert.assertEquals(kvInfo, kvInfo); final PluginProperty sameKvInfo = new PluginProperty(key, value, updatable); Assert.assertEquals(sameKvInfo, kvInfo); final PluginProperty otherKvInfo = new PluginProperty(key, value, !updatable); Assert.assertNotEquals(otherKvInfo, kvInfo); } }
public static final List<PluginProperty> toProperties(final Map<String, String> properties) { final List<PluginProperty> list = new ArrayList<PluginProperty>(); for (final Entry<String, String> entry : properties.entrySet()) { list.add(new PluginProperty(entry.getKey(), entry.getValue(), false)); } return list; }
@Test(groups = "fast") public void testSimplePluginProperty() throws PluginPropertySerializerException { final List<PluginProperty> input = new ArrayList<PluginProperty>(); input.add(new PluginProperty("foo", "bar", false)); final byte[] serialized = PluginPropertySerializer.serialize(input); final Iterable<PluginProperty> deserialized = PluginPropertySerializer.deserialize(serialized); int i = 0; for (PluginProperty cur : deserialized) { Assert.assertEquals(cur, input.get(i++)); } }
@Test(groups = "fast") public void testEquals() throws Exception { final String externalId = UUID.randomUUID().toString(); final boolean isDefault = false; final List<PluginProperty> props = ImmutableList.<PluginProperty>of(new PluginProperty(UUID.randomUUID().toString(), UUID.randomUUID().toString(), false)); final DefaultNoOpPaymentMethodPlugin paymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, props); Assert.assertEquals(paymentMethod, paymentMethod); final DefaultNoOpPaymentMethodPlugin samePaymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, props); Assert.assertEquals(samePaymentMethod, paymentMethod); final DefaultNoOpPaymentMethodPlugin otherPaymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, ImmutableList.<PluginProperty>of()); Assert.assertNotEquals(otherPaymentMethod, paymentMethod); }
@Test(groups = "fast") public void testLotsPluginProperty() throws PluginPropertySerializerException { final List<PluginProperty> input = new ArrayList<PluginProperty>(); for (int i = 0; i < 100; i++) { input.add(new PluginProperty("foo-" + i, "bar-" + i, false)); } final byte[] serialized = PluginPropertySerializer.serialize(input); final Iterable<PluginProperty> deserialized = PluginPropertySerializer.deserialize(serialized); int i = 0; for (PluginProperty cur : deserialized) { Assert.assertEquals(cur, input.get(i++)); } }
@Test(groups = "fast") public void testBuildFormDescriptorWithPaymentControl() throws PaymentApiException { final List<PluginProperty> initialProperties = new ArrayList<PluginProperty>(); initialProperties.add(new PluginProperty("keyA", "valueA", true)); initialProperties.add(new PluginProperty("keyB", "valueB", true)); initialProperties.add(new PluginProperty("keyC", "valueC", true)); final List<PluginProperty> priorNewProperties = new ArrayList<PluginProperty>(); priorNewProperties.add(new PluginProperty("keyD", "valueD", true)); final List<PluginProperty> priorRemovedProperties = new ArrayList<PluginProperty>(); priorRemovedProperties.add(new PluginProperty("keyA", "valueA", true)); plugin.setPriorCallProperties(priorNewProperties, priorRemovedProperties); final List<PluginProperty> onResultNewProperties = new ArrayList<PluginProperty>(); onResultNewProperties.add(new PluginProperty("keyE", "valueE", true)); final List<PluginProperty> onResultRemovedProperties = new ArrayList<PluginProperty>(); onResultRemovedProperties.add(new PluginProperty("keyB", "valueB", true)); plugin.setOnResultProperties(onResultNewProperties, onResultRemovedProperties); final List<PluginProperty> expectedPriorCallProperties = new ArrayList<PluginProperty>(); expectedPriorCallProperties.add(new PluginProperty("keyB", "valueB", true)); expectedPriorCallProperties.add(new PluginProperty("keyC", "valueC", true)); expectedPriorCallProperties.add(new PluginProperty("keyD", "valueD", true)); validationPlugin.setExpectedPriorCallProperties(expectedPriorCallProperties); final List<PluginProperty> expectedProperties = new ArrayList<PluginProperty>(); expectedProperties.add(new PluginProperty("keyC", "valueC", true)); expectedProperties.add(new PluginProperty("keyD", "valueD", true)); expectedProperties.add(new PluginProperty("keyE", "valueE", true)); validationPlugin.setExpectedProperties(expectedProperties); // Set a random UUID to verify the plugin will successfully override it paymentGatewayApi.buildFormDescriptorWithPaymentControl(account, UUID.randomUUID(), ImmutableList.<PluginProperty>of(), initialProperties, paymentOptions, callContext); }
@Test(groups = "fast", enabled = true) public void testPluginPropertyWithComplexValue() throws PluginPropertySerializerException { final HashMap<String, BigDecimal> something = new HashMap<String, BigDecimal>(); something.put("yoyo", new BigDecimal("0.0")); something.put("what", new BigDecimal("10.0")); final List<PluginProperty> input = new ArrayList<PluginProperty>(); input.add(new PluginProperty("prev", "simple", false)); input.add(new PluginProperty("foo", something, false)); input.add(new PluginProperty("next", "easy", false)); final byte[] serialized = PluginPropertySerializer.serialize(input); final Iterable<PluginProperty> deserialized = PluginPropertySerializer.deserialize(serialized); int i = 0; for (PluginProperty cur : deserialized) { if (i == 0 || i == 2) { Assert.assertEquals(cur, input.get(i)); } else { Assert.assertEquals(cur.getKey(), "foo"); Assert.assertTrue(cur.getValue() instanceof Map); final Map<String, BigDecimal> mappedValue = (Map<String, BigDecimal>) cur.getValue(); Assert.assertTrue(mappedValue.containsKey("yoyo")); Assert.assertTrue(mappedValue.containsKey("what")); Assert.assertTrue(mappedValue.get("yoyo").compareTo(BigDecimal.ZERO) == 0); Assert.assertTrue(mappedValue.get("what").compareTo(BigDecimal.TEN) == 0); } i++; } } }
public void overridePaymentTransactionPluginResult(final UUID kbPaymentId, final UUID kbTransactionId, final PaymentPluginStatus paymentPluginStatus) throws PaymentPluginApiException { final List<PaymentTransactionInfoPlugin> existingTransactions = paymentTransactions.get(kbPaymentId.toString()); PaymentTransactionInfoPlugin paymentTransactionInfoPlugin = null; for (final PaymentTransactionInfoPlugin existingTransaction : existingTransactions) { if (existingTransaction.getKbTransactionPaymentId().equals(kbTransactionId)) { paymentTransactionInfoPlugin = existingTransaction; break; } } Preconditions.checkNotNull(paymentTransactionInfoPlugin); final Iterable<PluginProperty> pluginProperties = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, paymentPluginStatus.toString(), false)); getPaymentTransactionInfoPluginResult(kbPaymentId, kbTransactionId, TransactionType.AUTHORIZE, paymentTransactionInfoPlugin.getAmount(), paymentTransactionInfoPlugin.getCurrency(), pluginProperties); }
@Test(groups = "slow") public void testNotifyPendingPaymentOfStateChanged() throws Exception { final String paymentExternalKey = UUID.randomUUID().toString(); final Iterable<PluginProperty> pluginPropertiesToDriveTransationToPending = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PENDING, false)); // Create Pending AUTH final String authorizationKey = UUID.randomUUID().toString(); final Payment authorization = paymentProcessor.createAuthorization(true, null, account, null, null, TEN, CURRENCY, null,paymentExternalKey, authorizationKey, null, null, SHOULD_LOCK_ACCOUNT, pluginPropertiesToDriveTransationToPending, callContext, internalCallContext); final PaymentTransaction pendingTransaction = authorization.getTransactions().get(0); Assert.assertEquals(pendingTransaction.getTransactionStatus(), TransactionStatus.PENDING); final UUID transactionId = pendingTransaction.getId(); // Override plugin status of payment mockPaymentProviderPlugin.overridePaymentPluginStatus(authorization.getId(), transactionId, PaymentPluginStatus.PROCESSED); // Notify that state has changed, after changing the state in the plugin final Payment updatedPayment = paymentProcessor.notifyPendingPaymentOfStateChanged(account, transactionId, true, callContext, internalCallContext); verifyPayment(updatedPayment, paymentExternalKey, TEN, ZERO, ZERO, 1); final PaymentTransaction updatedTransaction = updatedPayment.getTransactions().get(0); Assert.assertEquals(updatedTransaction.getTransactionStatus(), TransactionStatus.SUCCESS); }
@Test(groups = "slow") public void testGetAccountPaymentsWithJanitor() throws Exception { final String paymentExternalKey = UUID.randomUUID().toString(); final Iterable<PluginProperty> pluginPropertiesToDriveTransationToUnknown = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.UNDEFINED, false)); final String authorizationKey = UUID.randomUUID().toString(); final Payment authorization = paymentProcessor.createAuthorization(true, null, account, null, null, TEN, CURRENCY, null, paymentExternalKey, authorizationKey, null, null, SHOULD_LOCK_ACCOUNT, pluginPropertiesToDriveTransationToUnknown, callContext, internalCallContext); verifyPayment(authorization, paymentExternalKey, ZERO, ZERO, ZERO, 1); final UUID paymentId = authorization.getId(); verifyPaymentTransaction(authorization.getTransactions().get(0), authorizationKey, TransactionType.AUTHORIZE, TEN, paymentId); paymentBusListener.verify(0, 0, 1, account.getId(), paymentId, ZERO, TransactionStatus.UNKNOWN); mockPaymentProviderPlugin.overridePaymentPluginStatus(paymentId, authorization.getTransactions().get(0).getId(), PaymentPluginStatus.PROCESSED); final List<Payment> payments = paymentControlAwareRefresher.getAccountPayments(account.getId(), true, false, callContext, internalCallContext); Assert.assertEquals(payments.size(), 1); verifyPayment(payments.get(0), paymentExternalKey, TEN, ZERO, ZERO, 1); verifyPaymentTransaction(payments.get(0).getTransactions().get(0), authorizationKey, TransactionType.AUTHORIZE, TEN, paymentId); paymentBusListener.verify(1, 0, 1, account.getId(), paymentId, TEN, TransactionStatus.SUCCESS); }
@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); }
@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); }
@Test(groups = "slow") public void testInvalidTransition() throws Exception { final String paymentExternalKey = UUID.randomUUID().toString(); final Iterable<PluginProperty> pluginPropertiesToDriveTransationToPending = ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.ERROR, false)); // AUTH final String authorizationKey = UUID.randomUUID().toString(); final Payment authorization = paymentProcessor.createAuthorization(true, null, account, null, null, TEN, CURRENCY, null,paymentExternalKey, authorizationKey, null, null, SHOULD_LOCK_ACCOUNT, pluginPropertiesToDriveTransationToPending, callContext, internalCallContext); verifyPayment(authorization, paymentExternalKey, ZERO, ZERO, ZERO, 1); final UUID paymentId = authorization.getId(); verifyPaymentTransaction(authorization.getTransactions().get(0), authorizationKey, TransactionType.AUTHORIZE, TEN, paymentId); paymentBusListener.verify(0, 1, 0, account.getId(), paymentId, ZERO, TransactionStatus.PAYMENT_FAILURE); // REFUND final String refundKey = UUID.randomUUID().toString(); try { paymentProcessor.createRefund(true, null, account, paymentId, TEN, CURRENCY, null,refundKey, null, SHOULD_LOCK_ACCOUNT, PLUGIN_PROPERTIES, callContext, internalCallContext); Assert.fail(); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_OPERATION.getCode()); } final Payment refreshedPayment = paymentRefresher.getPayment(authorization.getId(), false, false, PLUGIN_PROPERTIES, callContext, internalCallContext); // Make sure no state has been created (no UNKNOWN transaction for the refund) verifyPayment(refreshedPayment, paymentExternalKey, ZERO, ZERO, ZERO, 1); paymentBusListener.verify(0, 1, 0, account.getId(), paymentId, ZERO, TransactionStatus.PAYMENT_FAILURE); }