Код: Выделить всё
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Card;
import com.stripe.model.Customer;
import java.util.HashMap;
import java.util.Map;
public class StripeExample {
public static void main(String[] args) throws StripeException {
final String API_KEY = System.getenv("STRIPE_API_KEY");
assert API_KEY != null : "API_KEY SHOULD NOT BE NULL";
Stripe.apiKey = API_KEY;
// Retrieve the existing customer by ID
Customer customer = Customer.retrieve(customerID);
// Use a Stripe test token instead of raw card details
String testToken = "tok_visa"; // Simulates a Visa card
// Attach the test card to the customer
Map sourceParams = new HashMap();
sourceParams.put("source", testToken);
Card card = (Card) customer.getSources().create(sourceParams);
System.out.println("Card added successfully: " + card.getId());
}
}
< /code>
Я получаю < /p>
null
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.stripe.model.PaymentSourceCollection.create(java.util.Map)" because the return value of "com.stripe.model.Customer.getSources()" is null
at org.example.Application.main(Application.java:82)
Подробнее здесь: https://stackoverflow.com/questions/795 ... ith-stripe