pinax / pinax-stripe-light

a payments Django app for Stripe
MIT License
681 stars 285 forks source link

Error: This customer has no attached payment source #233

Open jayfk opened 8 years ago

jayfk commented 8 years ago

I followed the getting started docs, but when running python manage.py init_customers, I'm getting:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.5/site-packages/pinax/stripe/management/commands/init_customers.py", line 15, in handle
    customers.create(user=user)
  File "/usr/local/lib/python3.5/site-packages/pinax/stripe/actions/customers.py", line 49, in create
    trial_end=trial_end
  File "/usr/local/lib/python3.5/site-packages/stripe/resource.py", line 406, in create
    response, api_key = requestor.request('post', url, params, headers)
  File "/usr/local/lib/python3.5/site-packages/stripe/api_requestor.py", line 138, in request
    resp = self.interpret_response(rbody, rcode, rheaders)
  File "/usr/local/lib/python3.5/site-packages/stripe/api_requestor.py", line 270, in interpret_response
    self.handle_api_error(rbody, rcode, resp, rheaders)
  File "/usr/local/lib/python3.5/site-packages/stripe/api_requestor.py", line 157, in handle_api_error
    rbody, rcode, resp, rheaders)
stripe.error.InvalidRequestError: Request req_7iDAhjdUPMZ7TC: This customer has no attached payment source```
ossanna16 commented 8 years ago

@jayfk Would you mind joining our Pinax Slack team (http://slack.pinaxproject.com) and bringing this up in the #pinax-stripe channel? Someone should be able to help you faster if you ping us in Slack. Thank you! :)

paltman commented 8 years ago

@jayfk this does seem like a bug, i'm going to need to try and reproduce it so I can debug further.

paltman commented 8 years ago

@jayfk so i just started with a fresh project:

pinax start --dev stripe mytestproject

I then seeded the database with some users and ran init_customers using a demo stripe account and customers were created just fine.

  1. Was this an existing site you were adding users to?
  2. Were you upgrading from a previous version of pinax-stripe (django-stripe-payments)?
  3. Do you have active users in your Stripe account?
  4. What version of the API is your Stripe account set to?

Thanks, Patrick

jayfk commented 8 years ago

Was this an existing site you were adding users to?

No, I started relatively fresh with a cookiecutter-django project.

Were you upgrading from a previous version of pinax-stripe (django-stripe-payments)?

No.

Do you have active users in your Stripe account?

I've created a couple of test users on the stripe dashboard, but does this matter here? When looking at the code, all init_customers is doing is to call customers.create for every user.

What version of the API is your Stripe account set to?

2015-10-16 (latest)

If I get a chance, I'll try to reproduce it with a new demo account on a new project.

paltman commented 8 years ago

Do you have your stripe account setup in such a way that there is a default plan or something? You should be able to create a customer without having a payment source, but it seems like perhaps in your case on your Stripe account that customer is trying to be added to a plan or something. Still looking.

paltman commented 8 years ago

@jayfk

Oh I see, I bet the plan settings.PINAX_STRIPE_DEFAULT_PLAN is not None or points to a plan that doesn't have a trial period so it's trying to charge immediately upon customer creation and when it can't the exception is being raised. I believe this is the proper behavior but open to ideas from your perspective.

Have you set PINAX_STRIPE_DEFAULT_PLAN to something?

mackinnon3540 commented 8 years ago

I had this issue, too. Users could not sign up. My settings.py had a default plan as follows: PINAX_STRIPE_DEFAULT_PLAN='plan1' where 'plan1' was the id of my stripe subscription plan. In my stripe account, 'plan1' had a trial period of 15 days. To get this to work, I had to remove the default plan from settings.py, then from the shell, run:

from pinax.stripe.actions import plans

plans.sync_plans() This added the plan to my db. The new users could then sign up and subscribe to the plan, but I had to leave the default plan out of my settings.py.

villancikos commented 7 years ago

I don't think this is a bug on the code. Perhaps, the problem has to do with the configuration of the plan. At least that was my problem. I didn't had a "grace period" activated hence creating the same issue. So, try adding the "trial_period_days" to check if ends with your error. It worked for me. :)

ThunderTrent commented 5 years ago

Having the same issue.. I don't want to have a grace period on my plan. I should be able to create a customer and then add a card afterwards?

dalanmiller commented 5 years ago

Hey all, the reason for this is because by default Subscriptions are charged at the beginning of the term, without a payment method attached to the Customer object the initial Invoice would be immediately un-payable.

One work around this as mentioned is using one of the trial_ parameters which will delay that initial charge.

https://stripe.com/docs/api/subscriptions/create#create_subscription-trial_end

ThunderTrent commented 5 years ago
token = tokenResults.id
        from pinax.stripe.actions import customers
        customers.create(user=User.objects.get(pk=user.pk),charge_immediately=False, plan=None)
        from pinax.stripe.actions.sources import create_card
        create_card(customer=User.objects.get(pk=user.pk).customer,token=token)
        from pinax.stripe.actions.subscriptions import create
        if planType == "Monthly":
            create(customer=User.objects.get(pk=user.pk).customer,plan='XXX',quantity=1,trial_days=0)
        else:
            create(customer=User.objects.get(pk=user.pk).customer,plan='XX',quantity=1,trial_days=0)

I was able to get the desired results without putting anyone on a trial this way -- for anyone looking for a way to do it later.