paypal-sdk-rest 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +44 -0
  4. data/lib/generators/paypal/sdk/USAGE +3 -0
  5. data/lib/generators/paypal/sdk/install_generator.rb +17 -0
  6. data/lib/generators/paypal/sdk/templates/paypal.rb +2 -0
  7. data/lib/generators/paypal/sdk/templates/paypal.yml +31 -0
  8. data/lib/paypal-sdk-core.rb +38 -0
  9. data/lib/paypal-sdk/core/api.rb +20 -0
  10. data/lib/paypal-sdk/core/api/base.rb +162 -0
  11. data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +44 -0
  12. data/lib/paypal-sdk/core/api/data_types/base.rb +224 -0
  13. data/lib/paypal-sdk/core/api/data_types/enum.rb +26 -0
  14. data/lib/paypal-sdk/core/api/data_types/simple_types.rb +52 -0
  15. data/lib/paypal-sdk/core/api/ipn.rb +66 -0
  16. data/lib/paypal-sdk/core/api/rest.rb +163 -0
  17. data/lib/paypal-sdk/core/authentication.rb +66 -0
  18. data/lib/paypal-sdk/core/config.rb +249 -0
  19. data/lib/paypal-sdk/core/credential.rb +16 -0
  20. data/lib/paypal-sdk/core/credential/base.rb +27 -0
  21. data/lib/paypal-sdk/core/credential/certificate.rb +32 -0
  22. data/lib/paypal-sdk/core/credential/signature.rb +22 -0
  23. data/lib/paypal-sdk/core/credential/third_party/subject.rb +25 -0
  24. data/lib/paypal-sdk/core/credential/third_party/token.rb +39 -0
  25. data/lib/paypal-sdk/core/exceptions.rb +96 -0
  26. data/lib/paypal-sdk/core/logging.rb +45 -0
  27. data/lib/paypal-sdk/core/openid_connect.rb +122 -0
  28. data/lib/paypal-sdk/core/openid_connect/api.rb +49 -0
  29. data/lib/paypal-sdk/core/openid_connect/data_types.rb +73 -0
  30. data/lib/paypal-sdk/core/openid_connect/get_api.rb +28 -0
  31. data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +52 -0
  32. data/lib/paypal-sdk/core/openid_connect/set_api.rb +36 -0
  33. data/lib/paypal-sdk/core/util.rb +11 -0
  34. data/lib/paypal-sdk/core/util/http_helper.rb +159 -0
  35. data/lib/paypal-sdk/core/util/oauth_signature.rb +64 -0
  36. data/lib/paypal-sdk/core/util/ordered_hash.rb +165 -0
  37. data/lib/paypal-sdk/rest/data_types.rb +1 -0
  38. data/lib/paypal-sdk/rest/version.rb +1 -1
  39. data/spec/config/paypal.yml +27 -0
  40. data/spec/config/sample_data.yml +3 -0
  41. data/spec/core/api/data_type_spec.rb +189 -0
  42. data/spec/core/api/rest_spec.rb +147 -0
  43. data/spec/core/config_spec.rb +192 -0
  44. data/spec/core/logging_spec.rb +28 -0
  45. data/spec/core/openid_connect_spec.rb +144 -0
  46. data/spec/log/http.log +71 -32
  47. data/spec/log/rest_http.log +133 -0
  48. data/spec/spec_helper.rb +7 -0
  49. data/spec/support/sample_data.rb +5 -0
  50. metadata +82 -5
@@ -464,6 +464,7 @@ module PayPal::SDK
464
464
  object_of :subtotal, String
465
465
  object_of :shipping, String
466
466
  object_of :tax, String
467
+ object_of :fee, String
467
468
  object_of :handling_fee, String
468
469
  object_of :shipping_discount, String
469
470
  object_of :insurance, String
@@ -1,7 +1,7 @@
1
1
  module PayPal
2
2
  module SDK
3
3
  module REST
4
- VERSION = "0.10.0"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,8 +1,35 @@
1
1
  test: &default
2
2
  client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
3
3
  client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
4
+ username: jb-us-seller_api1.paypal.com
5
+ password: WX4WTU3S8MY44S7F
6
+ signature: AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy
7
+ app_id: APP-80W284485P519543T
8
+ http_timeout: 30
4
9
  mode: sandbox
10
+ sandbox_email_address: Platform.sdk.seller@gmail.com
5
11
 
6
12
  development:
7
13
  <<: *default
8
14
 
15
+ with_authentication:
16
+ <<: *default
17
+ client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
18
+ client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
19
+
20
+ with_certificate:
21
+ <<: *default
22
+ username: platfo_1255170694_biz_api1.gmail.com
23
+ password: 2DPPKUPKB7DQLXNR
24
+ signature:
25
+ cert_path: <%= File.expand_path("../cert_key.pem", __FILE__) %>
26
+ app_id: APP-80W284485P519543T
27
+
28
+ with_oauth_token:
29
+ <<: *default
30
+ token: 3rMSi3kCmK1Q3.BKxkH29I53R0TRLrSuCO..l8AMOAFM6cQhPTTrfQ
31
+ token_secret: RuE1j8RNRlSuL5T-PSSpVWLvOlI
32
+
33
+ with_proxy:
34
+ <<: *default
35
+ http_proxy: <%= ENV['http_proxy'] %>
@@ -0,0 +1,3 @@
1
+ ipn:
2
+ valid_message: item_number=&residence_country=US&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXi5tzp0u2U-8QDyy.oC2A1Dhx04&address_country=United+States&address_city=San+Jose&address_status=unconfirmed&business=platfo_1255077030_biz%40gmail.com&payment_status=Pending&transaction_subject=&protection_eligibility=Ineligible&shipping=0.00&payer_id=934EKX9W68RRU&first_name=John&mc_fee=0.38&txn_id=5AL16697HX185734U&quantity=1&receiver_email=platfo_1255077030_biz%40gmail.com&notify_version=3.7&txn_type=web_accept&mc_gross=1.00&payer_status=unverified&mc_currency=USD&test_ipn=1&custom=&payment_date=01%3A48%3A31+Dec+04%2C+2012+PST&payment_fee=0.38&charset=windows-1252&address_country_code=US&payment_gross=1.00&address_zip=95131&ipn_track_id=af0f53159f21e&address_state=CA&receipt_id=4050-1771-4106-3070&pending_reason=paymentreview&tax=0.00&handling_amount=0.00&item_name=&address_name=John+Doe&last_name=Doe&payment_type=instant&receiver_id=HZH2W8NPXUE5W&address_street=1+Main+St
3
+ invalid_message: invalid=invalid
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayPal::SDK::Core::API::DataTypes::Base do
4
+
5
+ DataType = PayPal::SDK::Core::API::DataTypes::Base
6
+
7
+ class TestCurrency < DataType
8
+
9
+ # Members
10
+ object_of :amount, String
11
+ object_of :desciption, String, :namespace => "ns"
12
+ # Attributes
13
+ add_attribute :currencyID, :namespace => "cc"
14
+ end
15
+
16
+ class TestType < DataType
17
+ object_of :fromCurrency, TestCurrency
18
+ array_of :toCurrency, TestCurrency
19
+ object_of :firstname, String, :name => "first-name"
20
+ end
21
+
22
+ class TestSimpleType < DataType
23
+ include PayPal::SDK::Core::API::DataTypes::SimpleTypes
24
+ object_of :created_on, Date
25
+ object_of :created_at, DateTime
26
+ end
27
+
28
+ class Message < DataType
29
+ object_of :value, String
30
+ end
31
+
32
+ it "should allow content key" do
33
+ message = Message.new("Testing message")
34
+ message.value.should eql "Testing message"
35
+
36
+ message = Message.new(:value => "Testing message")
37
+ message.value.should eql "Testing message"
38
+ end
39
+
40
+ it "should create member object automatically" do
41
+ test_type = TestType.new
42
+ test_type.fromCurrency.should be_a TestCurrency
43
+ test_type.toCurrency.should be_a Array
44
+ test_type.toCurrency[0].should be_a TestCurrency
45
+ test_type.toCurrency[1].should be_a TestCurrency
46
+ test_type.toCurrency[0].amount.should eql nil
47
+ test_type.fromCurrency.amount.should eql nil
48
+ test_type.fromCurrency.desciption.should eql nil
49
+ test_type.fromCurrency.currencyID.should eql nil
50
+ end
51
+
52
+ it "should convert the given data to configured type" do
53
+ test_type = TestType.new( :fromCurrency => { :currencyID => "USD", :amount => "50.0"})
54
+ test_type.fromCurrency.should be_a TestCurrency
55
+ test_type.fromCurrency.currencyID.should eql "USD"
56
+ test_type.fromCurrency.amount.should eql "50.0"
57
+ end
58
+
59
+ it "should allow block with initializer" do
60
+ test_type = TestType.new do
61
+ fromCurrency do
62
+ self.currencyID = "USD"
63
+ self.amount = "50.0"
64
+ end
65
+ end
66
+ test_type.fromCurrency.currencyID.should eql "USD"
67
+ test_type.fromCurrency.amount.should eql "50.0"
68
+ end
69
+
70
+ it "should allow block with member" do
71
+ test_type = TestType.new
72
+ test_type.fromCurrency do
73
+ self.currencyID = "USD"
74
+ self.amount = "50.0"
75
+ end
76
+ test_type.fromCurrency.currencyID.should eql "USD"
77
+ test_type.fromCurrency.amount.should eql "50.0"
78
+ end
79
+
80
+ it "should assign value to attribute" do
81
+ test_currency = TestCurrency.new( :@currencyID => "USD", :amount => "50" )
82
+ test_currency.currencyID.should eql "USD"
83
+ end
84
+
85
+ it "should allow configured Class object" do
86
+ test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
87
+ test_type = TestType.new( :fromCurrency => test_currency )
88
+ test_type.fromCurrency.should eql test_currency
89
+ end
90
+
91
+ it "should allow snakecase" do
92
+ test_type = TestType.new( :from_currency => {} )
93
+ test_type.from_currency.should be_a TestCurrency
94
+ test_type.from_currency.should eql test_type.fromCurrency
95
+ end
96
+
97
+ it "should allow array" do
98
+ test_type = TestType.new( :toCurrency => [{ :currencyID => "USD", :amount => "50.0" }] )
99
+ test_type.toCurrency.should be_a Array
100
+ test_type.toCurrency.first.should be_a TestCurrency
101
+ test_type.toCurrency.first.currencyID.should eql "USD"
102
+ end
103
+
104
+ it "should skip undefind members on initializer" do
105
+ test_type = TestType.new( :notExist => "testing")
106
+ lambda do
107
+ test_type.notExist
108
+ end.should raise_error NoMethodError
109
+ lambda do
110
+ test_type.notExist = "Value"
111
+ end.should raise_error NoMethodError
112
+ end
113
+
114
+ it "should not convert empty hash" do
115
+ test_type = TestType.new( :fromCurrency => {} )
116
+ test_type.to_hash.should eql({})
117
+ end
118
+
119
+ it "should not convert empty array" do
120
+ test_type = TestType.new( :toCurrency => [] )
121
+ test_type.to_hash.should eql({})
122
+ end
123
+
124
+ it "should not convert array of empty hash" do
125
+ test_type = TestType.new( :toCurrency => [ {} ] )
126
+ test_type.to_hash.should eql({})
127
+ end
128
+
129
+ it "should return empty hash" do
130
+ test_type = TestType.new
131
+ test_type.to_hash.should eql({})
132
+ end
133
+
134
+ it "should convert to hash" do
135
+ test_currency = TestCurrency.new(:amount => "500")
136
+ test_currency.to_hash.should eql("amount" => "500")
137
+ end
138
+
139
+ it "should convert to hash with key as symbol" do
140
+ test_currency = TestCurrency.new(:amount => "500")
141
+ test_currency.to_hash(:symbol => true).should eql(:amount => "500")
142
+ end
143
+
144
+ it "should convert attribute key with @" do
145
+ test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
146
+ test_currency.to_hash["@currencyID"].should eql "USD"
147
+ end
148
+
149
+ it "should convert attribute key without @" do
150
+ test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
151
+ test_currency.to_hash(:attribute => false)["currencyID"].should eql "USD"
152
+ end
153
+
154
+ it "should convert to hash with namespace" do
155
+ test_currency = TestCurrency.new(:currencyID => "USD", :amount => "500", :desciption => "Testing" )
156
+ hash = test_currency.to_hash
157
+ hash["amount"].should eql "500"
158
+ hash["ns:desciption"].should eql "Testing"
159
+ hash["@currencyID"].should eql "USD"
160
+ hash = test_currency.to_hash(:namespace => false)
161
+ hash["amount"].should eql "500"
162
+ hash["desciption"].should eql "Testing"
163
+ hash["@currencyID"].should eql "USD"
164
+ end
165
+
166
+ it "should allow namespace" do
167
+ test_currency = TestCurrency.new(:amount => "500", :"ns:desciption" => "Testing" )
168
+ test_currency.desciption.should eql "Testing"
169
+ end
170
+
171
+ it "should use name option in members" do
172
+ test_type = TestType.new( :firstname => "FirstName")
173
+ test_type.to_hash.should eql({"first-name" => "FirstName" })
174
+ end
175
+
176
+ it "should allow date" do
177
+ date_time = "2010-10-10T10:10:10"
178
+ test_simple_type = TestSimpleType.new( :created_on => date_time, :created_at => date_time )
179
+ test_simple_type.created_on.should be_a Date
180
+ test_simple_type.created_at.should be_a DateTime
181
+ end
182
+
183
+ it "should allow date with value 0" do
184
+ test_simple_type = TestSimpleType.new( :created_at => "0" )
185
+ test_simple_type.created_at.should be_a DateTime
186
+ end
187
+
188
+ end
189
+
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayPal::SDK::Core::API::REST do
4
+
5
+ module PayPalRest
6
+ class API < PayPal::SDK::Core::API::REST
7
+ end
8
+ end
9
+
10
+ def create_api(*args)
11
+ api = PayPalRest::API.new(*args)
12
+ @log_file ||= File.open("spec/log/rest_http.log", "w")
13
+ api.http.set_debug_output(@log_file)
14
+ api
15
+ end
16
+
17
+ before :all do
18
+ @api = create_api("v1/payments/", :with_authentication)
19
+ @vault_api = create_api("v1/vault/", :with_authentication)
20
+ end
21
+
22
+ describe "Configuration" do
23
+ it "create api with prefix" do
24
+ api = create_api("v1/payments")
25
+ api.uri.path.should eql "/v1/payments"
26
+ end
27
+
28
+ it "service endpoint for sandbox" do
29
+ api = create_api
30
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
31
+ api.token_endpoint.should eql "https://api.sandbox.paypal.com"
32
+ api = create_api( :mode => "sandbox" )
33
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
34
+ api.token_endpoint.should eql "https://api.sandbox.paypal.com"
35
+ api = create_api( :mode => :sandbox )
36
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
37
+ api.token_endpoint.should eql "https://api.sandbox.paypal.com"
38
+ api = create_api( :mode => "invalid" )
39
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
40
+ api.token_endpoint.should eql "https://api.sandbox.paypal.com"
41
+ api = create_api( :mode => nil )
42
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
43
+ api.token_endpoint.should eql "https://api.sandbox.paypal.com"
44
+ end
45
+
46
+ it "service endpoint for live" do
47
+ api = create_api( :mode => "live" )
48
+ api.service_endpoint.should eql "https://api.paypal.com"
49
+ api.token_endpoint.should eql "https://api.paypal.com"
50
+ api = create_api( :mode => :live )
51
+ api.service_endpoint.should eql "https://api.paypal.com"
52
+ api.token_endpoint.should eql "https://api.paypal.com"
53
+ end
54
+
55
+ it "override service endpoint" do
56
+ api = create_api( :rest_endpoint => "https://testing.api.paypal.com" )
57
+ api.service_endpoint.should eql "https://testing.api.paypal.com"
58
+ api.token_endpoint.should eql "https://testing.api.paypal.com"
59
+ api = create_api( :endpoint => "https://testing.api.paypal.com" )
60
+ api.service_endpoint.should eql "https://testing.api.paypal.com"
61
+ api.token_endpoint.should eql "https://testing.api.paypal.com"
62
+ end
63
+
64
+ it "override token endpoint" do
65
+ api = create_api( :rest_token_endpoint => "https://testing.api.paypal.com" )
66
+ api.service_endpoint.should eql "https://api.sandbox.paypal.com"
67
+ api.token_endpoint.should eql "https://testing.api.paypal.com"
68
+ end
69
+ end
70
+
71
+ describe "Validation" do
72
+ it "Invalid client_id and client_secret" do
73
+ api = create_api(:with_authentication, :client_id => "XYZ", :client_secret => "ABC")
74
+ lambda {
75
+ api.token
76
+ }.should raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
77
+ end
78
+
79
+ it "Should handle expired token" do
80
+ old_token = @api.token
81
+ @api.token_hash[:expires_in] = 0
82
+ @api.token.should_not eql old_token
83
+ end
84
+
85
+ it "Get token" do
86
+ @api.token.should_not be_nil
87
+ end
88
+ end
89
+
90
+ describe "Success request" do
91
+
92
+ it "Create Payment" do
93
+ response = @api.post("payment", {
94
+ "intent" => "sale",
95
+ "payer" => {
96
+ "payment_method" => "credit_card",
97
+ "funding_instruments" => [{
98
+ "credit_card" => {
99
+ "type" => "visa",
100
+ "number" => "4417119669820331",
101
+ "expire_month" => "11", "expire_year" => "2018",
102
+ "first_name" => "Joe", "last_name" => "Shopper" }}]},
103
+ "transactions" => [{
104
+ "amount" => {
105
+ "total" => "7.47",
106
+ "currency" => "USD" }}]})
107
+ response["error"].should be_nil
108
+ end
109
+
110
+ it "List Payments" do
111
+ response = @api.get("payment", { "count" => 10 })
112
+ response["error"].should be_nil
113
+ response["count"].should_not be_nil
114
+ end
115
+
116
+ it "Execute Payment"
117
+
118
+ it "Create FundingInstrument" do
119
+ new_funding_instrument = @vault_api.post("credit-card", {
120
+ "type" => "visa",
121
+ "number" => "4111111111111111",
122
+ "expire_month" => "11", "expire_year" => "2018",
123
+ "cvv2" => "874",
124
+ "first_name" => "Joe", "last_name" => "Shopper" })
125
+ new_funding_instrument["error"].should be_nil
126
+ new_funding_instrument["id"].should_not be_nil
127
+
128
+ funding_instrument = @vault_api.get("credit-card/#{new_funding_instrument["id"]}")
129
+ funding_instrument["error"].should be_nil
130
+ funding_instrument["id"].should eql new_funding_instrument["id"]
131
+ end
132
+
133
+ end
134
+
135
+ describe "Failure request" do
136
+ it "Invalid Resource ID" do
137
+ lambda {
138
+ response = @api.get("payment/PAY-1234")
139
+ }.should raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
140
+ end
141
+
142
+ it "Invalid parameters" do
143
+ response = @api.post("payment")
144
+ response["error"]["name"].should eql "VALIDATION_ERROR"
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayPal::SDK::Core::Config do
4
+
5
+ Config = PayPal::SDK::Core::Config
6
+
7
+ it "load configuration file and default environment" do
8
+ lambda {
9
+ Config.load("spec/config/paypal.yml", "test")
10
+ Config.default_environment.should eql "test"
11
+ }.should_not raise_error
12
+ end
13
+
14
+ it "Set default environment" do
15
+ begin
16
+ backup_default_environment = Config.default_environment
17
+ Config.default_environment = "new_env"
18
+ Config.default_environment.should eql "new_env"
19
+ ensure
20
+ Config.default_environment = backup_default_environment
21
+ end
22
+ end
23
+
24
+ it "Set configurations" do
25
+ begin
26
+ backup_configurations = Config.configurations
27
+ Config.configurations = { Config.default_environment => { :username => "direct", :password => "direct" } }
28
+ Config.config.username.should eql "direct"
29
+ Config.config.password.should eql "direct"
30
+ Config.config.signature.should be_nil
31
+ ensure
32
+ Config.configurations = backup_configurations
33
+ end
34
+ end
35
+
36
+ it "Configure with parameters" do
37
+ begin
38
+ backup_configurations = Config.configurations
39
+ Config.configurations = nil
40
+ Config.configure( :username => "Testing" )
41
+ Config.config.username.should eql "Testing"
42
+ Config.config.app_id.should be_nil
43
+ ensure
44
+ Config.configurations = backup_configurations
45
+ end
46
+ end
47
+
48
+ it "Configure with block" do
49
+ begin
50
+ backup_configurations = Config.configurations
51
+ Config.configurations = nil
52
+ Config.configure do |config|
53
+ config.username = "Testing"
54
+ end
55
+ Config.config.username.should eql "Testing"
56
+ Config.config.app_id.should be_nil
57
+ ensure
58
+ Config.configurations = backup_configurations
59
+ end
60
+ end
61
+
62
+ it "Configure with default values" do
63
+ begin
64
+ backup_configurations = Config.configurations
65
+ default_config = Config.config
66
+ Config.configure do |config|
67
+ config.username = "Testing"
68
+ end
69
+ Config.config.username.should eql "Testing"
70
+ Config.config.app_id.should_not be_nil
71
+ Config.config.app_id.should eql default_config.app_id
72
+ ensure
73
+ Config.configurations = backup_configurations
74
+ end
75
+ end
76
+
77
+ it "validate configuration" do
78
+ config = Config.new( :username => "XYZ")
79
+ lambda {
80
+ config.required!(:username)
81
+ }.should_not raise_error
82
+ lambda {
83
+ config.required!(:password)
84
+ }.should raise_error "Required configuration(password)"
85
+ lambda {
86
+ config.required!(:username, :password)
87
+ }.should raise_error "Required configuration(password)"
88
+ lambda {
89
+ config.required!(:password, :signature)
90
+ }.should raise_error "Required configuration(password, signature)"
91
+ end
92
+
93
+ it "return default environment configuration" do
94
+ Config.config.should be_a Config
95
+ end
96
+
97
+ it "return configuration based on environment" do
98
+ Config.config(:development).should be_a Config
99
+ end
100
+
101
+ it "override default configuration" do
102
+ override_configuration = { :username => "test.example.com", :app_id => "test"}
103
+ config = Config.config(override_configuration)
104
+
105
+ config.username.should eql(override_configuration[:username])
106
+ config.app_id.should eql(override_configuration[:app_id])
107
+ end
108
+
109
+ it "get cached config" do
110
+ Config.config(:test).should eql Config.config(:test)
111
+ Config.config(:test).should_not eql Config.config(:development)
112
+ end
113
+
114
+ it "should raise error on invalid environment" do
115
+ lambda {
116
+ Config.config(:invalid_env)
117
+ }.should raise_error "Configuration[invalid_env] NotFound"
118
+ end
119
+
120
+ it "set logger" do
121
+ require 'logger'
122
+ my_logger = Logger.new(STDERR)
123
+ Config.logger = my_logger
124
+ Config.logger.should eql my_logger
125
+ end
126
+
127
+ it "Access PayPal::SDK methods" do
128
+ PayPal::SDK.configure.should eql PayPal::SDK::Core::Config.config
129
+ PayPal::SDK.logger.should eql PayPal::SDK::Core::Config.logger
130
+ PayPal::SDK.logger = PayPal::SDK.logger
131
+ PayPal::SDK.logger.should eql PayPal::SDK::Core::Config.logger
132
+ end
133
+
134
+ describe "include Configuration" do
135
+ class TestConfig
136
+ include PayPal::SDK::Core::Configuration
137
+ end
138
+
139
+ it "Get default configuration" do
140
+ test_object = TestConfig.new
141
+ test_object.config.should be_a Config
142
+ end
143
+
144
+ it "Change environment" do
145
+ test_object = TestConfig.new
146
+ test_object.set_config("test")
147
+ test_object.config.should eql Config.config("test")
148
+ test_object.config.should_not eql Config.config("development")
149
+ end
150
+
151
+ it "Override environment configuration" do
152
+ test_object = TestConfig.new
153
+ test_object.set_config("test", :username => "test")
154
+ test_object.config.should_not eql Config.config("test")
155
+ end
156
+
157
+ it "Override default/current configuration" do
158
+ test_object = TestConfig.new
159
+ test_object.set_config( :username => "test")
160
+ test_object.config.username.should eql "test"
161
+ test_object.set_config( :password => "test")
162
+ test_object.config.password.should eql "test"
163
+ test_object.config.username.should eql "test"
164
+ end
165
+
166
+ it "Append ssl_options" do
167
+ test_object = TestConfig.new
168
+ test_object.set_config( :ssl_options => { :ca_file => "test_path" } )
169
+ test_object.config.ssl_options[:ca_file].should eql "test_path"
170
+ test_object.set_config( :ssl_options => { :verify_mode => 1 } )
171
+ test_object.config.ssl_options[:verify_mode].should eql 1
172
+ test_object.config.ssl_options[:ca_file].should eql "test_path"
173
+ end
174
+
175
+ it "Set configuration without loading configuration File" do
176
+ backup_configurations = Config.configurations
177
+ begin
178
+ Config.configurations = nil
179
+ test_object = TestConfig.new
180
+ lambda {
181
+ test_object.config
182
+ }.should raise_error
183
+ test_object.set_config( :username => "test" )
184
+ test_object.config.should be_a Config
185
+ ensure
186
+ Config.configurations = backup_configurations
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end