It seems that the following endpoint:
/1.0/kb/accounts/{account_id}/paymentMethods
does not function as you would expect it to when adding new payment methods to existing customers with a linked customer account.
The linked customer account is in STRIPE_CUSTOMER_ID. When this is NOT set, the endpoint successfully creates a new account and payment method using a browser generated "token". Other plugin properties used are payment_method_id, and customer_id, and createStripeCustomer, though the efficacy is questionable.
Params include: pluginProperty and isDefault.
Payload includes: accountId and pluginName.
Attempting to add a second payment in a similar manner fails. The plugin seems to invoke a faulty stripe endpoint sequence. The payment method is then created in killbill, but never in Stripe. Thus, on the next Janitor refresh, it is quickly removed.
I have been able to work around this as follows:
1) Invoke the stripe api directly from the application server code as follows:
try:
# Attach the token to the customer as a source
card = stripe.Customer.create_source(
customer_id,
source=token_id
)
print(f"Successfully attached card {card.id} to customer {customer_id}")
# Set this card as the default payment source
stripe.Customer.modify(
customer_id,
default_source=card.id
)
print(f"Set card {card.id} as default payment method")
return card
except stripe.error.InvalidRequestError as e:
print(f"Invalid request: {e.user_message}")
raise
except stripe.error.StripeError as e:
print(f"Stripe error: {str(e)}")
raise
2) Invoke the Janitor with paymentMethods and refresh=true
The stripe calls cause the method to appear in stripe, then the refresh causes the new payment method to appear in killbill.
This is working, however, this completely breaks the plugin abstraction. Am I missing some plugin properties that might trrigger the possible behavior? If not, I think the plugin should do this detection on it's own.
Other solutons tried: The stripe documentation suggests using the strip payment method id rather than tokens, which are being phased out. However, I could find no way to get the plugin to accept them. When you remove the token, it generates an error to include sessionId (not appropriate) or an external id, but the property as described in the error message doesn't seem to work.
Also, completely deleting the custom field and existing payment method causes it to register the new payment method, but it will have a completely different customer id on the stripe side. Stripe recommended not doing this.
Any info would be appreciated.