Reputation: 519
I successfully integrated the Stripe checkout in a Java web application.
I would like to have the email and name fields prefilled. According to the docs, I have to create a new customer and than pass it to the session. Here is the relevant part of code:
Stripe.apiKey = retrieveKey("CLIENT_SECRET_KEY");
Map<String, Object> paramsC = new HashMap<>();
paramsC.put("description", "My First Test Customer (created for API docs)");
paramsC.put("email", "[email protected]");
paramsC.put("name", "some name");
Customer customer = Customer.create(paramsC);
Map<String, Object> params = new HashMap<>();
ArrayList<String> paymentMethodTypes = new ArrayList<>();
paymentMethodTypes.add("card");
params.put("payment_method_types", paymentMethodTypes);
ArrayList<HashMap<String, Object>> lineItems = new ArrayList<>();
HashMap<String, Object> lineItem = new HashMap<>();
lineItem.put("name", "Stainless Steel Water Bottle");
lineItem.put("amount", 8834);
lineItem.put("currency", "eur");
lineItem.put("quantity", 1);
lineItems.add(lineItem);
params.put("line_items", lineItems);
params.put("customer", customer.getId());
params.put("success_url", DOMAIN_URL);
params.put("cancel_url", DOMAIN_URL + "/cancel.xhtml");
RequestOptions requestOptions = RequestOptions.builder().setStripeAccount(CONNECTED_ACCOUNT_ID).build();
session = Session.create(params, requestOptions);
Unfortunately I got this error:
Severe: com.stripe.exception.InvalidRequestException: No such customer: 'cus_****'; code: resource_missing; request-id:
thrown from the line where the session is created.
Does any body knows how to fix this. Thank you very much.
Upvotes: 0
Views: 1601
Reputation: 7459
This is happening because in the requestOptions
for the Checkout session you are setting a connected account with setStripeAccount(CONNECTED_ACCOUNT_ID)
. THe customer creation does not have this, so the customer is being created on your platform account, not the connected account.
If you want to have the session on the connected account, you need to create the customer there too. You should add the same requestOptions
with setStripeAccount(CONNECTED_ACCOUNT_ID)
to your customer create request.
Upvotes: 1