Giter Club home page Giter Club logo

stripe_tester's Introduction

StripeTester

wercker status

StripeTester is a testing gem used to simulate Stripe webhooks and post them to a specified URL.

StripeTester allows you to submit webhooks to your application without hitting Stripe or requiring connectivity. You can use it in your test suite to simulate webhooks and ensure that your application reacts accordingly. You can also use StripeTester in the console to simulate webhooks easily.

Installation

Add this line to your application's Gemfile:

gem 'stripe_tester', "~> 0.5.0"

And then execute:

$ bundle

Or install it yourself as:

$ gem install stripe_tester

Requirements

Ruby >= 1.9.3

RSpec

Usage

In your test:

  1. Set the URL where the webhooks are handled:
# Normal HTTP URL
StripeTester.webhook_url = "http://www.example.com/my_post_url"

# HTTPS URL
StripeTester.webhook_url = "https://www.secure-example.com/my_post_url"
  1. If your URL is secured with a self-signed SSL certificate, disable SSL verification:
StripeTester.verify_ssl = false
  1. If you want to specify which Stripe webhook API version you would like to use (the default will be the latest supported version):
StripeTester.stripe_version = "2015-10-16"
  1. If you are using username and password in your Stripe webhook event, you can provide it in two ways:

This will set basic auth with the default username, stripe, and the password provided:

    StripeTester.webhook_password = "<password>"

Or you can set the username and password in the URL:

    # Normal HTTP URL
    StripeTester.webhook_url = "http://stripe:[email protected]/my_post_url"

    # HTTPS URL
    StripeTester.webhook_url = "https://stripe:[email protected]/my_post_url"
  1. Send the webhook. This will send a POST request to the URL with the event data as JSON:
# as a symbol
StripeTester.create_event(:invoice_created)

# or as a string
StripeTester.create_event("invoice_created")

Or if you want to overwrite certain attributes globally:

StripeTester.create_event(:invoice_created, {"amount" => 100, "currency" => 'gbp'})

Or you can explicitly overwrite certain attributes using deep object merging:

StripeTester.create_event(:customer_subscription_created, {"data"=>{"object"=>{"plan"=>{"id"=>"gold-v1"}}}}, :method=>:merge)

If you want to load the JSON only:

json = StripeTester.load_template(:invoice_payment_failed)

You can also overwrite certain attributes in the JSON:

json = StripeTester.load_template(:invoice_payment_failed, {"data"=>{"object"=>{"customer"=>"cus_MYCUSTOMERID"}}}, :method=>:merge)

Supported Stripe Webhook API Versions

Contributing

  • Fork it
  • Create your feature branch
  • Add your changes, and add a test for the changes.
  • Run tests using
  $ rspec spec
  • Make sure everything is passing
  • Push to the branch
  • Create a new Pull Request

License

Copyright (c) 2016 ButterCloud LLC.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

stripe_tester's People

Contributors

luaybs avatar lehresman avatar afhammad avatar amratab avatar seashellski avatar danarnold avatar

Watchers

James Cloos avatar Sieg Collado avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.