From f8532d225e20cb6ded2bd9a672a6d8a0479b80ba Mon Sep 17 00:00:00 2001 From: Ioannis Kolovos Date: Sat, 6 Feb 2016 16:55:29 +0200 Subject: [PATCH] Support for Stripe::CountrySpec --- lib/stripe.rb | 1 + lib/stripe/country_spec.rb | 10 +++++ lib/stripe/util.rb | 1 + test/stripe/country_spec_test.rb | 43 +++++++++++++++++++++ test/test_data.rb | 64 +++++++++++++++++++++++++++++++- 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 lib/stripe/country_spec.rb create mode 100644 test/stripe/country_spec_test.rb diff --git a/lib/stripe.rb b/lib/stripe.rb index 4ff6d97e..1b4e273a 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -32,6 +32,7 @@ require 'stripe/customer' require 'stripe/invoice' require 'stripe/invoice_item' require 'stripe/charge' +require 'stripe/country_spec' require 'stripe/plan' require 'stripe/file_upload' require 'stripe/coupon' diff --git a/lib/stripe/country_spec.rb b/lib/stripe/country_spec.rb new file mode 100644 index 00000000..ca5e33cb --- /dev/null +++ b/lib/stripe/country_spec.rb @@ -0,0 +1,10 @@ +module Stripe + class CountrySpec < APIResource + extend Stripe::APIOperations::List + + def self.url + '/v1/country_specs' + end + + end +end diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index f2e04d5d..336a63d4 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -30,6 +30,7 @@ module Stripe 'bank_account' => BankAccount, 'card' => Card, 'charge' => Charge, + 'country_spec' => CountrySpec, 'coupon' => Coupon, 'customer' => Customer, 'event' => Event, diff --git a/test/stripe/country_spec_test.rb b/test/stripe/country_spec_test.rb new file mode 100644 index 00000000..3c3e66ac --- /dev/null +++ b/test/stripe/country_spec_test.rb @@ -0,0 +1,43 @@ +require File.expand_path('../../test_helper', __FILE__) + +module Stripe + class CountrySpecTest < Test::Unit::TestCase + should "be listable" do + @mock.expects(:get).once. + returns(make_response(country_spec_array)) + c = Stripe::CountrySpec.list + + assert_equal('/v1/country_specs', c.url) + assert_equal('list', c.object) + assert(c.data.kind_of?(Array)) + assert_equal('US', c.data[0].id) + assert(c.data[0].kind_of?(Stripe::CountrySpec)) + end + + should "be retrievable" do + resp = make_country_spec + @mock.expects(:get).once. + with('https://api.stripe.com/v1/country_specs/US', nil, nil). + returns(make_response(resp)) + s = Stripe::CountrySpec.retrieve('US') + + assert_equal('/v1/country_specs/US', s.url) + assert_equal('country_spec', s.object) + assert(s.kind_of?(Stripe::CountrySpec)) + + s.supported_bank_account_currencies.map{ |k,v| assert v.kind_of?(Array) } + assert_equal(['US'], s.supported_bank_account_currencies['usd']) + assert(s.supported_payment_currencies.include?('usd')) + assert s.supported_payment_currencies.kind_of?(Array) + assert s.supported_payment_methods.kind_of?(Array) + + ['individual', 'company'].map{ |type| + item = s.verification_fields[type] + assert item.minimum.include?('external_account') + assert item.additional.include?('legal_entity.verification.document') + assert item.additional.kind_of?(Array) + assert item.minimum.kind_of?(Array) + } + end + end +end \ No newline at end of file diff --git a/test/test_data.rb b/test/test_data.rb index 1b1a27cb..8f3e5097 100644 --- a/test/test_data.rb +++ b/test/test_data.rb @@ -164,7 +164,6 @@ module Stripe } end - def make_dispute(params={}) id = params[:id] || 'dp_test_dispute' { @@ -672,5 +671,68 @@ module Stripe :charge => make_charge, }).merge(params) end + + def country_spec_array + { + :object => "list", + :url => "/v1/country_specs", + :data => [ + make_country_spec, + make_country_spec, + make_country_spec, + ] + } + end + + def make_country_spec(params={}) + { + :id=> "US", + :object=> "country_spec", + :supported_bank_account_currencies=> { + :usd => ["US"] + }, + :supported_payment_currencies=> + [ + "usd", "aed", "afn", "all" + ], + :supported_payment_methods=> + [ + "alipay", "card", "stripe" + ], + :verification_fields=> + { + :individual=> + { + :minimum=> + [ + "external_account", + "legal_entity.address.city", + "tos_acceptance.date", + "tos_acceptance.ip" + ], + :additional=> + [ + "legal_entity.personal_id_number", + "legal_entity.verification.document" + ] + }, + :company=> + { + :minimum=> + [ + "external_account", + "legal_entity.address.city", + "legal_entity.address.line1", + "tos_acceptance.ip" + ], + :additional=> + [ + "legal_entity.personal_id_number", + "legal_entity.verification.document" + ] + } + } + }.merge(params) + end end end