Skip to content

Instantly share code, notes, and snippets.

@ryansch
Created June 4, 2015 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryansch/ef0a3f74ac5a81b4f949 to your computer and use it in GitHub Desktop.
Save ryansch/ef0a3f74ac5a81b4f949 to your computer and use it in GitHub Desktop.
Chargify Webhook Feature Test
require 'feature/feature_helper'
feature 'Something involving chargify webhooks', :vcr, driver: :mechanize do
def chargify_webhook(from:, to:, subscription_id:)
payload = {subscription: {
id: subscription_id,
previous_state: from,
state: to
# Any other needed subscription info should go here
}}
using_session(:chargify) do
page.driver.browser.process_and_follow_redirects(
:post,
chargify_hooks_path,
{event: :subscription_state_change, payload: payload},
{'X-Chargify-Webhook-Signature-Hmac-Sha-256' => 'deadbeef'}
)
end
end
scenario 'Sign up, dunning, cancellation' do
# Test set up, Sign up
# Trigger dunning
chargify_webhook(from: :active, to: :past_due, subscription_id: 123)
# Trigger cancellation
chargify_webhook(from: :past_due, to: :canceled, subscription_id: 123)
# Expectations, etc
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment