All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.commercetools.payment.nopsp.NoPaymentServiceProvider Maven / Gradle / Ivy

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 io.sphere.sdk.payments.PaymentStatus;

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 {
    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) {
        switch (methodId) {
            case "FREE": return FreeCreatePaymentMethodProvider.of().create();
        }

        throw new UnsupportedOperationException();
    }

    @Override
    public Function> provideCreatePaymentTransactionHandler(String methodId) {
        switch (methodId) {
            case "FREE": return FreeCreatePaymentTransactionMethodProvider.of().create();
        }

        throw new UnsupportedOperationException();
    }

    @Override
    public Function provideGetPaymentStatusHandler() {
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy