0

I am using Stripe with Android I can't find what I a doing wrong to get this error :

Customer cus_xxx does not have a linked source with ID card_yyy com.stripe.exception.InvalidRequestException: Customer cus_xxx does not have a linked source with ID card_yyy.

I have already seen this SO post that deals with a comparable issue but mine is different.

Here is my workflow :

1.On my app I create a card with this code

Stripe stripe = new Stripe(context, PUBLISHABLE_KEY);
// Stripe API call to get paymentSourceId
stripe.createToken(card, new TokenCallback(){...});

This method is an HTTP API request and I get my paymentSourceId = card_yyy from the response to this webservice.

2.I get ephemeral key with an HTTP API request to my backend, I extract paymentSourceCustomerId = cus_xxx from ephemeral key

3.Finally I try to create a charge with this parameters

{
    "amount":2999,
    "currency":"USD",
    "paymentSourceCustomerId":"cus_xxx",
    "paymentSourceId":"card_yyy"
}

And then I get the error.

Moussa
  • 3,789
  • 5
  • 24
  • 41

1 Answers1

1

If you pass paymentSourceId with paymentSourceCustomerId, it is required to have that card linked with that customedId.

You have two option to link a card with customer:

  1. At the time of customer creation
curl https://api.stripe.com/v1/customers \
   -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
   -d description="Customer for emily.harris@example.com" \
   -d source=token
  1. Linking card to already created customer
curl https://api.stripe.com/v1/customers/cus_D1p9ZtnrPS4XAR/sources \ 
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \   
-d source=token

For more details: enter image description here

shan kulkarni
  • 823
  • 7
  • 17