com.commercetools.payment.nopsp.NoPaymentServiceProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nopsp-adapter Show documentation
Show all versions of nopsp-adapter Show documentation
The commercetools java payment project intend is to make payment integration easy
package com.commercetools.payment.nopsp;
import com.commercetools.payment.domain.PaymentServiceProvider;
import com.commercetools.payment.model.CreatePaymentData;
import com.commercetools.payment.model.CreatePaymentTransactionData;
import com.commercetools.payment.model.PaymentCreationResult;
import com.commercetools.payment.model.PaymentTransactionCreationResult;
import com.commercetools.payment.nopsp.config.NoPaymentServiceConfiguration;
import com.commercetools.payment.nopsp.config.NoPaymentServiceConfigurationProvider;
import com.commercetools.payment.nopsp.methods.FreeCreatePaymentMethodProvider;
import com.commercetools.payment.nopsp.methods.FreeCreatePaymentTransactionMethodProvider;
import io.sphere.sdk.payments.PaymentMethodInfo;
import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* For all Payment Methods that does not need a Payment Service Provider. F.I. Free payment.
* @author [email protected]
*/
public class NoPaymentServiceProvider implements PaymentServiceProvider {
private NoPaymentServiceConfiguration configuration;
public NoPaymentServiceProvider() {
configuration = NoPaymentServiceConfigurationProvider.of().load();
}
@Override
public String getId() {
return configuration.getInterfaceId();
}
@Override
public List getAvailablePaymentMethods() {
return getAvailablePaymentMethods(null);
}
@Override
public List getAvailablePaymentMethods(@Nullable Function, List> filter) {
List unfiltered = configuration.getEnabledMethods().stream().map(methodId -> configuration.getMethodInfo(methodId)).collect(Collectors.toList());
return filter != null
? filter.apply(unfiltered)
: unfiltered;
}
@Override
public Function> provideCreatePaymentHandler(String methodId)
throws UnsupportedOperationException {
switch (methodId) {
case "FREE": return FreeCreatePaymentMethodProvider.of().create();
}
throw createUnsupportedMethodException(methodId);
}
@Override
public Function> provideCreatePaymentTransactionHandler(String methodId)
throws UnsupportedOperationException {
switch (methodId) {
case "FREE": return FreeCreatePaymentTransactionMethodProvider.of().create();
}
throw createUnsupportedMethodException(methodId);
}
}