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

com.konduto.sdk.adapters.KondutoPaymentCollectionDeserializer Maven / Gradle / Ivy

Go to download

Easily integrate with Konduto (https://konduto.com), a fraud prevention service.

There is a newer version: 2.17.4
Show newest version
package com.konduto.sdk.adapters;

import com.google.gson.*;
import com.konduto.sdk.models.*;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * Deserialization of KondutoPayment collections.
 *
 */
public class KondutoPaymentCollectionDeserializer implements JsonDeserializer> {

	/**
	 * Method to deserialize a JSON object into a collection of KondutoPayment.
	 *
	 * @param json a serialized object
	 * @param typeOfT the object type
	 * @param context GSON serialization context
	 * @return an ArrayList of payments
	 * @throws JsonParseException
	 */
	@Override
	public Collection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			throws JsonParseException {

		Collection payments = new ArrayList();

		for(JsonElement je : json.getAsJsonArray()) {
			KondutoPaymentType type =
					KondutoPaymentType.valueOf(((JsonObject) je).get("type").getAsString().toUpperCase());
			switch (type){
				case BOLETO:
					KondutoBoletoPayment boletoPayment = new KondutoBoletoPayment();
					String expirationDateAsStr = ((JsonObject) je).get("expiration_date").getAsString();
					boletoPayment.setExpirationDate(expirationDateAsStr);
                    payments.add(boletoPayment);
					break;
				case CREDIT:
					payments.add((KondutoCreditCardPayment) context.deserialize(je, KondutoCreditCardPayment.class));
					break;
				case DEBIT:
					payments.add((KondutoDebitPayment) context.deserialize(je, KondutoDebitPayment.class));
					break;
				case TRANSFER:
					payments.add((KondutoTransferPayment) context.deserialize(je, KondutoTransferPayment.class));
					break;
				case VOUCHER:
					payments.add((KondutoVoucherPayment) context.deserialize(je, KondutoVoucherPayment.class));
					break;
			}
		}

		return payments;
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy