3
votes

I'm integrating Stripe Subscriptions in our workflow, but when creating a subscription with a Customer created with a paymentMethod instead of source I receive the error This customer has no attached payment source.

If I call in the browser createToken() and attach it to the customer in the source field it works.

We integrated one-time payments using the new docs with SCA that use createPaymentMethod() and not createToken(), so our customers are saved with paymentMethod, not source, like explained here:

https://stripe.com/docs/payments/cards/saving-cards-after-payment#save-payment-method

curl https://api.stripe.com/v1/customers \
  -u sk_test_secret_token \
  -d payment_method="{{PAYMENT_METHOD_ID}}"

Furthermore, in the migration guide it says to replace createToken() with createPaymentMethod().

In Scenario 2: Charging customers off-session for their initial payment, I saw the following:

To create subscriptions and charge customers off-session for their initial payment, you need to:

1) Use CreatePaymentMethod to collect payment information

2) Create a customer using the ID of the PaymentMethod you created

3) Create the subscription

4) Set up error handling using handleCardSetup for authentication failures and handleCardPayment for authorization failures

I followed those steps. I don't create a SetupIntent (just like I don't create it in one-time payments and it works in these cases), and receive the error I said before when trying to create subscriptions.

Is it possible to create subscriptions with a customer with paymentMethod instead of source?

(We reuse cards using the customers created with paymentMethod for one-time payments, so it would be very important to be able to reuse the same customer/card for subscriptions, without the need for the user input data in stripe elements or anything of the sort, because it would break our flow for reusing cards)

1

1 Answers

2
votes

I was able to solve it by including the payment method in the field default_payment_method.

This field is described as follows:

ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. If not set, invoices will use the default payment method in the customer’s invoice settings.

So I assumed that it would use the payment method I associated with the customer when not defined. It seems it is not happening, tough, so I needed to pass it explicitly (is it a Stripe bug? or creating the customer with paymentMethod doesn't make it the default payment method in the customer’s invoice settings? I will contact Stripe to make sure).

Update (2019-09-23)

I contacted Stripe asking if this was a bug and they replied:

[...] With that being said though, this wouldn't be a bug on our end, rather expected behavior.

If you're wanting for the Payment Method that you're adding to the customer object to be used on subscriptions, or invoices, by default without specifying the default_payment_method when creating the subscription then you would want to attach the Payment Method and specify the invoice_settings.default_payment_method parameter when updating the customer. This information can be found within our API reference here:

https://stripe.com/docs/api/payment_methods/attach

The parameter to use when updating this can be found on the customer object itself, here:

https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method

This can also be specified upon customer creation, which can be seen here:

https://stripe.com/docs/api/customers/create#create_customer-invoice_settings-default_payment_method

Specifying this parameter would indicate that the card being added would be the default for subscriptions, as well as invoices, so that the default_payment_method wouldn't need to be specified upon the subscription, or invoice, creation.