localstack-localstripe


Namelocalstack-localstripe JSON
Version 1.15.6.post1 PyPI version JSON
download
home_pageNone
SummaryLocalStack's fork of localstripe, a fake but stateful Stripe server that you can run locally, for testing purposes.
upload_time2024-11-23 17:04:33
maintainerNone
docs_urlNone
authorAdrien Vergé
requires_python>=3.9
licenseGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            localstripe
===========

*A fake but stateful Stripe server that you can run locally, for testing
purposes.*

This is a program that you can launch to simulate a Stripe server locally,
without touching real Stripe servers nor the Internet.

Unlike other test/mock software like `stripe-mock
<https://github.com/stripe/stripe-mock>`_, localstripe is *stateful*: it keeps
track of the actions performed (creating a customer, adding a card, etc.) so
that these actions have an impact on the next queries.

The goal is to have a ready-to-use mock server for end-to-end testing any
application.

Features
--------

- **works with any language**: localstripe is not a library that you include,
  but a real server that you can query at ``http://localhost:8420``, using
  regular Stripe API requests
- **stateful**: if you create a Stripe object (let's say, a customer), you will
  get it back on future requests
- **integrates with Stripe Elements**: localstripe includes a JavaScript file
  that can mock Stripe Elements on any webpage, allowing you to create tokens
  on the fake server, from your webpage
- **supports webhooks** that you can customize using a special API route

Limitations
-----------

- only the **latest version of Stripe API** is supported (on best effort)
- deprecated properties and features may or may not be supported
- **no Stripe Connect support**: localstripe currently only supports Stripe
  Payments, and does not support Stripe Connect

Get started
-----------

Install localstripe:

.. code:: shell

 pip install --user -U localstripe
 # or, to install globally:
 sudo pip install localstripe

Then simply run the command ``localstripe``. The fake Stripe server is now
listening on port 8420.

Or launch a container using `the Docker image
<https://hub.docker.com/r/adrienverge/localstripe/>`_:

.. code:: shell

 docker run -p 8420:8420 adrienverge/localstripe:latest

Docker image can be rebuilt using:

.. code::

 docker build --no-cache -t adrienverge/localstripe -<<EOF
 FROM python:3
 RUN pip install localstripe
 CMD ["localstripe"]
 EOF

Examples
--------

In the following example, let's create a ``Plan``, a ``Customer``, and
subscribe the latter to the former:

.. code:: shell

 curl localhost:8420/v1/plans -u sk_test_12345: \
      -d id=pro-plan \
      -d amount=2500 \
      -d currency=eur \
      -d interval=month \
      -d name="Plan for professionals"

.. code:: shell

 {
   "amount": 2500,
   "created": 1504187388,
   "currency": "eur",
   "id": "pro-plan",
   "interval": "month",
   "interval_count": 1,
   "livemode": false,
   "metadata": {},
   "name": "Plan for professionals",
   "object": "plan",
   "statement_descriptor": null,
   "trial_period_days": null
 }

.. code:: shell

 curl localhost:8420/v1/customers -u sk_test_12345: \
      -d description="Customer for david.anderson@example.com"

.. code:: shell

 {
   "id": "cus_b3IecP7GlNCPMM",
   "description": "Customer for david.anderson@example.com",
   "account_balance": 0,
   "currency": "eur",
   "default_source": null,
   ...
 }

.. code:: shell

 curl localhost:8420/v1/subscriptions -u sk_test_12345: \
      -d customer=cus_b3IecP7GlNCPMM \
      -d items[0][plan]=pro-plan

.. code:: shell

 {
   "id": "sub_UJIdAleo3FnwG7",
   "customer": "cus_b3IecP7GlNCPMM",
   "current_period_end": 1506779564,
   "current_period_start": 1504187564,
   "items": {
   ...
 }

Now if you retrieve that customer again, it has an associated subscription:

.. code:: shell

 curl localhost:8420/v1/customers/cus_b3IecP7GlNCPMM -u sk_test_12345:

.. code:: shell

 {
   "id": "cus_b3IecP7GlNCPMM",
   "description": "Customer for david.anderson@example.com",
   ...
   "subscriptions": {
     "data": [
       {
         "id": "sub_UJIdAleo3FnwG7",
         "items": {
           "data": [
             {
               "id": "si_2y5q9Q6lvAB9cr",
               "plan": {
                 "id": "pro-plan",
                 "name": "Plan for professionals",
                 "amount": 2500,
                 "currency": "eur",
                 "interval": "month",
   ...
 }

Integrate with your back-end
----------------------------

For instance in a Python application, you only need to set ``stripe.api_base``
to ``http://localhost:8420``:

.. code:: python

 import stripe

 stripe.api_key = 'sk_test_12345'
 stripe.api_base = 'http://localhost:8420'

Integrate with Stripe Elements
------------------------------

If your application takes card numbers on a web page using Stripe Elements, you
may want tokens to be sent to the mock server instead of the real Stripe
server.

To achieve this, you need to load the
``http://localhost:8420/js.stripe.com/v3/`` script into your page. It will
overwrite the global ``Stripe`` object, so new elements and card forms will
actually send data to the ``http://localhost:8420/v1/tokens`` API.

For example if you use a testing tool like Protractor, you need to inject this
JavaScript source in the web page before it creates card elements:

.. code:: html

 <script src="http://localhost:8420/js.stripe.com/v3/"></script>

Use webhooks
------------

Register a webhook using the special ``/_config`` route:

.. code:: shell

 curl localhost:8420/_config/webhooks/mywebhook1 \
      -d url=http://localhost:8888/api/url -d secret=whsec_s3cr3t

Then, localstripe will send webhooks to this url, signed using ``secret``. The
``events`` option can be used to filter events to be sent.
Only those events types are currently supported:

- Product: ``product.created``
- Plan: ``plan.created``
- Customer: ``customer.created``, ``customer.updated`` and ``customer.deleted``
- Source: ``customer.source.created``
- Subscription: ``customer.subscription.created`` and
  ``customer.subscription.deleted``
- Invoice: ``invoice.created``, ``invoice.payment_succeeded`` and
  ``invoice.payment_failed``

Flush stored data
-----------------

Flushing data programmatically can be useful to reset localstripe if your are
using it with any test framework.

Flushing stored data can be performed using the ``/_config/data`` route
with DELETE http method:

.. code:: shell

 curl -X DELETE localhost:8420/_config/data

Hacking and contributing
------------------------

To quickly run localstripe from source, and reload when a file changed:

.. code:: shell

 find -name '*.py' | entr -r python -m localstripe --from-scratch

To quickly build and run localstripe from source:

.. code:: shell

 python -m build
 pip install --user --upgrade dist/localstripe-*.tar.gz
 localstripe

If you plan to open a pull request to improve localstripe, that is so cool! To
make reviews smooth you should follow `our contributing guidelines
<CONTRIBUTING.rst>`_.

License
-------

This program is licensed under the GNU General Public License version 3.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "localstack-localstripe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Adrien Verg\u00e9",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/68/b1/b226fadbb5f4f16f3d58fc18849c012b61a3129cbb1c544d9cf97f1063bf/localstack-localstripe-1.15.6.post1.tar.gz",
    "platform": null,
    "description": "localstripe\n===========\n\n*A fake but stateful Stripe server that you can run locally, for testing\npurposes.*\n\nThis is a program that you can launch to simulate a Stripe server locally,\nwithout touching real Stripe servers nor the Internet.\n\nUnlike other test/mock software like `stripe-mock\n<https://github.com/stripe/stripe-mock>`_, localstripe is *stateful*: it keeps\ntrack of the actions performed (creating a customer, adding a card, etc.) so\nthat these actions have an impact on the next queries.\n\nThe goal is to have a ready-to-use mock server for end-to-end testing any\napplication.\n\nFeatures\n--------\n\n- **works with any language**: localstripe is not a library that you include,\n  but a real server that you can query at ``http://localhost:8420``, using\n  regular Stripe API requests\n- **stateful**: if you create a Stripe object (let's say, a customer), you will\n  get it back on future requests\n- **integrates with Stripe Elements**: localstripe includes a JavaScript file\n  that can mock Stripe Elements on any webpage, allowing you to create tokens\n  on the fake server, from your webpage\n- **supports webhooks** that you can customize using a special API route\n\nLimitations\n-----------\n\n- only the **latest version of Stripe API** is supported (on best effort)\n- deprecated properties and features may or may not be supported\n- **no Stripe Connect support**: localstripe currently only supports Stripe\n  Payments, and does not support Stripe Connect\n\nGet started\n-----------\n\nInstall localstripe:\n\n.. code:: shell\n\n pip install --user -U localstripe\n # or, to install globally:\n sudo pip install localstripe\n\nThen simply run the command ``localstripe``. The fake Stripe server is now\nlistening on port 8420.\n\nOr launch a container using `the Docker image\n<https://hub.docker.com/r/adrienverge/localstripe/>`_:\n\n.. code:: shell\n\n docker run -p 8420:8420 adrienverge/localstripe:latest\n\nDocker image can be rebuilt using:\n\n.. code::\n\n docker build --no-cache -t adrienverge/localstripe -<<EOF\n FROM python:3\n RUN pip install localstripe\n CMD [\"localstripe\"]\n EOF\n\nExamples\n--------\n\nIn the following example, let's create a ``Plan``, a ``Customer``, and\nsubscribe the latter to the former:\n\n.. code:: shell\n\n curl localhost:8420/v1/plans -u sk_test_12345: \\\n      -d id=pro-plan \\\n      -d amount=2500 \\\n      -d currency=eur \\\n      -d interval=month \\\n      -d name=\"Plan for professionals\"\n\n.. code:: shell\n\n {\n   \"amount\": 2500,\n   \"created\": 1504187388,\n   \"currency\": \"eur\",\n   \"id\": \"pro-plan\",\n   \"interval\": \"month\",\n   \"interval_count\": 1,\n   \"livemode\": false,\n   \"metadata\": {},\n   \"name\": \"Plan for professionals\",\n   \"object\": \"plan\",\n   \"statement_descriptor\": null,\n   \"trial_period_days\": null\n }\n\n.. code:: shell\n\n curl localhost:8420/v1/customers -u sk_test_12345: \\\n      -d description=\"Customer for david.anderson@example.com\"\n\n.. code:: shell\n\n {\n   \"id\": \"cus_b3IecP7GlNCPMM\",\n   \"description\": \"Customer for david.anderson@example.com\",\n   \"account_balance\": 0,\n   \"currency\": \"eur\",\n   \"default_source\": null,\n   ...\n }\n\n.. code:: shell\n\n curl localhost:8420/v1/subscriptions -u sk_test_12345: \\\n      -d customer=cus_b3IecP7GlNCPMM \\\n      -d items[0][plan]=pro-plan\n\n.. code:: shell\n\n {\n   \"id\": \"sub_UJIdAleo3FnwG7\",\n   \"customer\": \"cus_b3IecP7GlNCPMM\",\n   \"current_period_end\": 1506779564,\n   \"current_period_start\": 1504187564,\n   \"items\": {\n   ...\n }\n\nNow if you retrieve that customer again, it has an associated subscription:\n\n.. code:: shell\n\n curl localhost:8420/v1/customers/cus_b3IecP7GlNCPMM -u sk_test_12345:\n\n.. code:: shell\n\n {\n   \"id\": \"cus_b3IecP7GlNCPMM\",\n   \"description\": \"Customer for david.anderson@example.com\",\n   ...\n   \"subscriptions\": {\n     \"data\": [\n       {\n         \"id\": \"sub_UJIdAleo3FnwG7\",\n         \"items\": {\n           \"data\": [\n             {\n               \"id\": \"si_2y5q9Q6lvAB9cr\",\n               \"plan\": {\n                 \"id\": \"pro-plan\",\n                 \"name\": \"Plan for professionals\",\n                 \"amount\": 2500,\n                 \"currency\": \"eur\",\n                 \"interval\": \"month\",\n   ...\n }\n\nIntegrate with your back-end\n----------------------------\n\nFor instance in a Python application, you only need to set ``stripe.api_base``\nto ``http://localhost:8420``:\n\n.. code:: python\n\n import stripe\n\n stripe.api_key = 'sk_test_12345'\n stripe.api_base = 'http://localhost:8420'\n\nIntegrate with Stripe Elements\n------------------------------\n\nIf your application takes card numbers on a web page using Stripe Elements, you\nmay want tokens to be sent to the mock server instead of the real Stripe\nserver.\n\nTo achieve this, you need to load the\n``http://localhost:8420/js.stripe.com/v3/`` script into your page. It will\noverwrite the global ``Stripe`` object, so new elements and card forms will\nactually send data to the ``http://localhost:8420/v1/tokens`` API.\n\nFor example if you use a testing tool like Protractor, you need to inject this\nJavaScript source in the web page before it creates card elements:\n\n.. code:: html\n\n <script src=\"http://localhost:8420/js.stripe.com/v3/\"></script>\n\nUse webhooks\n------------\n\nRegister a webhook using the special ``/_config`` route:\n\n.. code:: shell\n\n curl localhost:8420/_config/webhooks/mywebhook1 \\\n      -d url=http://localhost:8888/api/url -d secret=whsec_s3cr3t\n\nThen, localstripe will send webhooks to this url, signed using ``secret``. The\n``events`` option can be used to filter events to be sent.\nOnly those events types are currently supported:\n\n- Product: ``product.created``\n- Plan: ``plan.created``\n- Customer: ``customer.created``, ``customer.updated`` and ``customer.deleted``\n- Source: ``customer.source.created``\n- Subscription: ``customer.subscription.created`` and\n  ``customer.subscription.deleted``\n- Invoice: ``invoice.created``, ``invoice.payment_succeeded`` and\n  ``invoice.payment_failed``\n\nFlush stored data\n-----------------\n\nFlushing data programmatically can be useful to reset localstripe if your are\nusing it with any test framework.\n\nFlushing stored data can be performed using the ``/_config/data`` route\nwith DELETE http method:\n\n.. code:: shell\n\n curl -X DELETE localhost:8420/_config/data\n\nHacking and contributing\n------------------------\n\nTo quickly run localstripe from source, and reload when a file changed:\n\n.. code:: shell\n\n find -name '*.py' | entr -r python -m localstripe --from-scratch\n\nTo quickly build and run localstripe from source:\n\n.. code:: shell\n\n python -m build\n pip install --user --upgrade dist/localstripe-*.tar.gz\n localstripe\n\nIf you plan to open a pull request to improve localstripe, that is so cool! To\nmake reviews smooth you should follow `our contributing guidelines\n<CONTRIBUTING.rst>`_.\n\nLicense\n-------\n\nThis program is licensed under the GNU General Public License version 3.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "LocalStack's fork of localstripe, a fake but stateful Stripe server that you can run locally, for testing purposes.",
    "version": "1.15.6.post1",
    "project_urls": {
        "documentation": "https://github.com/adrienverge/localstripe",
        "homepage": "https://github.com/adrienverge/localstripe",
        "repository": "https://github.com/adrienverge/localstripe"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bcba2065a212bf270f3019329f768db6d173e459aa3c82e1c5ee39ae35177f9",
                "md5": "a3f5984f24d70e535657cfc642eb537a",
                "sha256": "2e595d3f68b7c14d869cfcfdc8784422674a1e3131ff85dcc9fd30adaf674ea1"
            },
            "downloads": -1,
            "filename": "localstack_localstripe-1.15.6.post1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a3f5984f24d70e535657cfc642eb537a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 49077,
            "upload_time": "2024-11-23T17:04:32",
            "upload_time_iso_8601": "2024-11-23T17:04:32.506189Z",
            "url": "https://files.pythonhosted.org/packages/2b/cb/a2065a212bf270f3019329f768db6d173e459aa3c82e1c5ee39ae35177f9/localstack_localstripe-1.15.6.post1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68b1b226fadbb5f4f16f3d58fc18849c012b61a3129cbb1c544d9cf97f1063bf",
                "md5": "74fb1dada3749f35685841011cd789b7",
                "sha256": "74a6be894df842c378ba836a680093939baaf58386cc8c3ff33d63b4c246a4a3"
            },
            "downloads": -1,
            "filename": "localstack-localstripe-1.15.6.post1.tar.gz",
            "has_sig": false,
            "md5_digest": "74fb1dada3749f35685841011cd789b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 45544,
            "upload_time": "2024-11-23T17:04:33",
            "upload_time_iso_8601": "2024-11-23T17:04:33.953116Z",
            "url": "https://files.pythonhosted.org/packages/68/b1/b226fadbb5f4f16f3d58fc18849c012b61a3129cbb1c544d9cf97f1063bf/localstack-localstripe-1.15.6.post1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 17:04:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adrienverge",
    "github_project": "localstripe",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "localstack-localstripe"
}
        
Elapsed time: 0.89971s