private void verifyPaymentTransaction(final PaymentTransaction paymentTransaction, final String paymentTransactionExternalKey, final TransactionType transactionType, @Nullable final BigDecimal amount, final UUID paymentId) { Assert.assertEquals(paymentTransaction.getPaymentId(), paymentId); Assert.assertEquals(paymentTransaction.getExternalKey(), paymentTransactionExternalKey); Assert.assertEquals(paymentTransaction.getTransactionType(), transactionType); if (amount == null) { Assert.assertNull(paymentTransaction.getAmount()); Assert.assertNull(paymentTransaction.getCurrency()); } else { Assert.assertEquals(paymentTransaction.getAmount().compareTo(amount), 0); Assert.assertEquals(paymentTransaction.getCurrency(), CURRENCY); } }
public static PaymentTransaction buildPaymentTransaction(final Payment payment, final String transactionExternalKey, final TransactionType transactionType, final TransactionStatus transactionStatus, final BigDecimal amount, final Currency currency) { final PaymentTransaction paymentTransaction = Mockito.mock(PaymentTransaction.class); Mockito.when(paymentTransaction.getId()).thenReturn(UUID.randomUUID()); final UUID paymentId = payment.getId(); Mockito.when(paymentTransaction.getPaymentId()).thenReturn(paymentId); Mockito.when(paymentTransaction.getTransactionType()).thenReturn(transactionType); Mockito.when(paymentTransaction.getAmount()).thenReturn(amount); Mockito.when(paymentTransaction.getCurrency()).thenReturn(currency); Mockito.when(paymentTransaction.getEffectiveDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 56, DateTimeZone.UTC)); Mockito.when(paymentTransaction.getExternalKey()).thenReturn(transactionExternalKey); Mockito.when(paymentTransaction.getTransactionStatus()).thenReturn(transactionStatus); final PaymentTransactionInfoPlugin paymentTransactionInfoPlugin = Mockito.mock(PaymentTransactionInfoPlugin.class); final PaymentPluginStatus paymentPluginStatus = toPaymentPluginStatus(paymentTransaction.getTransactionStatus()); Mockito.when(paymentTransactionInfoPlugin.getStatus()).thenReturn(paymentPluginStatus); Mockito.when(paymentTransaction.getPaymentInfoPlugin()).thenReturn(paymentTransactionInfoPlugin); payment.getTransactions().add(paymentTransaction); return paymentTransaction; }
@Test(groups = "slow") public void testCreateSuccessPurchase() throws PaymentApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "bwwrr"; final String transactionExternalKey = "krapaut"; final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); assertEquals(payment.getExternalKey(), paymentExternalKey); assertEquals(payment.getPaymentMethodId(), account.getPaymentMethodId()); assertEquals(payment.getAccountId(), account.getId()); assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getPurchasedAmount().compareTo(requestedAmount), 0); assertEquals(payment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getCurrency(), Currency.AED); assertEquals(payment.getTransactions().size(), 1); assertEquals(payment.getTransactions().get(0).getExternalKey(), transactionExternalKey); assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED); assertEquals(payment.getTransactions().get(0).getProcessedAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getProcessedCurrency(), Currency.AED); assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE); assertNotNull(payment.getTransactions().get(0).getGatewayErrorMsg()); assertNotNull(payment.getTransactions().get(0).getGatewayErrorCode()); }
@Test(groups = "slow") public void testNotifyPendingTransactionOfStateChanged() throws PaymentApiException { final BigDecimal authAmount = BigDecimal.TEN; final String paymentExternalKey = "rouge"; final String transactionExternalKey = "vert"; final Payment initialPayment = createPayment(TransactionType.AUTHORIZE, null, paymentExternalKey, transactionExternalKey, authAmount, PaymentPluginStatus.PENDING); final Payment payment = paymentApi.notifyPendingTransactionOfStateChanged(account, initialPayment.getTransactions().get(0).getId(), true, callContext); assertEquals(payment.getExternalKey(), paymentExternalKey); assertEquals(payment.getPaymentMethodId(), account.getPaymentMethodId()); assertEquals(payment.getAccountId(), account.getId()); assertEquals(payment.getAuthAmount().compareTo(authAmount), 0); assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getPurchasedAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0); assertEquals(payment.getCurrency(), Currency.USD); assertEquals(payment.getTransactions().size(), 1); assertEquals(payment.getTransactions().get(0).getExternalKey(), transactionExternalKey); assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD); assertEquals(payment.getTransactions().get(0).getProcessedAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getProcessedCurrency(), Currency.USD); assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.AUTHORIZE); assertNull(payment.getTransactions().get(0).getGatewayErrorMsg()); assertNull(payment.getTransactions().get(0).getGatewayErrorCode()); }
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(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED);
assertEquals(payment4.getTransactions().get(3).getPaymentId(), payment.getId()); assertEquals(payment4.getTransactions().get(3).getAmount().compareTo(payment3.getCapturedAmount()), 0); assertEquals(payment4.getTransactions().get(3).getCurrency(), Currency.USD);
assertTrue(paymentInfo.getTransactions().get(0).getAmount().compareTo(MoreObjects.firstNonNull(expectedAmount, invoiceAmount)) == 0); assertEquals(paymentInfo.getTransactions().get(0).getCurrency(), Currency.USD); assertEquals(paymentInfo.getTransactions().get(0).getPaymentId(), paymentInfo.getId()); assertEquals(paymentInfo.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE); assertEquals(paymentInfo.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED); assertEquals(payment2.getTransactions().get(1).getPaymentId(), payment.getId()); assertNull(payment2.getTransactions().get(1).getAmount()); assertNull(payment2.getTransactions().get(1).getCurrency());
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED); assertEquals(payment2.getTransactions().get(1).getPaymentId(), payment.getId()); assertEquals(payment2.getTransactions().get(1).getAmount().compareTo(captureAmount), 0); assertEquals(payment2.getTransactions().get(1).getCurrency(), Currency.AED);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), currency);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED); assertEquals(payment2.getTransactions().get(1).getPaymentId(), payment.getId()); assertEquals(payment2.getTransactions().get(1).getAmount().compareTo(captureAmount), 0); assertEquals(payment2.getTransactions().get(1).getCurrency(), Currency.AED); assertEquals(payment3.getTransactions().get(2).getPaymentId(), payment.getId()); assertNull(payment3.getTransactions().get(2).getAmount()); assertNull(payment3.getTransactions().get(2).getCurrency()); assertEquals(payment4.getTransactions().get(3).getPaymentId(), payment.getId()); assertNull(payment4.getTransactions().get(3).getAmount()); assertNull(payment4.getTransactions().get(3).getCurrency());
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(authAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.AED); assertEquals(payment2.getTransactions().get(1).getPaymentId(), payment.getId()); assertEquals(payment2.getTransactions().get(1).getAmount().compareTo(captureAmount), 0); assertEquals(payment2.getTransactions().get(1).getCurrency(), Currency.AED); assertEquals(payment3.getTransactions().get(2).getPaymentId(), payment.getId()); assertNull(payment3.getTransactions().get(2).getAmount()); assertNull(payment3.getTransactions().get(2).getCurrency()); assertEquals(payment4.getTransactions().get(3).getPaymentId(), payment.getId()); assertEquals(payment4.getTransactions().get(3).getAmount().compareTo(captureAmount), 0); assertEquals(payment4.getTransactions().get(3).getCurrency(), Currency.AED);
assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId()); assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0); assertEquals(payment.getTransactions().get(0).getCurrency(), currency); assertEquals(payment2.getTransactions().get(1).getPaymentId(), payment.getId()); assertEquals(payment2.getTransactions().get(1).getAmount().compareTo(requestedAmount), 0); assertEquals(payment2.getTransactions().get(1).getCurrency(), currency); assertEquals(payment3.getTransactions().get(2).getPaymentId(), payment.getId()); assertNull(payment3.getTransactions().get(2).getAmount()); assertNull(payment3.getTransactions().get(2).getCurrency()); assertEquals(payment4.getTransactions().get(3).getPaymentId(), payment.getId()); assertEquals(payment4.getTransactions().get(3).getAmount().compareTo(refundAmount), 0); assertEquals(payment4.getTransactions().get(3).getCurrency(), currency); assertEquals(payment5.getTransactions().get(4).getPaymentId(), payment.getId()); assertEquals(payment5.getTransactions().get(4).getAmount().compareTo(secondChargebackAmount), 0); assertEquals(payment5.getTransactions().get(4).getCurrency(), currency); assertEquals(payment6.getTransactions().get(5).getPaymentId(), payment.getId()); assertNull(payment6.getTransactions().get(5).getAmount()); assertNull(payment6.getTransactions().get(5).getCurrency());
public PaymentTransactionJson(final PaymentTransaction transaction, final String paymentExternalKey, @Nullable final List<AuditLog> transactionLogs) { this(transaction.getId(), transaction.getExternalKey(), transaction.getPaymentId(), paymentExternalKey, transaction.getTransactionType(), transaction.getAmount(), transaction.getCurrency() != null ? transaction.getCurrency() : null, transaction.getEffectiveDate(), transaction.getProcessedAmount(), transaction.getProcessedCurrency() != null ? transaction.getProcessedCurrency() : null, transaction.getTransactionStatus() != null ? transaction.getTransactionStatus().toString() : null, transaction.getGatewayErrorCode(), transaction.getGatewayErrorMsg(), transaction.getPaymentInfoPlugin() == null ? null : transaction.getPaymentInfoPlugin().getFirstPaymentReferenceId(), transaction.getPaymentInfoPlugin() == null ? null : transaction.getPaymentInfoPlugin().getSecondPaymentReferenceId(), transaction.getPaymentInfoPlugin() == null ? null : toPluginPropertyJson(transaction.getPaymentInfoPlugin().getProperties()), toAuditLogJson(transactionLogs)); }
return uriBuilder.buildResponse(uriInfo, PaymentResource.class, "getPayment", pendingOrSuccessTransaction.getPaymentId(), request);