All Projects → stripe → Stripe Java

stripe / Stripe Java

Licence: mit
Java library for the Stripe API.

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Stripe Java

Stripe Laravel
Cartalyst Stripe package integration for Laravel.
Stars: ✭ 286 (-46.04%)
Mutual labels:  stripe
Stripe Webhook Monitor
Stripe Webhook Monitor provides a real-time feed and graph of Stripe events received via webhooks. 📈✨
Stars: ✭ 356 (-32.83%)
Mutual labels:  stripe
Checkout One Time Payments
Use Checkout to quickly collect one-time payments.
Stars: ✭ 417 (-21.32%)
Mutual labels:  stripe
React Stripe Elements
Moved to stripe/react-stripe-js.
Stars: ✭ 3,047 (+474.91%)
Mutual labels:  stripe
Checkout Single Subscription
Learn how to combine Checkout and Billing for fast subscription pages
Stars: ✭ 310 (-41.51%)
Mutual labels:  stripe
Digota
ecommerce microservice
Stars: ✭ 382 (-27.92%)
Mutual labels:  stripe
Yclas
Yclas Self Hosted is a powerful script that can transform any domain into a fully customizable classifieds site within a few seconds.
Stars: ✭ 276 (-47.92%)
Mutual labels:  stripe
Vue Stripe Elements
A Vue 2 component collection for StripeElements
Stars: ✭ 498 (-6.04%)
Mutual labels:  stripe
React Stripe Menu
A clone of Stripe's animated menu using React, Styled Components and React-Flip-Toolkit
Stars: ✭ 352 (-33.58%)
Mutual labels:  stripe
Flasksaas
A great starting point to build your SaaS in Flask & Python, with Stripe subscription billing 🚀
Stars: ✭ 412 (-22.26%)
Mutual labels:  stripe
Laravel Stripe Webhooks
Handle Stripe webhooks in a Laravel application
Stars: ✭ 300 (-43.4%)
Mutual labels:  stripe
Accept A Card Payment
Learn how to accept a basic card payment on web, iOS, Android
Stars: ✭ 301 (-43.21%)
Mutual labels:  stripe
Api
🏁🛠️ SaaS backend & API framework based on @nestjs
Stars: ✭ 390 (-26.42%)
Mutual labels:  stripe
Firebase Cms
A CMS + E-commerce platform built with Angular and Firebase
Stars: ✭ 286 (-46.04%)
Mutual labels:  stripe
Stripe Connect Rocketrides
Sample on-demand platform built on Stripe: Connect onboarding for pilots, iOS app for passengers to request rides.
Stars: ✭ 426 (-19.62%)
Mutual labels:  stripe
Cdk Constructs
A collection of higher-level aws cdk constructs: slack-approval-workflow, #slack & msteams notifications, chatops, blue-green-container-deployment, codecommit-backup, OWASP dependency-check, contentful-webhook, github-webhook, stripe-webhook, static-website, pull-request-check, pull-request-approval-rule, codepipeline-merge-action, codepipeline-check-parameter-action...
Stars: ✭ 282 (-46.79%)
Mutual labels:  stripe
Appcenter
Pay-what-you-want app store for elementary OS
Stars: ✭ 358 (-32.45%)
Mutual labels:  stripe
Payumbundle
Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
Stars: ✭ 509 (-3.96%)
Mutual labels:  stripe
Next Stripe
Simplified server-side Stripe workflows in Next.js
Stars: ✭ 480 (-9.43%)
Mutual labels:  stripe
Gringotts
A complete payment library for Elixir and Phoenix Framework
Stars: ✭ 396 (-25.28%)
Mutual labels:  stripe

Stripe Java client library

Maven Central JavaDoc Build Status

The official Stripe Java client library.

Installation

Requirements

  • Java 1.8 or later

Gradle users

Add this dependency to your project's build file:

implementation "com.stripe:stripe-java:20.41.0"

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.stripe</groupId>
  <artifactId>stripe-java</artifactId>
  <version>20.41.0</version>
</dependency>

Others

You'll need to manually install the following JARs:

ProGuard

If you're planning on using ProGuard, make sure that you exclude the Stripe client library. You can do this by adding the following to your proguard.cfg file:

-keep class com.stripe.** { *; }

Documentation

Please see the Java API docs for the most up-to-date documentation.

See video demonstrations covering how to use the library.

You can also refer to the online Javadoc.

Usage

StripeExample.java

import java.util.HashMap;
import java.util.Map;

import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Customer;
import com.stripe.net.RequestOptions;

public class StripeExample {

    public static void main(String[] args) {
        Stripe.apiKey = "sk_test_...";

        Map<String, Object> customerMap = new HashMap<String, Object>();
        customerMap.put("description", "Example description");
        customerMap.put("email", "[email protected]");
        customerMap.put("payment_method", "pm_card_visa"); // obtained via Stripe.js

        try {
            Customer customer = Customer.create(customerMap);
            System.out.println(customer);
        } catch (StripeException e) {
            e.printStackTrace();
        }
    }
}

See the project's functional tests for more examples.

Per-request Configuration

All of the request methods accept an optional RequestOptions object. This is used if you want to set an idempotency key, if you are using Stripe Connect, or if you want to pass the secret API key on each method.

RequestOptions requestOptions = new RequestOptionsBuilder()
    .setApiKey("sk_test_...")
    .setIdempotencyKey("a1b2c3...")
    .setStripeAccount("acct_...")
    .build();

Customer.list(null, requestOptions);

Customer.retrieve("cus_123456789", requestOptions);

Configuring automatic retries

The library can be configured to automatically retry requests that fail due to an intermittent network problem or other knowingly non-deterministic errors. This can be enabled globally:

Stripe.setMaxNetworkRetries(2);

Or on a finer grain level using RequestOptions:

RequestOptions options = RequestOptions.builder()
    .setMaxNetworkRetries(2)
    .build();
Customer.create(params, options);

Idempotency keys are added to requests to guarantee that retries are safe.

Configuring Timeouts

Connect and read timeouts can be configured globally:

Stripe.setConnectTimeout(30 * 1000); // in milliseconds
Stripe.setReadTimeout(80 * 1000);

Or on a finer grain level using RequestOptions:

RequestOptions options = RequestOptions.builder()
    .setConnectTimeout(30 * 1000) // in milliseconds
    .setReadTimeout(80 * 1000)
    .build();
Customer.create(params, options);

Please take care to set conservative read timeouts. Some API requests can take some time, and a short timeout increases the likelihood of a problem within our servers.

Configuring DNS Cache TTL

We cannot guarantee that the IP address of the Stripe API will be static. Commonly, default JVM configurations can have their DNS cache TTL set to forever. If Stripe's IP address changes, your application's requests to Stripe will all fail until the JVM restarts. Therefore we recommend that you modify the JVM's networkaddress.cache.ttl property to 60 seconds.

Writing a plugin

If you're writing a plugin that uses the library, we'd appreciate it if you identified using Stripe.setAppInfo():

Stripe.setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");

This information is passed along when the library makes calls to the Stripe API.

Request latency telemetry

By default, the library sends request latency telemetry to Stripe. These numbers help Stripe improve the overall latency of its API for all users.

You can disable this behavior if you prefer:

Stripe.enableTelemetry = false;

Development

The test suite depends on stripe-mock, so make sure to fetch and run it from a background terminal (stripe-mock's README also contains instructions for installing via Homebrew and other methods):

go get -u github.com/stripe/stripe-mock
stripe-mock

To run all checks (tests and code formatting):

./gradlew check

To run the tests:

./gradlew test

You can run particular tests by passing --tests Class#method. Make sure you use the fully qualified class name. For example:

./gradlew test --tests com.stripe.model.AccountTest
./gradlew test --tests com.stripe.functional.CustomerTest
./gradlew test --tests com.stripe.functional.CustomerTest.testCustomerCreate

The library uses Spotless along with google-java-format for code formatting. Code must be formatted before PRs are submitted, otherwise CI will fail. Run the formatter with:

./gradlew spotlessApply

The library uses Project Lombok. While it is not a requirement, you might want to install a plugin for your favorite IDE to facilitate development.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].