Package: 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 likestripe-mock, localstripe isstateful: 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.Featuresworks with any language: localstripe is not a library that you include,
but a real server that you can query athttp://localhost:8420, using
regular Stripe API requestsstateful: if you create a Stripe object (let’s say, a customer), you will
get it back on future requestsintegrates 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 webpagesupports webhooksthat you can customize using a special API routeLimitationsonly thelatest version of Stripe APIis supported (on best effort)deprecated properties and features may or may not be supportedno Stripe Connect support: localstripe currently only supports Stripe
Payments, and does not support Stripe ConnectGet startedInstall localstripe:pipinstall--user-Ulocalstripe# or, to install globally:sudopipinstalllocalstripeThen simply run the commandlocalstripe. The fake Stripe server is now
listening on port 8420.Or launch a container usingthe Docker image:dockerrun-p8420:8420adrienverge/localstripe:latestDocker image can be rebuilt using:docker build --no-cache -t adrienverge/localstripe -<<EOF
FROM python:3
RUN pip install localstripe
CMD ["localstripe"]
EOFExamplesIn the following example, let’s create aPlan, aCustomer, and
subscribe the latter to the former:curllocalhost:8420/v1/plans-usk_test_12345:\-did=pro-plan\-damount=2500\-dcurrency=eur\-dinterval=month\-dname="Plan for professionals"{"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}curllocalhost:8420/v1/customers-usk_test_12345:\-ddescription="Customer for david.anderson@example.com"{"id":"cus_b3IecP7GlNCPMM","description":"Customer for david.anderson@example.com","account_balance":0,"currency":"eur","default_source":null,...}curllocalhost:8420/v1/subscriptions-usk_test_12345:\-dcustomer=cus_b3IecP7GlNCPMM\-ditems[0][plan]=pro-plan{"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:curllocalhost:8420/v1/customers/cus_b3IecP7GlNCPMM-usk_test_12345:{"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-endFor instance in a Python application, you only need to setstripe.api_basetohttp://localhost:8420:importstripestripe.api_key='sk_test_12345'stripe.api_base='http://localhost:8420'Integrate with Stripe ElementsIf 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 thehttp://localhost:8420/js.stripe.com/v3/script into your page. It will
overwrite the globalStripeobject, so new elements and card forms will
actually send data to thehttp://localhost:8420/v1/tokensAPI.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:<scriptsrc="http://localhost:8420/js.stripe.com/v3/"></script>Use webhooksRegister a webhook using the special/_configroute:curllocalhost:8420/_config/webhooks/mywebhook1\-durl=http://localhost:8888/api/url-dsecret=whsec_s3cr3tThen, localstripe will send webhooks to this url, signed usingsecret. Theeventsoption can be used to filter events to be sent.
Only those events types are currently supported:Product:product.createdPlan:plan.createdCustomer:customer.created,customer.updatedandcustomer.deletedSource:customer.source.createdSubscription:customer.subscription.createdandcustomer.subscription.deletedInvoice:invoice.created,invoice.payment_succeededandinvoice.payment_failedFlush stored dataFlushing 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/dataroute
with DELETE http method:curl-XDELETElocalhost:8420/_config/dataHacking and contributingTo quickly run localstripe from source, and reload when a file changed:find-name'*.py'|entr-rpython-mlocalstripe--from-scratchTo quickly build and run localstripe from source:python-mbuildpipinstall--user--upgradedist/localstripe-*.tar.gzlocalstripeIf you plan to open a pull request to improve localstripe, that is so cool! To
make reviews smooth you should followour contributing guidelines.LicenseThis program is licensed under the GNU General Public License version 3.