diff --git a/Gemfile b/Gemfile index 7aa5dc465..f70f08194 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'capistrano-ext' gem 'radix62', '~> 1.0.1' gem 'streamio-ffmpeg' gem 'rubyzip', :require => "zip" +gem 'stripe', :git => "https://github.com/stripe/stripe-ruby" # needed for looser jpeg header compat gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" diff --git a/Gemfile.lock b/Gemfile.lock index ab92e44d8..7581f49dc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,15 @@ GIT specs: ruby-imagespec (0.3.1) +GIT + remote: https://github.com/stripe/stripe-ruby + revision: da216fd53b7a5386c136e93bdfe5efaff20682b7 + specs: + stripe (1.16.0) + json (~> 1.8.1) + mime-types (>= 1.25, < 3.0) + rest-client (~> 1.4) + GEM remote: https://rubygems.org/ specs: @@ -131,6 +140,7 @@ GEM net-ssh (2.8.0) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) + netrc (0.8.0) newrelic_rpm (3.9.6.257) nokogiri (1.6.1) mini_portile (~> 0.5.0) @@ -168,6 +178,9 @@ GEM raindrops (0.13.0) rake (10.3.2) ref (1.0.5) + rest-client (1.7.2) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) rmagick (2.13.3) ruby-prof (0.14.2) rubyzip (1.1.6) @@ -284,6 +297,7 @@ DEPENDENCIES sprockets-rails statistics2 streamio-ffmpeg + stripe! term-ansicolor therubyracer timecop diff --git a/app/assets/stylesheets/specific/users.css.scss b/app/assets/stylesheets/specific/users.css.scss index 35e99de38..cdb7e0fdd 100644 --- a/app/assets/stylesheets/specific/users.css.scss +++ b/app/assets/stylesheets/specific/users.css.scss @@ -87,6 +87,10 @@ div#c-users { max-width: 40em; font-size: 1.2em; + form.stripe { + display: inline; + } + div#feature-comparison { overflow: hidden; margin-bottom: 1em; diff --git a/app/controllers/user_upgrades_controller.rb b/app/controllers/user_upgrades_controller.rb new file mode 100644 index 000000000..52db53a94 --- /dev/null +++ b/app/controllers/user_upgrades_controller.rb @@ -0,0 +1,50 @@ +class UserUpgradesController < ApplicationController + before_filter :member_only + + def create + if params[:desc] == "Upgrade to Gold" + level = User::Levels::GOLD + cost = 2000 + + elsif params[:desc] == "Upgrade to Platinum" + level = User::Levels::PLATINUM + cost = 4000 + + elsif params[:desc] == "Upgrade Gold to Platinum" && CurrentUser.user.level == User::Levels::GOLD + level = User::Levels::PLATINUM + cost = 2000 + + else + render :text => "invalid desc", :status => 422 + return + end + + @user = CurrentUser.user + stripe_token = params[:stripeToken] + + begin + charge = Stripe::Charge.create( + :amount => cost, + :currency => "usd", + :card => params[:stripeToken], + :description => params[:desc] + ) + @user.promote_to!(level, :skip_feedback => true) + UserMailer.upgrade(@user, params[:email]).deliver + flash[:success] = true + rescue Stripe::CardError => e + flash[:error] = e.message + end + + redirect_to user_upgrade_path + end + + def new + unless CurrentUser.user.is_anonymous? + TransactionLogItem.record_account_upgrade_view(CurrentUser.user, request.referer) + end + end + + def show + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a337573ae..3049a56bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -59,24 +59,6 @@ class UsersController < ApplicationController respond_with(@user) end - def upgrade_information - unless CurrentUser.user.is_anonymous? - TransactionLogItem.record_account_upgrade_view(CurrentUser.user, request.referer) - end - end - - def upgrade - @user = User.find(params[:id]) - - if params[:email] =~ /paypal/ - UserMailer.upgrade_fail(params[:email]).deliver - else - UserMailer.upgrade(@user, params[:email]).deliver - end - - redirect_to user_path(@user), :notice => "Email was sent" - end - def cache @user = User.find(params[:id]) @user.update_cache diff --git a/app/helpers/user_upgrades_helper.rb b/app/helpers/user_upgrades_helper.rb new file mode 100644 index 000000000..960ba1977 --- /dev/null +++ b/app/helpers/user_upgrades_helper.rb @@ -0,0 +1,20 @@ +module UserUpgradesHelper + def stripe_button(desc, cost) + html = %{ +
+ + #{hidden_field_tag(:desc, desc)} + +
+ } + + raw(html) + end +end diff --git a/app/logical/current_user.rb b/app/logical/current_user.rb index 69efcb215..272f50c0e 100644 --- a/app/logical/current_user.rb +++ b/app/logical/current_user.rb @@ -74,7 +74,7 @@ class CurrentUser end def self.set_safe_mode(req) - if req.host =~ /safe/ + if req.host =~ /safe/ || req.params[:safe_mode] Thread.current[:safe_mode] = true else Thread.current[:safe_mode] = false diff --git a/app/logical/user_promotion.rb b/app/logical/user_promotion.rb index 15f01db8c..cd6e5b1c6 100644 --- a/app/logical/user_promotion.rb +++ b/app/logical/user_promotion.rb @@ -1,10 +1,11 @@ class UserPromotion - attr_reader :user, :promoter, :new_level + attr_reader :user, :promoter, :new_level, :options - def initialize(user, promoter, new_level) + def initialize(user, promoter, new_level, options = {}) @user = user @promoter = promoter @new_level = new_level + @options = options end def promote! @@ -14,7 +15,7 @@ class UserPromotion user.inviter_id = promoter.id create_transaction_log_item - create_user_feedback + create_user_feedback unless options[:skip_feedback] create_dmail user.save diff --git a/app/models/post.rb b/app/models/post.rb index 6b2df0d28..c339ab47b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1484,6 +1484,7 @@ class Post < ActiveRecord::Base def visible? return false if !Danbooru.config.can_user_see_post?(CurrentUser.user, self) return false if CurrentUser.safe_mode? && rating != "s" + return false if CurrentUser.safe_mode? && post.has_tag?("toddlercon|toddler|diaper|tentacle|rape|bestiality|beastiality|lolita|loli|nude|shota|pussy|penis") return false if is_banned? && !CurrentUser.is_gold? return true end diff --git a/app/models/user.rb b/app/models/user.rb index 6e3a0fdac..6dee9045a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -271,8 +271,8 @@ class User < ActiveRecord::Base end end - def promote_to!(new_level) - UserPromotion.new(self, CurrentUser.user, new_level).promote! + def promote_to!(new_level, options = {}) + UserPromotion.new(self, CurrentUser.user, new_level, options).promote! end def promote_to_admin_if_first_user diff --git a/app/views/user_upgrades/_stripe_payment.html.erb b/app/views/user_upgrades/_stripe_payment.html.erb new file mode 100644 index 000000000..a26c8ae68 --- /dev/null +++ b/app/views/user_upgrades/_stripe_payment.html.erb @@ -0,0 +1,8 @@ +

Upgrading from Gold to Platinum will only cost $20. If you have any further questions or concerns, feel free to contact me at <%= mail_to Danbooru.config.contact_email, nil, :encode => :javascript %>.

+ +<% if CurrentUser.user.level < User::Levels::GOLD %> + <%= stripe_button("Upgrade to Gold", 2000) %> + <%= stripe_button("Upgrade to Platinum", 4000) %> +<% elsif CurrentUser.user.level < User::Levels::PLATINUM %> + <%= stripe_button("Upgrade Gold to Platinum", 2000) %> +<% end %> diff --git a/app/views/user_upgrades/_unavailable_payment.html.erb b/app/views/user_upgrades/_unavailable_payment.html.erb new file mode 100644 index 000000000..a5c3ae85f --- /dev/null +++ b/app/views/user_upgrades/_unavailable_payment.html.erb @@ -0,0 +1 @@ +

You can upgrade your account at <%= link_to "Safebooru", new_user_upgrade_path(:protocol => "https", :host => "safebooru.donmai.us", :only_path => false), :target => "_blank" %>.

\ No newline at end of file diff --git a/app/views/user_upgrades/new.html.erb b/app/views/user_upgrades/new.html.erb new file mode 100644 index 000000000..bc07910bf --- /dev/null +++ b/app/views/user_upgrades/new.html.erb @@ -0,0 +1,98 @@ +
+
+

Upgrade Your Account

+ +

Annoyed by ads? Want more searching power? Upgrade your account and become a power user of the best database of anime artwork on the internet.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BasicGoldPlatinum
CostFree$20

One time fee

$40

One time fee

Tag Limit2612
Favorite Limit10,00020,000Unlimited
Page Limit1,0002,0005,000
Tag SubscriptionsNoYesYes
See Censored TagsNoYesYes
API Hourly Limit3,00010,00020,000
Database Timeout3 sec6 sec9 sec
Variable Posts Per PageNoYesYes
Name ChangesNoYesYes
+
+ + <% if CurrentUser.safe_mode? %> + <%= render "stripe_payment" %> + <% else %> + <%= render "unavailable_payment" %> + <% end %> +
+
+ +<%= render "users/secondary_links" %> + +<% content_for(:page_title) do %> + Upgrade - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/user_upgrades/show.html.erb b/app/views/user_upgrades/show.html.erb new file mode 100644 index 000000000..443c54920 --- /dev/null +++ b/app/views/user_upgrades/show.html.erb @@ -0,0 +1,22 @@ +
+
+ <% if flash[:disable] %> +

You can upgrade your account at <%= link_to "Safebooru", new_user_upgrade_path(:protocol => "https", :host => "safebooru.donmai.us", :only_path => false) %>.

+ <% elsif flash[:success] %> +

Congradulations!

+ +

You are now a <%= CurrentUser.user.level_string %> level account. Thanks for supporting the site!

+

<%= link_to "Return to posts", posts_path %>

+ <% elsif flash[:error] %> +

An error occurred!

+

<%= flash[:error] %>

+

<%= link_to "Try again", new_user_upgrade_path %>

+ <% end %> +
+
+ +<%= render "users/secondary_links" %> + +<% content_for(:page_title) do %> + Upgrade - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index f65559561..d08d9d25b 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -21,8 +21,8 @@
  • <%= link_to "Send message", new_dmail_path(:dmail => {:to_id => @user.id}) %>
  • <% end %> - <% if !CurrentUser.is_gold? %> -
  • <%= link_to "Upgrade", upgrade_information_users_path %>
  • + <% if CurrentUser.is_member? || CurrentUser.is_gold? %> +
  • <%= link_to "Upgrade", new_user_upgrade_path %>
  • <% end %> <% if CurrentUser.is_moderator? %> diff --git a/app/views/users/_upgrade_notice.html.erb b/app/views/users/_upgrade_notice.html.erb index 2a3eb5a90..f6e8f6141 100644 --- a/app/views/users/_upgrade_notice.html.erb +++ b/app/views/users/_upgrade_notice.html.erb @@ -1,4 +1,4 @@
    -

    <%= link_to "Upgrade your account for only $20!", upgrade_information_users_path %>

    +

    <%= link_to "Upgrade your account for only $20!", new_user_upgrade_path %>

    <%= link_to "No thanks", "#", :id => "hide-upgrade-account-notice" %>

    diff --git a/app/views/users/upgrade_information.html.erb b/app/views/users/upgrade_information.html.erb index ca34cba1c..43516000e 100644 --- a/app/views/users/upgrade_information.html.erb +++ b/app/views/users/upgrade_information.html.erb @@ -2,7 +2,94 @@

    Upgrade Your Account

    -

    Upgrades are currently not available.

    +

    Annoyed by ads? Want more searching power? Upgrade your account and become a power user of the best database of anime artwork on the internet.

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    BasicGoldPlatinum
    CostFree$20

    One time fee

    $40

    One time fee

    Tag Limit2612
    Favorite Limit10,00020,000Unlimited
    Page Limit1,0002,0005,000
    Tag SubscriptionsNoYesYes
    See Censored TagsNoYesYes
    API Hourly Limit3,00010,00020,000
    Database Timeout3 sec6 sec9 sec
    Variable Posts Per PageNoYesYes
    Name ChangesNoYesYes
    +
    +

    Upgrading from Gold to Platinum will only cost $20. If you have any further questions or concerns, feel free to contact me at <%= mail_to Danbooru.config.contact_email, nil, :encode => :javascript %>.

    + + <% if true || CurrentUser.user.level < User::Levels::GOLD %> + <%= stripe_button("Upgrade to Gold", 2000) %> + <%= stripe_button("Upgrade to Platinum", 4000) %> + <% elsif CurrentUser.user.level < User::Levels::PLATINUM %> + <%= stripe_button("Upgrade Gold to Platinum", 2000) %> + <% end %>
    diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index a1a65005a..7a053c87e 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -9,7 +9,11 @@ module Danbooru # The name of this Danbooru. def app_name - "Danbooru" + if CurrentUser.safe_mode? + "Safebooru" + else + "Danbooru" + end end # The hostname of the server. @@ -322,5 +326,13 @@ module Danbooru def shared_dir_path "/var/www/danbooru2/shared" end + + def stripe_secret_key + "sk_test_kHviyCxbt9kBxeu46TeefJQH" + end + + def stripe_publishable_key + "pk_test_5lKN65jYpUw8EActq8RMkQxH" + end end end diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb new file mode 100644 index 000000000..43495044b --- /dev/null +++ b/config/initializers/stripe.rb @@ -0,0 +1 @@ +Stripe.api_key = Danbooru.config.stripe_secret_key diff --git a/config/routes.rb b/config/routes.rb index a5378c559..46c439fba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -235,16 +235,15 @@ Rails.application.routes.draw do resources :uploads resources :users do collection do - get :upgrade_information get :search get :custom_style end member do delete :cache - post :upgrade end end + resource :user_upgrade, :only => [:new, :create, :show] resources :user_feedbacks do collection do get :search diff --git a/test/controllers/user_upgrades_controller_test.rb b/test/controllers/user_upgrades_controller_test.rb new file mode 100644 index 000000000..021142e39 --- /dev/null +++ b/test/controllers/user_upgrades_controller_test.rb @@ -0,0 +1,113 @@ +require 'test_helper' + +class UserUpgradesControllerTest < ActionController::TestCase + def get_stripe_token + Stripe::Token.create( + :card => { + :number => "4242424242424242", + :exp_month => 1, + :exp_year => 1.year.from_now.year, + :cvc => "123" + } + ) + end + + setup do + @user = FactoryGirl.create(:user) + end + + context "#create" do + context "for basic -> gold" do + should "promote the account" do + VCR.use_cassette("stripe-basic-to-gold", :record => :once) do + post :create, {:stripeToken => get_stripe_token.id, :desc => "Upgrade to Gold", :email => "nowhere@donmai.us"}, {:user_id => @user.id} + end + assert_redirected_to user_upgrade_path + @user.reload + assert_equal(User::Levels::GOLD, @user.level) + end + end + + context "for basic -> platinum" do + should "promote the account" do + VCR.use_cassette("stripe-basic-to-plat", :record => :once) do + post :create, {:stripeToken => get_stripe_token.id, :desc => "Upgrade to Platinum", :email => "nowhere@donmai.us"}, {:user_id => @user.id} + end + assert_redirected_to user_upgrade_path + @user.reload + assert_equal(User::Levels::PLATINUM, @user.level) + end + end + + context "for gold -> platinum" do + context "when the user is gold" do + setup do + @user.update_attribute(:level, User::Levels::GOLD) + end + + should "promote the account" do + VCR.use_cassette("stripe-gold-to-plat", :record => :once) do + post :create, {:stripeToken => get_stripe_token.id, :desc => "Upgrade Gold to Platinum", :email => "nowhere@donmai.us"}, {:user_id => @user.id} + end + assert_redirected_to user_upgrade_path + @user.reload + assert_equal(User::Levels::PLATINUM, @user.level) + end + end + + context "when the user is not gold" do + should "fail" do + VCR.use_cassette("stripe-gold-to-plat-bad", :record => :once) do + post :create, {:stripeToken => get_stripe_token.id, :desc => "Upgrade Gold to Platinum", :email => "nowhere@donmai.us"}, {:user_id => @user.id} + end + assert_response 422 + @user.reload + assert_equal(User::Levels::MEMBER, @user.level) + end + end + end + end + + context "#new" do + context "for safe mode" do + setup do + CurrentUser.stubs(:safe_mode?).returns(true) + end + + should "render" do + get :new, {}, {:user_id => @user.id} + assert_response :success + end + end + + context "for default mode" do + should "render" do + get :new, {}, {:user_id => @user.id} + assert_response :success + end + end + end + + context "#show" do + context "with disable=true" do + should "render" do + get :show, {}, {:user_id => @user.id}, {:disable => true} + assert_response :success + end + end + + context "with success=true" do + should "render" do + get :show, {}, {:user_id => @user.id}, {:success => true} + assert_response :success + end + end + + context "with error=true" do + should "render" do + get :show, {}, {:user_id => @user.id}, {:error => true} + assert_response :success + end + end + end +end diff --git a/test/fixtures/vcr_cassettes/stripe-basic-to-gold.yml b/test/fixtures/vcr_cassettes/stripe-basic-to-gold.yml new file mode 100644 index 000000000..1fa1c7d7f --- /dev/null +++ b/test/fixtures/vcr_cassettes/stripe-basic-to-gold.yml @@ -0,0 +1,169 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/tokens + body: + encoding: US-ASCII + string: card[number]=4242424242424242&card[exp_month]=1&card[exp_year]=2015&card[cvc]=123 + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '81' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:31 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '623' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - ea64b1f2-9b94-4b6f-bb1c-c6e3784007b3 + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"tok_14w1lj2Od3yiQVdJdZtBSbXI\",\n \"livemode\": false,\n + \ \"created\": 1415324551,\n \"used\": false,\n \"object\": \"token\",\n + \ \"type\": \"card\",\n \"card\": {\n \"id\": \"card_14w1lj2Od3yiQVdJ1fiG5eGJ\",\n + \ \"object\": \"card\",\n \"last4\": \"4242\",\n \"brand\": \"Visa\",\n + \ \"funding\": \"credit\",\n \"exp_month\": 1,\n \"exp_year\": 2015,\n + \ \"fingerprint\": \"xrSmurPsZCJllxXR\",\n \"country\": \"US\",\n \"name\": + null,\n \"address_line1\": null,\n \"address_line2\": null,\n \"address_city\": + null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_country\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n }\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:31 GMT +- request: + method: post + uri: https://api.stripe.com/v1/charges + body: + encoding: US-ASCII + string: amount=2000¤cy=usd&card=tok_14w1lj2Od3yiQVdJdZtBSbXI&description=Upgrade%20to%20Gold + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '90' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:32 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '1362' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - dad96b4a-bcc7-4537-9ddb-dd3b6093a0d2 + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"ch_14w1lk2Od3yiQVdJuaBrKoSb\",\n \"object\": \"charge\",\n + \ \"created\": 1415324552,\n \"livemode\": false,\n \"paid\": true,\n \"amount\": + 2000,\n \"currency\": \"usd\",\n \"refunded\": false,\n \"card\": {\n \"id\": + \"card_14w1lj2Od3yiQVdJ1fiG5eGJ\",\n \"object\": \"card\",\n \"last4\": + \"4242\",\n \"brand\": \"Visa\",\n \"funding\": \"credit\",\n \"exp_month\": + 1,\n \"exp_year\": 2015,\n \"fingerprint\": \"xrSmurPsZCJllxXR\",\n + \ \"country\": \"US\",\n \"name\": null,\n \"address_line1\": null,\n + \ \"address_line2\": null,\n \"address_city\": null,\n \"address_state\": + null,\n \"address_zip\": null,\n \"address_country\": null,\n \"cvc_check\": + \"pass\",\n \"address_line1_check\": null,\n \"address_zip_check\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n },\n \"captured\": + true,\n \"refunds\": {\n \"object\": \"list\",\n \"total_count\": 0,\n + \ \"has_more\": false,\n \"url\": \"/v1/charges/ch_14w1lk2Od3yiQVdJuaBrKoSb/refunds\",\n + \ \"data\": []\n },\n \"balance_transaction\": \"txn_14w1lk2Od3yiQVdJ4tGMRyec\",\n + \ \"failure_message\": null,\n \"failure_code\": null,\n \"amount_refunded\": + 0,\n \"customer\": null,\n \"invoice\": null,\n \"description\": \"Upgrade + to Gold\",\n \"dispute\": null,\n \"metadata\": {},\n \"statement_description\": + null,\n \"fraud_details\": {\n \"stripe_report\": null,\n \"user_report\": + null\n },\n \"receipt_email\": null,\n \"receipt_number\": null,\n \"shipping\": + null\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:32 GMT +- request: + method: post + uri: https://collector.newrelic.com/agent_listener/14//get_redirect_host?marshal_format=json + body: + encoding: UTF-8 + string: ! '[]' + headers: + Content-Encoding: + - identity + Host: + - collector.newrelic.com + Accept: + - ! '*/*' + User-Agent: + - NewRelic-RubyAgent/3.9.6.257 (ruby 1.9.3 x86_64-darwin13.1.0) zlib/1.2.5 + Content-Type: + - application/octet-stream + response: + status: + code: 200 + message: OK + headers: + Content-Length: + - '133' + body: + encoding: US-ASCII + string: ! '{"exception":{"message":"Invalid license key, please contact support@newrelic.com","error_type":"NewRelic::Agent::LicenseException"}}' + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:32 GMT +recorded_with: VCR 2.9.0 diff --git a/test/fixtures/vcr_cassettes/stripe-basic-to-plat.yml b/test/fixtures/vcr_cassettes/stripe-basic-to-plat.yml new file mode 100644 index 000000000..0f3787329 --- /dev/null +++ b/test/fixtures/vcr_cassettes/stripe-basic-to-plat.yml @@ -0,0 +1,140 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/tokens + body: + encoding: US-ASCII + string: card[number]=4242424242424242&card[exp_month]=1&card[exp_year]=2015&card[cvc]=123 + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '81' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:32 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '623' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - 1110fe22-457d-495f-9a80-1d5d595cc99c + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"tok_14w1lk2Od3yiQVdJJ3XzlTSH\",\n \"livemode\": false,\n + \ \"created\": 1415324552,\n \"used\": false,\n \"object\": \"token\",\n + \ \"type\": \"card\",\n \"card\": {\n \"id\": \"card_14w1lk2Od3yiQVdJ8ddU76Aq\",\n + \ \"object\": \"card\",\n \"last4\": \"4242\",\n \"brand\": \"Visa\",\n + \ \"funding\": \"credit\",\n \"exp_month\": 1,\n \"exp_year\": 2015,\n + \ \"fingerprint\": \"xrSmurPsZCJllxXR\",\n \"country\": \"US\",\n \"name\": + null,\n \"address_line1\": null,\n \"address_line2\": null,\n \"address_city\": + null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_country\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n }\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:32 GMT +- request: + method: post + uri: https://api.stripe.com/v1/charges + body: + encoding: US-ASCII + string: amount=4000¤cy=usd&card=tok_14w1lk2Od3yiQVdJJ3XzlTSH&description=Upgrade%20to%20Platinum + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '94' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:32 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '1366' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - fcf2b1e8-ce3c-4f1d-8742-a422cc0a1d3a + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"ch_14w1lk2Od3yiQVdJAQwoEXgF\",\n \"object\": \"charge\",\n + \ \"created\": 1415324552,\n \"livemode\": false,\n \"paid\": true,\n \"amount\": + 4000,\n \"currency\": \"usd\",\n \"refunded\": false,\n \"card\": {\n \"id\": + \"card_14w1lk2Od3yiQVdJ8ddU76Aq\",\n \"object\": \"card\",\n \"last4\": + \"4242\",\n \"brand\": \"Visa\",\n \"funding\": \"credit\",\n \"exp_month\": + 1,\n \"exp_year\": 2015,\n \"fingerprint\": \"xrSmurPsZCJllxXR\",\n + \ \"country\": \"US\",\n \"name\": null,\n \"address_line1\": null,\n + \ \"address_line2\": null,\n \"address_city\": null,\n \"address_state\": + null,\n \"address_zip\": null,\n \"address_country\": null,\n \"cvc_check\": + \"pass\",\n \"address_line1_check\": null,\n \"address_zip_check\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n },\n \"captured\": + true,\n \"refunds\": {\n \"object\": \"list\",\n \"total_count\": 0,\n + \ \"has_more\": false,\n \"url\": \"/v1/charges/ch_14w1lk2Od3yiQVdJAQwoEXgF/refunds\",\n + \ \"data\": []\n },\n \"balance_transaction\": \"txn_14w1lk2Od3yiQVdJjDRDaKkC\",\n + \ \"failure_message\": null,\n \"failure_code\": null,\n \"amount_refunded\": + 0,\n \"customer\": null,\n \"invoice\": null,\n \"description\": \"Upgrade + to Platinum\",\n \"dispute\": null,\n \"metadata\": {},\n \"statement_description\": + null,\n \"fraud_details\": {\n \"stripe_report\": null,\n \"user_report\": + null\n },\n \"receipt_email\": null,\n \"receipt_number\": null,\n \"shipping\": + null\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:32 GMT +recorded_with: VCR 2.9.0 diff --git a/test/fixtures/vcr_cassettes/stripe-gold-to-plat-bad.yml b/test/fixtures/vcr_cassettes/stripe-gold-to-plat-bad.yml new file mode 100644 index 000000000..b7a12f94b --- /dev/null +++ b/test/fixtures/vcr_cassettes/stripe-gold-to-plat-bad.yml @@ -0,0 +1,66 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/tokens + body: + encoding: US-ASCII + string: card[number]=4242424242424242&card[exp_month]=1&card[exp_year]=2015&card[cvc]=123 + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '81' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:34 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '623' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - 131d3a38-43aa-4ae1-9740-e745bbec695d + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"tok_14w1lm2Od3yiQVdJsgew67au\",\n \"livemode\": false,\n + \ \"created\": 1415324554,\n \"used\": false,\n \"object\": \"token\",\n + \ \"type\": \"card\",\n \"card\": {\n \"id\": \"card_14w1ll2Od3yiQVdJbLrKD9YV\",\n + \ \"object\": \"card\",\n \"last4\": \"4242\",\n \"brand\": \"Visa\",\n + \ \"funding\": \"credit\",\n \"exp_month\": 1,\n \"exp_year\": 2015,\n + \ \"fingerprint\": \"xrSmurPsZCJllxXR\",\n \"country\": \"US\",\n \"name\": + null,\n \"address_line1\": null,\n \"address_line2\": null,\n \"address_city\": + null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_country\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n }\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:33 GMT +recorded_with: VCR 2.9.0 diff --git a/test/fixtures/vcr_cassettes/stripe-gold-to-plat.yml b/test/fixtures/vcr_cassettes/stripe-gold-to-plat.yml new file mode 100644 index 000000000..6f0bf6a82 --- /dev/null +++ b/test/fixtures/vcr_cassettes/stripe-gold-to-plat.yml @@ -0,0 +1,140 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/tokens + body: + encoding: US-ASCII + string: card[number]=4242424242424242&card[exp_month]=1&card[exp_year]=2015&card[cvc]=123 + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '81' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:33 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '623' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - 26c76792-4ff5-4154-b226-a309d79bdb0e + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"tok_14w1ll2Od3yiQVdJ6kLDgI43\",\n \"livemode\": false,\n + \ \"created\": 1415324553,\n \"used\": false,\n \"object\": \"token\",\n + \ \"type\": \"card\",\n \"card\": {\n \"id\": \"card_14w1ll2Od3yiQVdJy4qdhKMh\",\n + \ \"object\": \"card\",\n \"last4\": \"4242\",\n \"brand\": \"Visa\",\n + \ \"funding\": \"credit\",\n \"exp_month\": 1,\n \"exp_year\": 2015,\n + \ \"fingerprint\": \"xrSmurPsZCJllxXR\",\n \"country\": \"US\",\n \"name\": + null,\n \"address_line1\": null,\n \"address_line2\": null,\n \"address_city\": + null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_country\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n }\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:33 GMT +- request: + method: post + uri: https://api.stripe.com/v1/charges + body: + encoding: US-ASCII + string: amount=2000¤cy=usd&card=tok_14w1ll2Od3yiQVdJ6kLDgI43&description=Upgrade%20Gold%20to%20Platinum + headers: + Accept: + - ! '*/*; q=0.5, application/xml' + Accept-Encoding: + - gzip, deflate + User-Agent: + - Stripe/v1 RubyBindings/1.16.0 + Authorization: + - Bearer sk_test_kHviyCxbt9kBxeu46TeefJQH + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-User-Agent: + - ! '{"bindings_version":"1.16.0","lang":"ruby","lang_version":"1.9.3 p327 (2012-11-10)","platform":"x86_64-darwin13.1.0","publisher":"stripe","uname":"Darwin + ayi-ltm1.internal.salesforce.com 13.4.0 Darwin Kernel Version 13.4.0: Sun + Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"}' + Content-Length: + - '101' + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Fri, 07 Nov 2014 01:42:33 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '1371' + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - a3e5cda9-d4c4-47f6-8c4f-9f3638399300 + Stripe-Version: + - '2014-10-07' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains + body: + encoding: US-ASCII + string: ! "{\n \"id\": \"ch_14w1ll2Od3yiQVdJcu6dUs9x\",\n \"object\": \"charge\",\n + \ \"created\": 1415324553,\n \"livemode\": false,\n \"paid\": true,\n \"amount\": + 2000,\n \"currency\": \"usd\",\n \"refunded\": false,\n \"card\": {\n \"id\": + \"card_14w1ll2Od3yiQVdJy4qdhKMh\",\n \"object\": \"card\",\n \"last4\": + \"4242\",\n \"brand\": \"Visa\",\n \"funding\": \"credit\",\n \"exp_month\": + 1,\n \"exp_year\": 2015,\n \"fingerprint\": \"xrSmurPsZCJllxXR\",\n + \ \"country\": \"US\",\n \"name\": null,\n \"address_line1\": null,\n + \ \"address_line2\": null,\n \"address_city\": null,\n \"address_state\": + null,\n \"address_zip\": null,\n \"address_country\": null,\n \"cvc_check\": + \"pass\",\n \"address_line1_check\": null,\n \"address_zip_check\": + null,\n \"dynamic_last4\": null,\n \"customer\": null\n },\n \"captured\": + true,\n \"refunds\": {\n \"object\": \"list\",\n \"total_count\": 0,\n + \ \"has_more\": false,\n \"url\": \"/v1/charges/ch_14w1ll2Od3yiQVdJcu6dUs9x/refunds\",\n + \ \"data\": []\n },\n \"balance_transaction\": \"txn_14w1ll2Od3yiQVdJ34rCa0xY\",\n + \ \"failure_message\": null,\n \"failure_code\": null,\n \"amount_refunded\": + 0,\n \"customer\": null,\n \"invoice\": null,\n \"description\": \"Upgrade + Gold to Platinum\",\n \"dispute\": null,\n \"metadata\": {},\n \"statement_description\": + null,\n \"fraud_details\": {\n \"stripe_report\": null,\n \"user_report\": + null\n },\n \"receipt_email\": null,\n \"receipt_number\": null,\n \"shipping\": + null\n}\n" + http_version: + recorded_at: Fri, 07 Nov 2014 01:42:33 GMT +recorded_with: VCR 2.9.0