Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create a Charge #88

Open
matbarker opened this issue Aug 23, 2019 · 1 comment
Open

Can't create a Charge #88

matbarker opened this issue Aug 23, 2019 · 1 comment

Comments

@matbarker
Copy link

Trying to create a charge using the docker image fails with a generic error message:

#!/bin/bash
set -eux

HOST=http://localhost:8420
SK=sk_test_12345
	 
curl -sSf -u $SK: $HOST/v1/charges \
  -d amount=2000 \
  -d currency=usd \
  -d source=tok_visa

Response:

Content-Type: application/json; charset=utf-8
Content-Length: 87
Date: Thu, 22 Aug 2019 10:03:27 GMT
Server: Python/3.7 aiohttp/3.5.4

{
  "error": {
    "message": "Bad request",
    "type": "invalid_request_error"
  }
}

How do I get a more specific error message, or figure out what I'm doing wrong?

@adrienverge
Copy link
Owner

Hi @matbarker,

To know what's going wrong, the best is probably to look at the Charge class definition. I think what's failing here is:

assert (source.startswith('pm_') or source.startswith('src_')
or source.startswith('card_'))

  • Currently, localstripe only accept sources, not card tokens. The "supported" use case is to attach the token to a customer first, in order to have a card_ object:

    curl -sSf -u $SK: localhost:8420/v1/customers/cus_zLHwf2fPMEmIxF/sources
         -d source=tok_1oBvNLpoJRZ3xP

    Of course, contributions to support creating charges directly from tokens are welcome.

  • localstripe acts like real Stripe servers, which means example tokens from the docs (like tok_visa) don't work. You need to create a token, like in real-life conditions:

    curl -sSf localhost:8420/v1/tokens \
         -d key=pk_test_sldkjflaksdfj \
         -d card[number]=4242424242424242 \
         -d card[exp_month]=12 \
         -d card[exp_year]=2019 \
         -d card[cvc]=123

meatherly added a commit to meatherly/localstripe that referenced this issue Aug 7, 2020
It implements the /sources endpoint for a customer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants