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

com.stripe.model.PaymentIntentSourceActionDeserializer Maven / Gradle / Ivy

There is a newer version: 28.4.0
Show newest version
package com.stripe.model;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.stripe.net.ApiResource;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

public class PaymentIntentSourceActionDeserializer implements
    JsonDeserializer {

  static final Map> objectMap =
      new HashMap>();

  static {
    objectMap.put("authorize_with_url", PaymentIntentSourceActionValueAuthorizeWithUrl.class);
  }

  /**
   * Deserializes the JSON payload contained in a next_source_action attribute into a
   * {@link PaymentIntentSourceAction} instance.
   */
  @Override
  public PaymentIntentSourceAction deserialize(JsonElement json, Type typeOfT,
      JsonDeserializationContext context)
      throws JsonParseException {
    PaymentIntentSourceAction sourceAction = new PaymentIntentSourceAction();
    JsonObject jsonObject = json.getAsJsonObject();
    String type = jsonObject.get("type").getAsString();
    sourceAction.setType(type);
    Class cl = objectMap.get(type);
    if (cl != null) {
      PaymentIntentSourceActionValue value = ApiResource.GSON.fromJson(jsonObject.get("value"), cl);
      sourceAction.setValue(value);
    }
    return sourceAction;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy