From 8f93cd5fac98cbdf054507549d4eca12eb887d6c Mon Sep 17 00:00:00 2001 From: Andrew Narkewicz Date: Fri, 26 Dec 2014 09:10:23 -0700 Subject: [PATCH] Added deauthorize method to account for deauthorizing from stripe connect application --- lib/stripe.rb | 3 ++- lib/stripe/account.rb | 5 +++++ test/stripe/account_test.rb | 14 +++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/stripe.rb b/lib/stripe.rb index 3a11dcca..bb18a277 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -53,6 +53,7 @@ require 'stripe/errors/authentication_error' module Stripe DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt' @api_base = 'https://api.stripe.com' + @connect_base = 'https://connect.stripe.com' @ssl_bundle_path = DEFAULT_CA_BUNDLE_PATH @verify_ssl_certs = true @@ -60,7 +61,7 @@ module Stripe class << self - attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version + attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base end def self.api_url(url='', api_base_url=nil) diff --git a/lib/stripe/account.rb b/lib/stripe/account.rb index 16b0196e..e06f8776 100644 --- a/lib/stripe/account.rb +++ b/lib/stripe/account.rb @@ -1,4 +1,9 @@ module Stripe class Account < SingletonAPIResource + def deauthorize(client_id, opts={}) + api_key, headers = Util.parse_opts(opts) + response, api_key = Stripe.request(:post, '/oauth/deauthorize', api_key, { 'client_id' => client_id, 'stripe_user_id' => self.id }, headers, Stripe.connect_base) + Util.convert_to_stripe_object(response, api_key) + end end end diff --git a/test/stripe/account_test.rb b/test/stripe/account_test.rb index 5c096ef2..a97bca0a 100644 --- a/test/stripe/account_test.rb +++ b/test/stripe/account_test.rb @@ -10,5 +10,17 @@ module Stripe assert !a.charge_enabled assert !a.details_submitted end + + should "be able to deauthorize an account" do + resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false} + @mock.expects(:get).once.returns(test_response(resp)) + a = Stripe::Account.retrieve + + + @mock.expects(:post).once.with do |url, api_key, params| + url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]} + end.returns(test_response({ 'stripe_user_id' => a.id })) + a.deauthorize('ca_1234', 'sk_test_1234') + end end -end \ No newline at end of file +end