Skip to content

Instantly share code, notes, and snippets.

@fred-stripe
Created April 3, 2020 22:03
Show Gist options
  • Save fred-stripe/0f61436d664d03c31dfc3ba86c3fc60b to your computer and use it in GitHub Desktop.
Save fred-stripe/0f61436d664d03c31dfc3ba86c3fc60b to your computer and use it in GitHub Desktop.
Simple stripe-java example that uses Maven to pull down the requirements
// To appease Maven, put this file in src/main/java/example/HelloStripe.java
// cd your-copy-of-this-project
// mkdir -p src/main/java/example/
// mv HelloStripe.java src/main/java/example/
package example;
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 HelloStripe {
public static void main(String[] args) {
System.out.println("Hello, Stripe!");
Stripe.apiKey = "…";
Map<String, Object> customerMap = new HashMap<String, Object>();
customerMap.put("description", "Example descriptipn");
customerMap.put("email", "test@example.com");
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();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>stripe-with-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>18.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>example.HelloStripe</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment