public static PaymentMethodJson toPaymentMethodJson(final Account account, final PaymentMethod in, @Nullable final AccountAuditLogs accountAuditLogs) { final boolean isDefault = account.getPaymentMethodId() != null && account.getPaymentMethodId().equals(in.getId()); final PaymentMethodPlugin pluginDetail = in.getPluginDetail(); PaymentMethodPluginDetailJson pluginDetailJson = null; if (pluginDetail != null) { List<PluginPropertyJson> properties = null; if (pluginDetail.getProperties() != null) { properties = new ArrayList<PluginPropertyJson>(Collections2.transform(pluginDetail.getProperties(), new Function<PluginProperty, PluginPropertyJson>() { @Override public PluginPropertyJson apply(final PluginProperty input) { return new PluginPropertyJson(input.getKey(), input.getValue() == null ? null : input.getValue().toString(), input.getIsUpdatable()); } })); } pluginDetailJson = new PaymentMethodPluginDetailJson(pluginDetail.getExternalPaymentMethodId(), pluginDetail.isDefaultPaymentMethod(), properties); } return new PaymentMethodJson(in.getId(), in.getExternalKey(), account.getId(), isDefault, in.getPluginName(), pluginDetailJson, toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForPaymentMethod(in.getId()))); }
@Override public boolean apply(final PaymentMethodPlugin input) { if (input.getProperties() != null) { for (PluginProperty cur : input.getProperties()) { if (cur.getValue().equals(searchKey)) { return true; } } } return (input.getKbPaymentMethodId().toString().equals(searchKey)); } }));
public TestPaymentMethodPlugin(final UUID kbPaymentMethodId, final PaymentMethodPlugin src, final String externalPaymentId) { this.kbPaymentMethodId = kbPaymentMethodId; this.externalPaymentMethodId = externalPaymentId; this.isDefaultPaymentMethod = src.isDefaultPaymentMethod(); this.properties = src.getProperties(); }
Assert.assertEquals(plugin.getKbPaymentMethodId(), kbPaymentMethodId, "Wrong kbPaymentMethodId"); Assert.assertEquals(plugin.getExternalPaymentMethodId(), null, "Wrong externalPaymentMethodId"); Assert.assertEquals(plugin.isDefaultPaymentMethod(), true, "Wrong defaultPaymentMethod"); Assert.assertNotNull(plugin.getProperties(), "Wrong properties"); Assert.assertEquals(plugin.getProperties().size(), 0, "Wrong properties size");
public UUID addTestPaymentMethod(final String pluginName, final Account account, final PaymentMethodPlugin paymentMethodInfo, final Iterable<PluginProperty> pluginProperties) throws Exception { final boolean setDefault = paymentMethodInfo.isDefaultPaymentMethod(); final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), pluginName, setDefault, paymentMethodInfo, pluginProperties, context); if (isFastTest() && setDefault) { final Account account1 = new MockAccountBuilder(account).paymentMethodId(paymentMethodId).build(); accountApi.updateAccount(account1, context); } return paymentMethodId; }
@Override public void addPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final PaymentMethodPlugin paymentMethodProps, final boolean setDefault, final Iterable<PluginProperty> properties, final CallContext context) throws PaymentPluginApiException { // Note: query parameters have precedence by convention final Map<String, String> mergedProperties = PluginProperties.toStringMap(paymentMethodProps.getProperties(), properties); final DateTime utcNow = clock.getUTCNow(); try { dao.addPaymentMethod(kbAccountId, kbPaymentMethodId, setDefault, mergedProperties, utcNow, context.getTenantId()); } catch (final SQLException e) { throw new PaymentPluginApiException("Unable to add payment method for kbPaymentMethodId " + kbPaymentMethodId, e); } }
private Account addTestExternalPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo) throws Exception { final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), ExternalPaymentProviderPlugin.PLUGIN_NAME, true, paymentMethodInfo, ImmutableList.<PluginProperty>of(), callContext); return accountApi.getAccountById(account.getId(), internalCallContext); }
Assert.assertEquals(plugin.getKbPaymentMethodId(), kbPaymentMethodId, "Wrong kbPaymentMethodId"); Assert.assertEquals(plugin.getExternalPaymentMethodId(), "myToken", "Wrong externalPaymentMethodId"); Assert.assertEquals(plugin.isDefaultPaymentMethod(), true, "Wrong defaultPaymentMethod"); Assert.assertNotNull(plugin.getProperties(), "Wrong properties"); final List<PluginProperty> pluginProperties = plugin.getProperties(); Assert.assertEquals(pluginProperties.size(), 3, "Wrong properties size"); Assert.assertEquals(PluginProperties.getValue("Foo", null, pluginProperties), "myFooXX", "Wrong extra property Foo");
@Test(groups = "slow") public void testGetPaymentMethodsWithAndWithoutPluginInfo() throws PaymentApiException, PaymentPluginApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "externalKey"; final String transactionExternalKey = "transactionKey"; final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); final Pagination<PaymentMethod> paymentMethods = paymentApi.getPaymentMethods(0L, 10L, false, null, callContext); final Pagination<PaymentMethod> paymentMethodsPlugin = paymentApi.getPaymentMethods(0L, 10L, true, null, callContext); Assert.assertTrue(paymentMethods.getTotalNbRecords() == 1); Assert.assertTrue(paymentMethodsPlugin.getTotalNbRecords() == 1); PaymentMethod paymentMethod = paymentMethods.iterator().next(); PaymentMethod paymentMethodPlugin = paymentMethodsPlugin.iterator().next(); Assert.assertEquals(paymentMethod.getAccountId(), paymentMethodPlugin.getAccountId()); Assert.assertEquals(paymentMethod.getId(), paymentMethodPlugin.getId()); Assert.assertEquals(paymentMethod.getExternalKey(), paymentMethodPlugin.getExternalKey()); Assert.assertEquals(paymentMethod.getPluginName(), paymentMethodPlugin.getPluginName()); Assert.assertNull(paymentMethod.getPluginDetail()); Assert.assertNotNull(paymentMethodPlugin.getPluginDetail()); Assert.assertTrue(paymentMethodPlugin.getPluginDetail().getProperties().isEmpty()); }