Skip to content

Commit

Permalink
killbill#40 Simplified PaymentInfoConverters and added missing Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Langendorf committed Dec 2, 2015
1 parent df4cafd commit ef8fee3
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
public interface PaymentInfoConverter<T extends PaymentInfo> {

/**
* @return the payment type this converter is handling
* @return {@code true} if this converter is handling the payment type
*/
PaymentType getPaymentType();
boolean supportsPaymentType(PaymentType type);

/**
* Convert a PaymentInfo Object into an object understandable by the payment service provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.killbill.billing.plugin.adyen.client.payment.converter.impl;

import com.google.common.collect.ImmutableSet;
import org.killbill.adyen.common.BrowserInfo;
import org.killbill.adyen.payment.AnyType2AnyTypeMap;
import org.killbill.adyen.payment.PaymentRequest;
Expand All @@ -29,8 +30,24 @@

import com.google.common.base.Strings;

import java.util.Set;

import static org.killbill.billing.plugin.adyen.client.model.PaymentType.*;

public class CreditCardConverter implements PaymentInfoConverter<Card> {

private static final Set<PaymentType> SUPPORTED_PAYMENT_TYPES = ImmutableSet.<PaymentType>builder()
.add(CREDITCARD)
.add(MASTERCARD)
.add(VISA)
.add(AMEX)
.add(DINERSCLUB)
.add(ELO)
.add(DANKORT)
.add(SHOPPING)
.add(CABAL)
.build();

@Override
public Object convertPaymentInfoToPSPTransferObject(final String holderName, final Card paymentInfo) {
final PaymentProvider paymentProvider = paymentInfo.getPaymentProvider();
Expand Down Expand Up @@ -117,8 +134,8 @@ public Object convertPaymentInfoFor3DSecureAuth(final Long billedAmount, final C
}

@Override
public PaymentType getPaymentType() {
return PaymentType.CREDITCARD;
public boolean supportsPaymentType(final PaymentType type) {
return type != null && SUPPORTED_PAYMENT_TYPES.contains(type);
}

public String getCcSecCode(final Card card) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@

package org.killbill.billing.plugin.adyen.client.payment.converter.impl;

import org.killbill.adyen.payment.PaymentRequest;
import org.killbill.billing.plugin.adyen.client.model.PaymentType;
import org.killbill.billing.plugin.adyen.client.model.paymentinfo.Card;

import static org.killbill.billing.plugin.adyen.client.model.PaymentType.AMEX;
import static org.killbill.billing.plugin.adyen.client.model.PaymentType.ISRACARD;

public class AmexConverter extends CreditCardConverter {
public class IsracardConverter extends CreditCardConverter {

@Override
public PaymentType getPaymentType() {
return AMEX;
public Object convertPaymentInfoToPSPTransferObject(final String holderName, final Card paymentInfo) {
final PaymentRequest result = (PaymentRequest) super.convertPaymentInfoToPSPTransferObject(holderName, paymentInfo);
result.setSelectedBrand(ISRACARD.getName());
return result;
}

@Override
public boolean supportsPaymentType(final PaymentType type) {
return ISRACARD.equals(type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class MaestroConverter extends CreditCardConverter {
@Override
public Object convertPaymentInfoToPSPTransferObject(final String holderName, final Card paymentInfo) {
final PaymentRequest result = (PaymentRequest) super.convertPaymentInfoToPSPTransferObject(holderName, paymentInfo);
result.setSelectedBrand("maestro");
result.setSelectedBrand(MAESTRO.getName());
return result;
}

@Override
public PaymentType getPaymentType() {
return MAESTRO;
public boolean supportsPaymentType(final PaymentType type) {
return MAESTRO.equals(type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.killbill.billing.plugin.adyen.client.model.paymentinfo.MaestroUK;
import org.killbill.billing.plugin.adyen.client.payment.converter.PaymentInfoConverter;

import static org.killbill.billing.plugin.adyen.client.model.PaymentType.MAESTROUK;

public class MaestroUKConverter implements PaymentInfoConverter<MaestroUK> {

@Override
Expand Down Expand Up @@ -59,7 +61,8 @@ public Object convertPaymentInfoFor3DSecureAuth(final Long billedAmount, final C
}

@Override
public PaymentType getPaymentType() {
return PaymentType.MAESTROUK;
public boolean supportsPaymentType(final PaymentType type) {
return MAESTROUK.equals(type);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class NullObjectConverter implements PaymentInfoConverter {

@Override
public PaymentType getPaymentType() {
public boolean supportsPaymentType(PaymentType type) {
throw new UnsupportedOperationException("method is not supported!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ public class PaymentInfoConverterService implements PaymentInfoConverterManageme

public PaymentInfoConverterService() {
this(ImmutableList.<PaymentInfoConverter<? extends PaymentInfo>>of(
new AmexConverter(),
new DinersConverter(),
new CreditCardConverter(),
new MaestroConverter(),
new MaestroUKConverter(),
new MasterCardConverter(),
new VisaConverter(),
new IsracardConverter(),
new SepaDirectDebitConverter(),
new RecurringConverter()));
}
Expand All @@ -56,7 +53,7 @@ public Object getBrowserInfoFor3DSecureAuth(final Long billedAmount, final Card
checkNotNull(card, "card is null");

for (final PaymentInfoConverter pic : paymentInfoConverters) {
if (pic.getPaymentType().equals(card.getPaymentProvider().getPaymentType())) {
if (pic.supportsPaymentType(card.getPaymentProvider().getPaymentType())) {
return pic.convertPaymentInfoFor3DSecureAuth(billedAmount, card);
}
}
Expand All @@ -66,7 +63,7 @@ public Object getBrowserInfoFor3DSecureAuth(final Long billedAmount, final Card
@Override
public PaymentInfoConverter<PaymentInfo> getConverterForPaymentInfo(final PaymentInfo paymentInfo) {
for (final PaymentInfoConverter pic : paymentInfoConverters) {
if (pic.getPaymentType().equals(paymentInfo.getPaymentProvider().getPaymentType())) {
if (pic.supportsPaymentType(paymentInfo.getPaymentProvider().getPaymentType())) {
return pic;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public Object convertPaymentInfoFor3DSecureAuth(final Long billedAmount, final C
}

@Override
public PaymentType getPaymentType() {
return EMPTY;
public boolean supportsPaymentType(final PaymentType type) {
return EMPTY.equals(type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public Object convertPaymentInfoFor3DSecureAuth(final Long billedAmount, final C
}

@Override
public PaymentType getPaymentType() {
return SEPA_DIRECT_DEBIT;
public boolean supportsPaymentType(final PaymentType type) {
return SEPA_DIRECT_DEBIT.equals(type);
}

private String holderName(final SepaDirectDebit sepaDirectDebit, final String holderName) {
Expand Down

This file was deleted.

0 comments on commit ef8fee3

Please sign in to comment.