title: Setting a Stripe Subscription with a Customer without a Default PaymentMethod in Java
body: <p><strong>This question is a misunderstanding on how to collect a PaymentMethod for a subscription, with the new SCA requirements. The key, was to read carefully how to <a href="https://stripe.com/docs/billing/subscriptions/set-up-subscription0025" rel="nofollow noreferrer">Sep up a Subscription</a>, which is slightly different than with single payments.</strong> </p>
  
  <p>I'm migrating a Stripe implementation to the version 16.4.0, for an app developed with Java using the Spring-boot framework, in order to support the Strong Customer Authentication (SCA) requirements.</p>
  
  <p>The problem is that <strong>I can't create a subscription, because the customer doesn't have any Payment Method</strong>.</p>
  
  <p>That's my workflow for a subscription:</p>
  
  <p>I create a customer:</p>
  
  <pre><code>   Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();
     params.put("name", customerName);
     params.put("email", user.getUsername());
     params.put("description", "idweb: " + user.getIdweb() + " " + customerName);
     Customer customer = Customer.create(params);
     customerId = customer.getId();
  </code></pre>
  
  <p>Next, I create a subscription for this customer:</p>
  
  <pre><code>   Map&lt;String, Object&gt; firstItem = new HashMap&lt;&gt;();
     firstItem.put("plan", baseFee);
     firstItem.put("quantity", 1);
  
     Map&lt;String, Object&gt; secondItem = new HashMap&lt;&gt;();
     secondItem.put("plan", perUnitFee);
     secondItem.put("quantity", propertiesBase);
  
     Map&lt;String, Object&gt; items = new HashMap&lt;&gt;();
     items.put("0", firstItem);
     items.put("1", secondItem);
  
     Map&lt;String, Object&gt; metadata = new HashMap&lt;&gt;();
     metadata.put("properties", properties);
     metadata.put("RwRate", stripePlans.getRwRate());
  
     Map&lt;String, Object&gt; subscriptionParams = new HashMap&lt;&gt;();
     subscriptionParams.put("customer", customerId);
     subscriptionParams.put("collection_method", "charge_automatically");
     subscriptionParams.put("items", items);
     subscriptionParams.put("metadata", metadata);
  
     Subscription subscription = Subscription.create(subscriptionParams);
  
  </code></pre>
  
  <p>Here the system raises this error:</p>
  
  <pre><code>com.stripe.exception.InvalidRequestException: This customer has no attached payment source or default payment method.
  </code></pre>
  
  <p>As I have understood from the documentation <em>...using an API version on or after 2019-03-14</em>, the system sets a subscription into the status <em>incomplete</em>, if a payment intent fails, so that we can collect the payment method at the front end.</p>
  
  <p>If I could create the subscription, I would take its latest invoice from which I would take its Payment Intent to pass the <em>Client Secret</em> to the front end.</p>
  
  <pre><code>    Invoice invoice = Invoice.retrieve(subscription.getLatestInvoice());
      PaymentIntent paymentIntent = PaymentIntent.retrieve(invoice.getPaymentIntent());
      model.addAttribute("clientSecret", paymentIntent.getClientSecret());
  </code></pre>
  
  <p>From this point onwards, I should be able to assign the collected payment method to the guest and leave the subscription active, for the next payments, as it has been working until now without the SCA requirements.</p>
  
  <p><strong>I may be missing something or my approach may be wrong, in any case any advice would be more than welcome</strong>. I've read about different approaches, setting a trial period or setting a <em>SetupIntent</em>. But my ideal scenario, is to charge the first quota when collecting the customer's card and leaving the subscription ready, for the next ones to be automatically charged.</p>