make ApplicationFee.refunds a list object instead of array

This commit is contained in:
Cosmin Nicolaescu 2014-07-28 19:40:01 -07:00
parent 9cf5089dc1
commit d3dfa18990
8 changed files with 94 additions and 3 deletions

View File

@ -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:

View File

@ -1 +1 @@
1.14.0
1.15.0

View File

@ -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'

View File

@ -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

View File

@ -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)}"

View File

@ -32,7 +32,8 @@ module Stripe
'subscription' => Subscription,
'list' => ListObject,
'refund' => Refund,
'application_fee' => ApplicationFee
'application_fee' => ApplicationFee,
'fee_refund' => ApplicationFeeRefund
}
end

View File

@ -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

View File

@ -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'
{