к каталогу

📦 stripe-java/ stripe

Java library for the Stripe API.

Открыть на GitHubобновлён 4д назад
Звёзды
990
Форки
404
За неделю
За месяц
Рост %
Язык
Java

Установка и запуск

Usage

StripeExample.java

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

import com.stripe.StripeClient;
import com.stripe.exception.StripeException;
import com.stripe.model.Customer;
import com.stripe.net.RequestOptions;
import com.stripe.param.CustomerCreateParams;

public class StripeExample {

    public static void main(String[] args) {
        StripeClient client = new StripeClient("sk_test_...");
        CustomerCreateParams params =
            CustomerCreateParams
                .builder()
                .setDescription("Example description")
                .setEmail("test@example.com")
                .setPaymentMethod("pm_card_visa")  // obtained via Stripe.js
                .build();

        try {
            Customer customer = client.v1().customers().create(params);
            System.out.println(customer);
        } catch (StripeException e) {
            e.printStackTrace();
        }
    }
}

See the project's [functional tests][functional-tests] for more examples.

How to use undocumented parameters and properties

stripe-java is a typed library and it supports all public properties or parameters.

Stripe sometimes has beta which introduces new properties or parameters that are not immediately public. The library does not support these properties or parameters until they are public but there is still an approach that allows you to use them.

Parameters

To pass undocumented parameters to Stripe using stripe-java you need to use the putExtraParam() method, as shown below:

CustomerCreateParams params =
  CustomerCreateParams.builder()
    .setEmail("jenny.rosen@example.com")
    .putExtraParam("secret_feature_enabled", "true")
    .putExtraParam("secret_parameter[primary]", "primary value")
    .putExtraParam("secret_parameter[secondary]", "secondary value")
    .build();

client.v1().customers().create(params);

Properties

To retrieve undocumented properties from Stripe using Java you can use an option in the library to return the raw JSON object and return the property as a native type. An example of this is shown below:

final Customer customer = client.v1().customers().retrieve("cus_1234");
Boolean featureEnabled =
  customer.getRawJsonObject()
    .getAsJsonPrimitive("secret_feature_enabled")
    .getAsBoolean();
String primaryValue =
  customer.getRawJsonObject()
    .getAsJsonObject("secret_parameter")
    .getAsJsonPrimitive("primary")
    .getAsString();
String secondaryValue =
  customer.getRawJsonObject()
    .getAsJsonObject("secret_parameter")
    .getAsJsonPrimitive("secondary")
    .getAsString();

Из README репозитория · полный README на GitHub

Категории

Теги

javastripestripe-sdk