diff --git a/History.txt b/History.txt index 54a758fa..eab27823 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +=== 1.15.0 2014-07-26 + +* 1 major enhacement: + * Application Fee refunds now a list instead of array + === 1.14.0 2014-06-17 * 1 major enhancement: diff --git a/VERSION b/VERSION index 850e7424..141f2e80 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.14.0 +1.15.0 diff --git a/lib/stripe.rb b/lib/stripe.rb index 2fc23ce8..21e9263f 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -39,6 +39,7 @@ require 'stripe/card' require 'stripe/subscription' require 'stripe/application_fee' require 'stripe/refund' +require 'stripe/application_fee_refund' # Errors require 'stripe/errors/stripe_error' diff --git a/lib/stripe/application_fee_refund.rb b/lib/stripe/application_fee_refund.rb new file mode 100644 index 00000000..b2836674 --- /dev/null +++ b/lib/stripe/application_fee_refund.rb @@ -0,0 +1,14 @@ +module Stripe + class ApplicationFeeRefund < APIResource + include Stripe::APIOperations::Update + include Stripe::APIOperations::List + + def url + "#{ApplicationFee.url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}" + end + + def self.retrieve(id, api_key=nil) + raise NotImplementedError.new("Refunds cannot be retrieved without an application fee ID. Retrieve a refund using appfee.refunds.retrieve('refund_id')") + end + end +end diff --git a/lib/stripe/refund.rb b/lib/stripe/refund.rb index 68fd7ac7..86385b31 100644 --- a/lib/stripe/refund.rb +++ b/lib/stripe/refund.rb @@ -1,6 +1,7 @@ module Stripe class Refund < APIResource include Stripe::APIOperations::Update + include Stripe::APIOperations::List def url "#{Charge.url}/#{CGI.escape(charge)}/refunds/#{CGI.escape(id)}" diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index e9416df0..42b0ce21 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -32,7 +32,8 @@ module Stripe 'subscription' => Subscription, 'list' => ListObject, 'refund' => Refund, - 'application_fee' => ApplicationFee + 'application_fee' => ApplicationFee, + 'fee_refund' => ApplicationFeeRefund } end diff --git a/test/stripe/application_fee_refund_test.rb b/test/stripe/application_fee_refund_test.rb new file mode 100644 index 00000000..c8fca9cd --- /dev/null +++ b/test/stripe/application_fee_refund_test.rb @@ -0,0 +1,47 @@ +require File.expand_path('../../test_helper', __FILE__) + +module Stripe + class ApplicationFeeRefundTest < Test::Unit::TestCase + should "refunds should be listable" do + @mock.expects(:get).once.returns(test_response(test_application_fee)) + + application_fee = Stripe::ApplicationFee.retrieve('test_application_fee') + + assert application_fee.refunds.first.kind_of?(Stripe::ApplicationFeeRefund) + end + + should "refunds should be refreshable" do + @mock.expects(:get).twice.returns(test_response(test_application_fee), test_response(test_application_fee_refund(:id => 'refreshed_refund'))) + + application_fee = Stripe::ApplicationFee.retrieve('test_application_fee') + refund = application_fee.refunds.first + refund.refresh + + assert_equal 'refreshed_refund', refund.id + end + + should "refunds should be updateable" do + @mock.expects(:get).once.returns(test_response(test_application_fee)) + @mock.expects(:post).once.returns(test_response(test_application_fee_refund(:metadata => {'key' => 'value'}))) + + application_fee = Stripe::ApplicationFee.retrieve('test_application_fee') + refund = application_fee.refunds.first + + assert_equal nil, refund.metadata['key'] + + refund.metadata['key'] = 'valu' + refund.save + + assert_equal 'value', refund.metadata['key'] + end + + should "create should return a new refund" do + @mock.expects(:get).once.returns(test_response(test_application_fee)) + @mock.expects(:post).once.returns(test_response(test_application_fee_refund(:id => 'test_new_refund'))) + + application_fee = Stripe::ApplicationFee.retrieve('test_application_fee') + refund = application_fee.refunds.create(:amount => 20) + assert_equal 'test_new_refund', refund.id + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1917caa3..e80106ee 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -71,20 +71,34 @@ def test_balance_transaction_array end def test_application_fee(params={}) + id = params[:id] || 'fee_test_fee' { :refunded => false, :amount => 100, :application => "ca_test_application", :user => "acct_test_user", :charge => "ch_test_charge", - :id => "fee_test_fee", + :id => id, :livemode => false, :currency => "usd", :object => "application_fee", + :refunds => test_application_fee_refund_array(id), :created => 1304114826 }.merge(params) end +def test_application_fee_refund(params = {}) + { + :object => 'fee_refund', + :amount => 30, + :currency => "usd", + :created => 1308595038, + :id => "ref_test_app_fee_refund", + :fee => "ca_test_application", + :metadata => {} + }.merge(params) +end + def test_application_fee_array { :data => [test_application_fee, test_application_fee, test_application_fee], @@ -93,6 +107,14 @@ def test_application_fee_array } end +def test_application_fee_refund_array(fee_id) + { + :data => [test_application_fee_refund, test_application_fee_refund, test_application_fee_refund], + :object => 'list', + :url => '/v1/application_fees/' + fee_id + '/refunds' + } +end + def test_customer(params={}) id = params[:id] || 'c_test_customer' {