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

com.chargebee.BatchEntry Maven / Gradle / Ivy

There is a newer version: 3.26.0
Show newest version
package com.chargebee;

import com.chargebee.internal.Params;
import com.chargebee.internal.Request;
import org.json.JSONObject;

import java.util.Iterator;
import java.util.Map;

import static com.chargebee.BatchConstants.CORRELATION_ID;


public class BatchEntry {

    String correlationId;

    public void setParameters(JSONObject parameters) {
        this.parameters = parameters;
    }

    JSONObject parameters;

    public Request getRequestObject() {
        return requestObject;
    }

    Request requestObject;

    public BatchEntry(Request requestObject, String correlationId) {
        this(requestObject);
        this.correlationId = correlationId;
    }

    public BatchEntry(Request requestObject) {
        this.requestObject = requestObject;
        this.parameters = jsonParams(requestObject.params());
    }

    private JSONObject jsonParams(Params params) {
        JSONObject paramJson = new JSONObject();
        Iterator paramIterator = params.entries().iterator();
        while (paramIterator.hasNext()) {
            Map.Entry paramMap = (Map.Entry) paramIterator.next();
            paramJson.put(paramMap.getKey().toString(), paramMap.getValue());
        }
        return paramJson;
    }

    public JSONObject getJSON() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("parameters", this.parameters);
        if(this.correlationId != null ) {
            jsonObject.put(CORRELATION_ID, this.correlationId);
        }
        return jsonObject;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy