@Override public UUID apply(final InvoicePayment input) { return input.getPaymentId(); } }));
@Override public boolean apply(final InvoicePayment input) { return input.getPaymentId().equals(payment.getId()) && input.getType() == InvoicePaymentType.ATTEMPT; } }).orNull();
@Override public boolean apply(@Nullable final InvoicePayment invoicePayment) { return invoicePayment.getType() == type && invoicePayment.getPaymentId().equals(paymentId); } });
@Override public Payment apply(@Nullable final Void input) { try { final InvoicePayment invoicePayment = invoicePaymentApi.createRefundForInvoicePayment(true, iias, account, payment.getId(), amount, currency, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext); return paymentApi.getPayment(invoicePayment.getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { fail(e.toString()); return null; } } }, events);
payment.getPaymentExternalKey(), null, pluginProperties, callContext); return result != null ? uriBuilder.buildResponse(uriInfo, InvoicePaymentResource.class, "getInvoicePayment", result.getPaymentId(), request) : Response.status(Status.NO_CONTENT).build();
@Override public Payment apply(@Nullable final Void input) { try { final InvoicePayment invoicePayment = invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, amount, currency, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext); return paymentApi.getPayment(invoicePayment.getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { fail(e.toString()); return null; } } }, events);
private void verifyRefund(final Invoice invoice, final BigDecimal invoiceAmount, final BigDecimal refundAmount, final BigDecimal finalInvoiceAmount, final boolean adjusted, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts) throws InvoiceApiException { final InvoicePayment payment = createAndPersistPayment(invoiceInternalApi, clock, invoice.getId(), invoiceAmount, CURRENCY, internalCallContext); // Verify the initial invoice balance final BigDecimal initialInvoiceBalance = invoiceInternalApi.getInvoiceById(invoice.getId(), internalCallContext).getBalance(); Assert.assertEquals(initialInvoiceBalance.compareTo(BigDecimal.ZERO), 0); // Create a full refund with no adjustment final InvoicePayment refund = invoiceInternalApi.recordRefund(payment.getPaymentId(), refundAmount, adjusted, invoiceItemIdsWithAmounts, UUID.randomUUID().toString(), internalCallContext); Assert.assertEquals(refund.getAmount().compareTo(refundAmount.negate()), 0); Assert.assertEquals(refund.getCurrency(), CURRENCY); Assert.assertEquals(refund.getInvoiceId(), invoice.getId()); Assert.assertEquals(refund.getPaymentId(), payment.getPaymentId()); Assert.assertEquals(refund.getType(), InvoicePaymentType.REFUND); // Verify the current invoice balance final BigDecimal newInvoiceBalance = invoiceInternalApi.getInvoiceById(invoice.getId(), internalCallContext).getBalance(); Assert.assertEquals(newInvoiceBalance.compareTo(finalInvoiceAmount), 0); } }
public static InvoicePayment createAndPersistPayment(final InvoiceInternalApi invoicePaymentApi, final Clock clock, final UUID invoiceId, final BigDecimal amount, final Currency currency, final InternalCallContext callContext) throws InvoiceApiException { final InvoicePayment payment = Mockito.mock(InvoicePayment.class); Mockito.when(payment.getId()).thenReturn(UUID.randomUUID()); Mockito.when(payment.getType()).thenReturn(InvoicePaymentType.ATTEMPT); Mockito.when(payment.getInvoiceId()).thenReturn(invoiceId); Mockito.when(payment.getPaymentId()).thenReturn(UUID.randomUUID()); Mockito.when(payment.getPaymentCookieId()).thenReturn(UUID.randomUUID().toString()); final DateTime utcNow = clock.getUTCNow(); Mockito.when(payment.getPaymentDate()).thenReturn(utcNow); Mockito.when(payment.getAmount()).thenReturn(amount); Mockito.when(payment.getCurrency()).thenReturn(currency); Mockito.when(payment.getProcessedCurrency()).thenReturn(currency); Mockito.when(payment.isSuccess()).thenReturn(true); invoicePaymentApi.recordPaymentAttemptCompletion(payment.getInvoiceId(), payment.getAmount(), payment.getCurrency(), payment.getProcessedCurrency(), payment.getPaymentId(), payment.getPaymentCookieId(), payment.getPaymentDate(), payment.isSuccess(), callContext); return payment; } }
@Override public Payment apply(@Nullable final Void input) { try { final InvoicePayment invoicePayment = invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, invoice.getBalance(), invoice.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), EXTERNAL_PAYMENT_OPTIONS, callContext); return paymentApi.getPayment(invoicePayment.getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { fail(e.toString()); return null; } } }, events);
public PaymentTransaction checkRefund(final UUID paymentId, final CallContext context, ExpectedRefundCheck expected) throws PaymentApiException { final Payment payment = paymentApi.getPayment(paymentId, false, false, ImmutableList.<PluginProperty>of(), context); final PaymentTransaction refund = Iterables.tryFind(payment.getTransactions(), new Predicate<PaymentTransaction>() { @Override public boolean apply(final PaymentTransaction input) { return input.getTransactionType() == TransactionType.REFUND; } }).orNull(); Assert.assertNotNull(refund); final InvoicePayment refundInvoicePayment = getInvoicePaymentEntry(paymentId, InvoicePaymentType.REFUND, context); final InvoicePayment invoicePayment = getInvoicePaymentEntry(paymentId, InvoicePaymentType.ATTEMPT, context); Assert.assertEquals(refund.getPaymentId(), expected.getPaymentId()); Assert.assertEquals(refund.getCurrency(), expected.getCurrency()); Assert.assertEquals(refund.getAmount().compareTo(expected.getRefundAmount()), 0); Assert.assertEquals(refundInvoicePayment.getPaymentId(), paymentId); Assert.assertEquals(refundInvoicePayment.getLinkedInvoicePaymentId(), invoicePayment.getId()); Assert.assertEquals(refundInvoicePayment.getPaymentCookieId(), refund.getExternalKey()); Assert.assertEquals(refundInvoicePayment.getInvoiceId(), invoicePayment.getInvoiceId()); Assert.assertEquals(refundInvoicePayment.getAmount().compareTo(expected.getRefundAmount().negate()), 0); Assert.assertEquals(refundInvoicePayment.getCurrency(), expected.getCurrency()); return refund; }
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId());
public InvoicePaymentModelDao(final InvoicePayment invoicePayment) { this(invoicePayment.getId(), invoicePayment.getCreatedDate(), invoicePayment.getType(), invoicePayment.getInvoiceId(), invoicePayment.getPaymentId(), invoicePayment.getPaymentDate(), invoicePayment.getAmount(), invoicePayment.getCurrency(), invoicePayment.getProcessedCurrency(), invoicePayment.getPaymentCookieId(), invoicePayment.getLinkedInvoicePaymentId(), invoicePayment.isSuccess()); }
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId());
assertEquals(invoice1.getPayments().get(0).getCurrency(), Currency.USD); assertFalse(invoice1.getPayments().get(0).isSuccess()); assertNotNull(invoice1.getPayments().get(0).getPaymentId()); assertEquals(invoice2.getPayments().get(0).getCurrency(), Currency.USD); assertTrue(invoice2.getPayments().get(0).isSuccess()); assertNotNull(invoice2.getPayments().get(0).getPaymentId());
final InvoicePayment invoicePayment = invoicePaymentApi.getInvoicePayments(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).get(1).getPayments().get(0).getPaymentId(), callContext).get(0); Payment payment = paymentApi.getPayment(invoicePayment.getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext); payment = createChargeBackAndCheckForCompletion(account, payment, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT, NextEvent.BLOCK);
final Payment payment = paymentApi.getPayment(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).get(1).getPayments().get(0).getPaymentId(), false, false, PLUGIN_PROPERTIES, callContext); refundPaymentAndCheckForCompletion(account, payment, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT, NextEvent.BLOCK);
Assert.assertNull(invoice1.getPayments().get(0).getLinkedInvoicePaymentId()); Assert.assertEquals(invoice1.getPayments().get(0).getPaymentCookieId(), payment1.getTransactions().get(0).getExternalKey()); Assert.assertEquals(invoice1.getPayments().get(0).getPaymentId(), payment1.getId()); Assert.assertEquals(invoice1.getPayments().get(0).getType(), InvoicePaymentType.ATTEMPT); Assert.assertTrue(invoice1.getPayments().get(0).isSuccess()); Assert.assertNull(invoice1.getPayments().get(1).getLinkedInvoicePaymentId()); Assert.assertEquals(invoice1.getPayments().get(1).getPaymentCookieId(), payment2.getTransactions().get(0).getExternalKey()); Assert.assertEquals(invoice1.getPayments().get(1).getPaymentId(), payment2.getId()); Assert.assertEquals(invoice1.getPayments().get(1).getType(), InvoicePaymentType.ATTEMPT); Assert.assertTrue(invoice1.getPayments().get(1).isSuccess()); Assert.assertEquals(invoice1.getPayments().get(2).getLinkedInvoicePaymentId(), invoice1.getPayments().get(0).getId()); Assert.assertEquals(invoice1.getPayments().get(2).getPaymentCookieId(), payment1.getTransactions().get(1).getExternalKey()); Assert.assertEquals(invoice1.getPayments().get(2).getPaymentId(), payment1.getId()); Assert.assertEquals(invoice1.getPayments().get(2).getType(), InvoicePaymentType.REFUND); Assert.assertTrue(invoice1.getPayments().get(2).isSuccess()); Assert.assertEquals(invoice1.getPayments().get(3).getLinkedInvoicePaymentId(), invoice1.getPayments().get(1).getId()); Assert.assertEquals(invoice1.getPayments().get(3).getPaymentCookieId(), payment2.getTransactions().get(1).getExternalKey()); Assert.assertEquals(invoice1.getPayments().get(3).getPaymentId(), payment2.getId()); Assert.assertEquals(invoice1.getPayments().get(3).getType(), InvoicePaymentType.REFUND); Assert.assertTrue(invoice1.getPayments().get(3).isSuccess());
assertEquals(childInvoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0); assertEquals(childInvoices.get(1).getPayments().size(), 1); assertEquals(paymentApi.getPayment(childInvoices.get(1).getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(), childAccount.getPaymentMethodId()); assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0); assertEquals(parentInvoice.getPayments().size(), 1); assertEquals(paymentApi.getPayment(parentInvoice.getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(), parentAccount.getPaymentMethodId());