Git Product home page Git Product logo

chargebee-java's Introduction

Java Client Library for Chargebee API


This is the source code for the Java client library for Chargebee APIs.

Library versions


The versioning scheme of this library is inspired by SemVer and the format is v{MAJOR}.{MINOR}.{PATCH}. For example, v3.0.0 and v2.5.1 are valid library versions.

The following table provides some details for each major version:

Library major version Status Compatible API versions Branch
v3 Active v2 and v1 master
v2 Inactive v2 and v1 chargebee-v2
v1 Inactive v1 chargebee-v1

A couple of terms used in the above table are explained below:

  • Status: The current development status for the library version. An Active major version is currently being maintained and continues to get backward-compatible changes. Inactive versions no longer receive any updates.
  • Branch: The branch in this repository containing the source code for the latest release of the library version. Every version of the library has been tagged. You can check out the source code for any version using its tag.

๐Ÿ”ด Attention: The support for v2 will eventually be discontinued on December 31st 2023 and will no longer receive any further updates. We strongly recommend upgrading to v3 as soon as possible.

Note: See the changelog for a history of changes.

Install the library


Requirement


  • Java 1.8 or later.

Install using Maven


You can install any release of an active library version by adding the below dependency to pom.xml:

<dependency>
  <groupId>com.chargebee</groupId>
  <artifactId>chargebee-java</artifactId>
  <version>{MAJOR}.{MINOR}.{PATCH}</version>
</dependency>

For example, the following are valid:

  • Install the latest version:
<dependency>
  <groupId>com.chargebee</groupId>
  <artifactId>chargebee-java</artifactId>
  <version>3.0.0</version>
</dependency>
  • Install an earlier version, say v2.5.1:
<dependency>
  <groupId>com.chargebee</groupId>
  <artifactId>chargebee-java</artifactId>
  <version>2.5.1</version>
</dependency>

Install JAR files


Obtain pre-built JAR files


You can find the JAR files for the library in the dist directory. To obtain the JAR files for a specific library version, check the dist directory within the source tree of the appropriate tag.

Build JAR files


Alternatively, you can build the JAR files by following the steps below:

  1. Checkout the appropriate version of the library source code.
git checkout {tagname}

For example, the following is valid:

git checkout v3.0.0
  1. Clean and build using Maven.
mvn clean package

Use the library


Create a subscription

import java.io.IOException;
import com.chargebee.*;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;

public class Sample{

  public static void main(String args[]) throws IOException{
    Environment.configure("{site}","{site_api_key}");
    Result result = Subscription.create()
                      .id("HwxfyiHNUFzaiWO")
                      .planId("starter")
                      .customerEmail("[email protected]")
                      .customerFirstName("John")
                      .customerLastName("Wayne").request();
    Subscription subscription = result.subscription();
    Customer customer = result.customer();
    Card card = result.card();
    System.out.println(result);
  }
}

Create an idempotent request

Idempotency keys are passed along with request headers to allow a safe retry of POST requests.

import com.chargebee.models.Card;
import com.chargebee.models.Contact;
import com.chargebee.models.Customer;
import com.chargebee.models.Subscription;
import org.json.JSONObject;

public class Sample {
    public static void main(String[] args) throws Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Customer.create()
                .firstName("John")
                .lastName("Dove")
                .email("[email protected]")
                .setIdempotencyKey("<<UUID>>") // Replace <<UUID>> with a unique string
                .request();
        Customer customer = result.customer();
        System.out.println(result.customer());
        Map<String, List<String>> responseHeaders = result.getResponseHeaders(); // Retrieves response headers
        System.out.println(responseHeaders);
        String idempotencyReplayedHeader = result.isIdempotencyReplayed();// Retrieves idempotency replayed header value 
        System.out.println(idempotencyReplayedHeader);
    }
}

isIdempotencyReplayed() method can be accessed to differentiate between original and replayed requests.

Contribution


You may contribute patches to any of the Active versions of this library. To do so, raise a PR against the respective branch.

If you find something amiss, you are welcome to create an issue.

API documentation


The API documentation for the Java library can be found in our API reference.

License


See the LICENSE.

chargebee-java's People

Contributors

cb-alish avatar cb-ashik avatar cb-bharathvaj avatar cb-gaurav avatar cb-goutham avatar cb-karthikp avatar cb-khushbubibay avatar cb-navaneedhan avatar cb-nithins avatar cb-prajaktachavan avatar cb-sriramthiagarajan avatar cb-thiyagu avatar cb-thushitamariaselvan avatar cb-yateshmathuria avatar hellokps avatar karthi-cb avatar rraman avatar sangeethabaskaran avatar saravana-cb avatar vaibhav1510 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chargebee-java's Issues

License problems of dependency org.json

Hi,
I want to use this library as Java API for Chargebee for a commercial product but when checking the dependencies of this library I found out that you are relying on org.json which is under "The JSON License".
That license is considered legally dangerous by quite some people in the opensource ecosystem due to the vague clause of "The Software shall be used for Good, not Evil." and in my case prevents me from using this library for interfacing with Chargebee for compliance reasons.

Similar issues also arose for other projects: fabric8io/docker-maven-plugin#1016

Could you consider replacing that dependency with an alternative to make compliance less of an issue please?

please don't use reflection in ClazzUtil

The com.chargebee.internal.ClazzUtil class uses reflection to pick which class to return. This causes problems when using Graalvm to get a native build. Please consider changing that code to use a switch statement on the model type instead so that it works when compiling to a native binary.

Please update the source and target Java version to 7 or above

The pom specifies Java 5 which is out of support and with recent versions of Maven will result in:

[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.

Personally I feel 8 is the lowest anyone should support these days with Java 11 and above being ideal.

Add subscriptions in ResultBase object

What problem does your feature request address?

We realized that some events (for example "Customer deleted") contains subscriptions field (collection of customer subscriptions).
However, the type com.chargebee.models.Event.content() which is the representation of event content does not provide a method to access this field.

Describe the desired solution

The desired solution would be to make subscriptions method available in ResultBase this possible:

Event event = // the instance of event
var subscriptions = event.content().subscriptions(); // This is not available 
var subscription = event.content().subscription(); // This is availabale

it would be great if we could add this method.

Alternatives considered

Currently, we access the list of subscriptions via parsing the JSONObject:

var subscriptions = this.optJSONObject("content").optJSONArray("subscriptions");

Additional context

The subscriptions field is mentioned in the documentation for customer_deleted event here

APIException constructor should not `throw Exception`

Dealing with the Chargebee API Excpetions is quite painful. Even though they are descendants of the RuntimeException and should not need to be checked, their constructor has a throws Exception annotation, defeating the purpose!

public APIException(int httpStatusCode,JSONObject jsonObj) throws Exception {
super(jsonObj.getString("message"));
this.jsonObj = jsonObj;
this.httpStatusCode = httpStatusCode;
this.apiErrorCode = jsonObj.getString("api_error_code");
this.type = jsonObj.optString("type");
this.param = jsonObj.optString("param");
this.httpCode = httpStatusCode;
this.code = jsonObj.getString("error_code");
this.message = jsonObj.getString("error_msg");
}

Could you please remove that throws Exception declaration?

And consequently also remove all the other unnecessary throws Exception declarations from your request methods?

Add enums of accepted values for fields like Country and Currency Code

while testing the API I've found that I cannot use "GBP" as a currency code and I cannot specify "United States" as a country (seems "US" is the expected value). The fields are both strings with no indication of how the format of the values should be. Perhaps it would be better to be able to use .billingAddressCountry(CountryCode.US) and .preferredCurrencyCode(CurrencyCode.USD).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.