public static PaymentTransaction filterForTransaction(final Payment payment, final TransactionType transactionType) { for (final PaymentTransaction paymentTransaction : payment.getTransactions()) { if (paymentTransaction.getTransactionType().equals(transactionType)) { return paymentTransaction; } } return null; } }
@Override public int hashCode() { int result = accountId != null ? accountId.hashCode() : 0; result = 31 * result + (paymentMethodId != null ? paymentMethodId.hashCode() : 0); result = 31 * result + (paymentExternalKey != null ? paymentExternalKey.hashCode() : 0); result = 31 * result + (transactionId != null ? transactionId.hashCode() : 0); result = 31 * result + (transactionExternalKey != null ? transactionExternalKey.hashCode() : 0); result = 31 * result + (transactionType != null ? transactionType.hashCode() : 0); result = 31 * result + (effectiveDate != null ? effectiveDate.hashCode() : 0); result = 31 * result + (stateName != null ? stateName.hashCode() : 0); result = 31 * result + (amount != null ? amount.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); result = 31 * result + (pluginName != null ? pluginName.hashCode() : 0); result = 31 * result + (pluginProperties != null ? pluginProperties.hashCode() : 0); return result; } }
} else if (transactionType != null) { parameterType = "transactionType"; parameterValue = transactionType.name(); } else { parameterType = "paymentId";
@Override public OnSuccessPaymentControlResult onSuccessCall(final PaymentControlContext paymentControlContext, final Iterable<PluginProperty> properties) throws PaymentControlApiException { final PluginProperty nameProperty = Iterables.tryFind(properties, new Predicate<PluginProperty>() { @Override public boolean apply(final PluginProperty input) { return input.getKey().equals("name"); } }).orNull(); if (nameProperty != null && nameProperty.getValue().equals(TEST_PAYMENT_WITH_CONTROL)) { final Integer result = calls.get(paymentControlContext.getTransactionType()); calls.put(paymentControlContext.getTransactionType().toString(), result == null ? new Integer(1) : new Integer(result.intValue() + 1)); } return new OnSuccessPaymentControlResult() { @Override public Iterable<PluginProperty> getAdjustedPluginProperties() { return null; } }; }
@Override protected PaymentTransactionInfoPlugin buildPaymentTransactionInfoPlugin(final TestResponsesRecord record) { final DateTime createdDate = new DateTime(record.getCreatedDate(), DateTimeZone.UTC); final List<PluginProperty> properties = TestUtils.buildPluginProperties(record.getAdditionalData()); return new PluginPaymentTransactionInfoPlugin(UUID.fromString(record.getKbPaymentId()), UUID.fromString(record.getKbPaymentTransactionId()), TransactionType.valueOf(record.getTransactionType()), record.getAmount(), Strings.isNullOrEmpty(record.getCurrency()) ? null : Currency.valueOf(record.getCurrency()), PaymentPluginStatus.UNDEFINED, null, // String gatewayError null, // String gatewayErrorCode null, // String firstPaymentReferenceId null, // String secondPaymentReferenceId createdDate, createdDate, properties); }
@Override public Void withConnection(final Connection conn) throws SQLException { DSL.using(conn, dialect, settings) .insertInto(responsesTable, DSL.field(KB_ACCOUNT_ID), DSL.field(KB_PAYMENT_ID), DSL.field(KB_PAYMENT_TRANSACTION_ID), DSL.field(TRANSACTION_TYPE), DSL.field(AMOUNT), DSL.field(CURRENCY), DSL.field(ADDITIONAL_DATA), DSL.field(CREATED_DATE), DSL.field(KB_TENANT_ID)) .values(kbAccountId.toString(), kbPaymentId.toString(), kbPaymentTransactionId.toString(), transactionType.toString(), amount, currency == null ? null : currency.name(), asString(additionalData), toTimestamp(utcNow), kbTenantId.toString()) .execute(); return null; } });
return false; if (transactionType != null ? !transactionType.equals(that.transactionType) : that.transactionType != null) { return false;
@Override public RESP_R withConnection(final Connection conn) throws SQLException { return DSL.using(conn, dialect, settings) .selectFrom(responsesTable) .where(DSL.field(KB_PAYMENT_ID).equal(kbPaymentId.toString())) .and(DSL.field(TRANSACTION_TYPE).equal(TransactionType.AUTHORIZE.toString())) .and(DSL.field(KB_TENANT_ID).equal(kbTenantId.toString())) .orderBy(DSL.field(recordIdFieldName).desc()) .limit(1) .fetchOne(); } });
@Override public int hashCode() { int result = transactionId != null ? transactionId.hashCode() : 0; result = 31 * result + (paymentId != null ? paymentId.hashCode() : 0); result = 31 * result + (transactionExternalKey != null ? transactionExternalKey.hashCode() : 0); result = 31 * result + (transactionType != null ? transactionType.hashCode() : 0); result = 31 * result + (effectiveDate != null ? effectiveDate.hashCode() : 0); result = 31 * result + (status != null ? status.hashCode() : 0); result = 31 * result + (amount != null ? amount.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); result = 31 * result + (processedAmount != null ? processedAmount.hashCode() : 0); result = 31 * result + (processedCurrency != null ? processedCurrency.hashCode() : 0); result = 31 * result + (gatewayErrorCode != null ? gatewayErrorCode.hashCode() : 0); result = 31 * result + (gatewayErrorMsg != null ? gatewayErrorMsg.hashCode() : 0); result = 31 * result + (firstPaymentReferenceId != null ? firstPaymentReferenceId.hashCode() : 0); result = 31 * result + (secondPaymentReferenceId != null ? secondPaymentReferenceId.hashCode() : 0); result = 31 * result + (properties != null ? properties.hashCode() : 0); return result; } }
Assert.assertEquals(record.getKbPaymentId(), kbPaymentId.toString(), "Wrong kbAccountId"); Assert.assertEquals(record.getKbPaymentTransactionId(), kbTransactionId.toString(), "Wrong kbPaymentTransactionId"); Assert.assertEquals(record.getTransactionType(), transactionType.name(), "Wrong transactionType"); Assert.assertEquals(record.getAmount().doubleValue(), amount.doubleValue(), "Wrong amount"); Assert.assertEquals(record.getCurrency(), currency.name(), "Wrong currency");
return false; if (transactionType != null ? !transactionType.equals(that.transactionType) : that.transactionType != null) { return false;
@Test(groups = "slow") public void testAuthCaptureWithPaymentControl() throws Exception { final AccountData accountData = getAccountData(1); final Account account = createAccountWithNonOsgiPaymentMethod(accountData); busHandler.pushExpectedEvents(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorizationWithPaymentControl(account, account.getPaymentMethodId(), null, BigDecimal.ONE, account.getCurrency(), null, null, null, properties, paymentOptions, callContext); assertListenerStatus(); Payment paymentWithAttempts = paymentApi.getPayment(payment.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().size(), 1); Assert.assertEquals(paymentWithAttempts.getExternalKey(), paymentWithAttempts.getPaymentAttempts().get(0).getPaymentExternalKey()); Assert.assertEquals(paymentWithAttempts.getTransactions().get(0).getExternalKey(), paymentWithAttempts.getPaymentAttempts().get(0).getTransactionExternalKey()); // Verify fix for https://github.com/killbill/killbill/issues/349 when no external key is set Assert.assertEquals(paymentWithAttempts.getId().toString(), paymentWithAttempts.getPaymentAttempts().get(0).getPaymentExternalKey()); Assert.assertEquals(paymentWithAttempts.getTransactions().get(0).getId().toString(), paymentWithAttempts.getPaymentAttempts().get(0).getTransactionExternalKey()); busHandler.pushExpectedEvents(NextEvent.PAYMENT); paymentApi.createCaptureWithPaymentControl(account, payment.getId(), BigDecimal.ONE, account.getCurrency(), null, null, properties, paymentOptions, callContext); assertListenerStatus(); paymentWithAttempts = paymentApi.getPayment(payment.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().size(), 2); Assert.assertEquals(paymentWithAttempts.getTransactions().get(1).getExternalKey(), paymentWithAttempts.getPaymentAttempts().get(1).getTransactionExternalKey()); Assert.assertEquals(paymentWithAttempts.getTransactions().get(1).getId().toString(), paymentWithAttempts.getPaymentAttempts().get(1).getTransactionExternalKey()); Assert.assertEquals(testPaymentControlWithControl.getCalls().size(), 2); Assert.assertEquals(testPaymentControlWithControl.getCalls().get(TransactionType.AUTHORIZE.toString()), new Integer(1)); Assert.assertEquals(testPaymentControlWithControl.getCalls().get(TransactionType.CAPTURE.toString()), new Integer(1)); }
@Override public int hashCode() { int result = kbPaymentId != null ? kbPaymentId.hashCode() : 0; result = 31 * result + (kbTransactionPaymentPaymentId != null ? kbTransactionPaymentPaymentId.hashCode() : 0); result = 31 * result + (transactionType != null ? transactionType.hashCode() : 0); result = 31 * result + (amount != null ? amount.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); result = 31 * result + (pluginStatus != null ? pluginStatus.hashCode() : 0); result = 31 * result + (gatewayError != null ? gatewayError.hashCode() : 0); result = 31 * result + (gatewayErrorCode != null ? gatewayErrorCode.hashCode() : 0); result = 31 * result + (firstPaymentReferenceId != null ? firstPaymentReferenceId.hashCode() : 0); result = 31 * result + (secondPaymentReferenceId != null ? secondPaymentReferenceId.hashCode() : 0); result = 31 * result + (createdDate != null ? createdDate.hashCode() : 0); result = 31 * result + (effectiveDate != null ? effectiveDate.hashCode() : 0); result = 31 * result + (properties != null ? properties.hashCode() : 0); return result; } }
@Override public boolean apply(final PaymentTransaction input) { if (input.getTransactionStatus() != TransactionStatus.PENDING && input.getTransactionStatus() != TransactionStatus.SUCCESS) { return false; } if (transactionId != null && !transactionId.equals(input.getId())) { return false; } if (transactionExternalKey != null && !transactionExternalKey.equals(input.getExternalKey())) { return false; } if (transactionType != null && !transactionType.equals(input.getTransactionType())) { return false; } // // If we were given a transactionId or a transactionExternalKey or a transactionType we checked there was a match; // In the worst case, if we were given nothing, we return the PENDING transaction for that payment // return true; } });
@Override public boolean apply(final PaymentTransaction input) { return TransactionType.CHARGEBACK.equals(input.getTransactionType()) && TransactionStatus.SUCCESS.equals(input.getTransactionStatus()); } });