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

mx.openpay.client.core.operations.PlanOperations Maven / Gradle / Ivy

There is a newer version: 1.7.4
Show newest version
/*
 * Copyright 2013 Opencard Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mx.openpay.client.core.operations;

import static mx.openpay.client.utils.OpenpayPathComponents.ID;
import static mx.openpay.client.utils.OpenpayPathComponents.MERCHANT_ID;
import static mx.openpay.client.utils.OpenpayPathComponents.PLANS;
import static mx.openpay.client.utils.OpenpayPathComponents.SUBSCRIPTIONS;

import java.util.List;
import java.util.Map;

import mx.openpay.client.Plan;
import mx.openpay.client.Subscription;
import mx.openpay.client.core.JsonServiceClient;
import mx.openpay.client.exceptions.OpenpayServiceException;
import mx.openpay.client.exceptions.ServiceUnavailableException;
import mx.openpay.client.utils.SearchParams;

/**
 * @author elopez
 */
public class PlanOperations extends ServiceOperations {

    private static final String PLANS_PATH = MERCHANT_ID + PLANS;

    private static final String GET_PLAN_PATH = PLANS_PATH + ID;

	private static final String GET_SUBSCRIPTIONS_PLAN_PATH = GET_PLAN_PATH + SUBSCRIPTIONS;

    public PlanOperations(final JsonServiceClient client) {
        super(client);
    }

    public Plan create(final Plan plan) throws OpenpayServiceException, ServiceUnavailableException {
        String path = String.format(PLANS_PATH, this.getMerchantId());
        return this.getJsonClient().post(path, plan, Plan.class);
    };

    public Plan update(final Plan plan) throws OpenpayServiceException, ServiceUnavailableException {
        String path = String.format(GET_PLAN_PATH, this.getMerchantId(), plan.getId());
        return this.getJsonClient().put(path, plan, Plan.class);
    };

    public void delete(final String planId) throws OpenpayServiceException, ServiceUnavailableException {
        String path = String.format(GET_PLAN_PATH, this.getMerchantId(), planId);
        this.getJsonClient().delete(path);
    };

    public Plan get(final String planId) throws OpenpayServiceException, ServiceUnavailableException {
        String path = String.format(GET_PLAN_PATH, this.getMerchantId(), planId);
        return this.getJsonClient().get(path, Plan.class);
    };

    public List list(final SearchParams params) throws OpenpayServiceException, ServiceUnavailableException {
        String path = String.format(PLANS_PATH, this.getMerchantId());
        Map map = params == null ? null : params.asMap();
        return this.getJsonClient().list(path, map, Plan.class);
    };

	public List listSubscriptions(final String planId, final SearchParams params)
			throws OpenpayServiceException, ServiceUnavailableException {
		String path = String.format(GET_SUBSCRIPTIONS_PLAN_PATH, this.getMerchantId(), planId);
		Map map = params == null ? null : params.asMap();
		return this.getJsonClient().list(path, map, Subscription.class);
	};

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy