paypal-sdk-rest-pmrb 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/README.md +265 -0
  4. data/Rakefile +15 -0
  5. data/data/DigiCertHighAssuranceEVRootCA.pem +23 -0
  6. data/data/DigiCertSHA2ExtendedValidationServerCA.pem +28 -0
  7. data/data/paypal.crt +193 -0
  8. data/lib/generators/paypal/sdk/USAGE +3 -0
  9. data/lib/generators/paypal/sdk/install_generator.rb +17 -0
  10. data/lib/generators/paypal/sdk/templates/paypal.rb +2 -0
  11. data/lib/generators/paypal/sdk/templates/paypal.yml +29 -0
  12. data/lib/paypal-sdk-core.rb +38 -0
  13. data/lib/paypal-sdk-rest.rb +2 -0
  14. data/lib/paypal-sdk/core/api.rb +20 -0
  15. data/lib/paypal-sdk/core/api/base.rb +169 -0
  16. data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +44 -0
  17. data/lib/paypal-sdk/core/api/data_types/base.rb +225 -0
  18. data/lib/paypal-sdk/core/api/data_types/enum.rb +26 -0
  19. data/lib/paypal-sdk/core/api/data_types/simple_types.rb +52 -0
  20. data/lib/paypal-sdk/core/api/ipn.rb +66 -0
  21. data/lib/paypal-sdk/core/api/rest.rb +177 -0
  22. data/lib/paypal-sdk/core/authentication.rb +66 -0
  23. data/lib/paypal-sdk/core/config.rb +253 -0
  24. data/lib/paypal-sdk/core/credential.rb +16 -0
  25. data/lib/paypal-sdk/core/credential/base.rb +27 -0
  26. data/lib/paypal-sdk/core/credential/certificate.rb +32 -0
  27. data/lib/paypal-sdk/core/credential/signature.rb +22 -0
  28. data/lib/paypal-sdk/core/credential/third_party/subject.rb +25 -0
  29. data/lib/paypal-sdk/core/credential/third_party/token.rb +39 -0
  30. data/lib/paypal-sdk/core/exceptions.rb +112 -0
  31. data/lib/paypal-sdk/core/logging.rb +50 -0
  32. data/lib/paypal-sdk/core/openid_connect.rb +140 -0
  33. data/lib/paypal-sdk/core/openid_connect/api.rb +50 -0
  34. data/lib/paypal-sdk/core/openid_connect/data_types.rb +73 -0
  35. data/lib/paypal-sdk/core/openid_connect/get_api.rb +28 -0
  36. data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +52 -0
  37. data/lib/paypal-sdk/core/openid_connect/set_api.rb +36 -0
  38. data/lib/paypal-sdk/core/util.rb +11 -0
  39. data/lib/paypal-sdk/core/util/http_helper.rb +171 -0
  40. data/lib/paypal-sdk/core/util/oauth_signature.rb +64 -0
  41. data/lib/paypal-sdk/core/util/ordered_hash.rb +165 -0
  42. data/lib/paypal-sdk/rest.rb +39 -0
  43. data/lib/paypal-sdk/rest/api.rb +23 -0
  44. data/lib/paypal-sdk/rest/data_types.rb +2597 -0
  45. data/lib/paypal-sdk/rest/error_hash.rb +39 -0
  46. data/lib/paypal-sdk/rest/get_api.rb +20 -0
  47. data/lib/paypal-sdk/rest/request_data_type.rb +53 -0
  48. data/lib/paypal-sdk/rest/set_api.rb +42 -0
  49. data/lib/paypal-sdk/rest/version.rb +7 -0
  50. data/spec/README.md +22 -0
  51. data/spec/config/cacert.pem +171 -0
  52. data/spec/config/cert_key.pem +33 -0
  53. data/spec/config/paypal.yml +35 -0
  54. data/spec/config/sample_data.yml +3 -0
  55. data/spec/core/api/data_type_spec.rb +289 -0
  56. data/spec/core/api/rest_spec.rb +211 -0
  57. data/spec/core/config_spec.rb +192 -0
  58. data/spec/core/logging_spec.rb +28 -0
  59. data/spec/core/openid_connect_spec.rb +153 -0
  60. data/spec/invoice_examples_spec.rb +38 -0
  61. data/spec/log/http.log +175 -0
  62. data/spec/log/rest_http.log +0 -0
  63. data/spec/payments_examples_spec.rb +437 -0
  64. data/spec/payouts_examples_spec.rb +74 -0
  65. data/spec/rest/data_types_spec.rb +62 -0
  66. data/spec/rest/error_hash_spec.rb +83 -0
  67. data/spec/spec_helper.rb +37 -0
  68. data/spec/subscription_examples_spec.rb +227 -0
  69. data/spec/support/sample_data.rb +5 -0
  70. data/spec/web_profile_examples_spec.rb +106 -0
  71. data/spec/webhooks_examples_spec.rb +93 -0
  72. metadata +177 -0
@@ -0,0 +1,211 @@
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
+ expect(api.uri.path).to eql "/v1/payments"
26
+ end
27
+
28
+ it "service endpoint for sandbox" do
29
+ api = create_api
30
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
31
+ expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
32
+ api = create_api( :mode => "sandbox" )
33
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
34
+ expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
35
+ api = create_api( :mode => :sandbox )
36
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
37
+ expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
38
+ api = create_api( :mode => "invalid" )
39
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
40
+ expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
41
+ api = create_api( :mode => nil )
42
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
43
+ expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
44
+ end
45
+
46
+ it "service endpoint for live" do
47
+ api = create_api( :mode => "live" )
48
+ expect(api.service_endpoint).to eql "https://api.paypal.com"
49
+ expect(api.token_endpoint).to eql "https://api.paypal.com"
50
+ api = create_api( :mode => :live )
51
+ expect(api.service_endpoint).to eql "https://api.paypal.com"
52
+ expect(api.token_endpoint).to 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
+ expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
58
+ expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
59
+ api = create_api( :endpoint => "https://testing.api.paypal.com" )
60
+ expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
61
+ expect(api.token_endpoint).to 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
+ expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
67
+ expect(api.token_endpoint).to 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
+ expect {
75
+ api.token
76
+ }.to 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
+ new_token = @api.token
83
+ expect(@api.token_hash[:expires_in]).not_to eql 0
84
+ end
85
+
86
+ it "Get token" do
87
+ expect(@api.token).not_to be_nil
88
+ end
89
+ end
90
+
91
+ describe "Success request", :integration => true do
92
+
93
+ it "Create Payment" do
94
+ response = @api.post("payment", {
95
+ "intent" => "sale",
96
+ "payer" => {
97
+ "payment_method" => "credit_card",
98
+ "funding_instruments" => [{
99
+ "credit_card" => {
100
+ "type" => "visa",
101
+ "number" => "4567516310777851",
102
+ "expire_month" => "11", "expire_year" => "2018",
103
+ "first_name" => "Joe", "last_name" => "Shopper" }}]},
104
+ "transactions" => [{
105
+ "amount" => {
106
+ "total" => "7.47",
107
+ "currency" => "USD" }}]})
108
+ expect(response["error"]).to be_nil
109
+ end
110
+
111
+ it "List Payments" do
112
+ response = @api.get("payment", { "count" => 10 })
113
+ expect(response["error"]).to be_nil
114
+ expect(response["count"]).not_to be_nil
115
+ end
116
+
117
+ it "Execute Payment"
118
+
119
+ it "Create FundingInstrument" do
120
+ new_funding_instrument = @vault_api.post("credit-card", {
121
+ "type" => "visa",
122
+ "number" => "4111111111111111",
123
+ "expire_month" => "11", "expire_year" => "2018",
124
+ "cvv2" => "874",
125
+ "first_name" => "Joe", "last_name" => "Shopper" })
126
+ expect(new_funding_instrument["error"]).to be_nil
127
+ expect(new_funding_instrument["id"]).not_to be_nil
128
+
129
+ funding_instrument = @vault_api.get("credit-card/#{new_funding_instrument["id"]}")
130
+ expect(funding_instrument["error"]).to be_nil
131
+ expect(funding_instrument["id"]).to eql new_funding_instrument["id"]
132
+ end
133
+
134
+ end
135
+
136
+ describe "Failure request", :integration => true do
137
+ it "Invalid Resource ID" do
138
+ expect {
139
+ response = @api.get("payment/PAY-1234")
140
+ }.to raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
141
+ end
142
+
143
+ it "Invalid parameters" do
144
+ response = @api.post("payment")
145
+ expect(response["error"]["name"]).to eql "VALIDATION_ERROR"
146
+ end
147
+ end
148
+
149
+ describe "format response" do
150
+ before :each do
151
+ @response = instance_double(Net::HTTPResponse)
152
+ allow(@response).to receive(:code) { "200" }
153
+ allow(@response).to receive(:content_type) { "application/json" }
154
+ end
155
+
156
+ it "parses empty object JSON correctly" do
157
+ allow(@response).to receive(:body) { "{}" }
158
+ payload = {
159
+ :response => @response
160
+ }
161
+
162
+ formatted_response = @api.format_response(payload)
163
+ expect(formatted_response).to_not be_nil
164
+ expect(formatted_response[:data]).to eq({})
165
+ end
166
+
167
+ it "parses empty string JSON correctly" do
168
+ allow(@response).to receive(:body) { '""' }
169
+ payload = {
170
+ :response => @response
171
+ }
172
+
173
+ formatted_response = @api.format_response(payload)
174
+ expect(formatted_response).to_not be_nil
175
+ expect(formatted_response[:data]).to eq("")
176
+ end
177
+
178
+ it "parses whitespace body correctly" do
179
+ allow(@response).to receive(:body) { ' ' }
180
+ payload = {
181
+ :response => @response
182
+ }
183
+
184
+ formatted_response = @api.format_response(payload)
185
+ expect(formatted_response).to_not be_nil
186
+ expect(formatted_response[:data]).to eq({})
187
+ end
188
+
189
+ it "parses nil body correctly" do
190
+ allow(@response).to receive(:body) { nil }
191
+ payload = {
192
+ :response => @response
193
+ }
194
+
195
+ formatted_response = @api.format_response(payload)
196
+ expect(formatted_response).to_not be_nil
197
+ expect(formatted_response[:data]).to eq({})
198
+ end
199
+
200
+ it "parses with whitespace around JSON correctly" do
201
+ allow(@response).to receive(:body) { ' { "test": "value" } ' }
202
+ payload = {
203
+ :response => @response
204
+ }
205
+
206
+ formatted_response = @api.format_response(payload)
207
+ expect(formatted_response).to_not be_nil
208
+ expect(formatted_response[:data]).to eq({ "test" => "value" })
209
+ end
210
+ end
211
+ 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
+ expect {
9
+ Config.load("spec/config/paypal.yml", "test")
10
+ expect(Config.default_environment).to eql "test"
11
+ }.not_to 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
+ expect(Config.default_environment).to 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
+ expect(Config.config.username).to eql "direct"
29
+ expect(Config.config.password).to eql "direct"
30
+ expect(Config.config.signature).to 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
+ expect(Config.config.username).to eql "Testing"
42
+ expect(Config.config.app_id).to 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
+ expect(Config.config.username).to eql "Testing"
56
+ expect(Config.config.app_id).to 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
+ expect(Config.config.username).to eql "Testing"
70
+ expect(Config.config.app_id).not_to be_nil
71
+ expect(Config.config.app_id).to 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
+ expect {
80
+ config.required!(:username)
81
+ }.not_to raise_error
82
+ expect {
83
+ config.required!(:password)
84
+ }.to raise_error "Required configuration(password)"
85
+ expect {
86
+ config.required!(:username, :password)
87
+ }.to raise_error "Required configuration(password)"
88
+ expect {
89
+ config.required!(:password, :signature)
90
+ }.to raise_error "Required configuration(password, signature)"
91
+ end
92
+
93
+ it "return default environment configuration" do
94
+ expect(Config.config).to be_a Config
95
+ end
96
+
97
+ it "return configuration based on environment" do
98
+ expect(Config.config(:development)).to 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
+ expect(config.username).to eql(override_configuration[:username])
106
+ expect(config.app_id).to eql(override_configuration[:app_id])
107
+ end
108
+
109
+ it "get cached config" do
110
+ expect(Config.config(:test)).to eql Config.config(:test)
111
+ expect(Config.config(:test)).not_to eql Config.config(:development)
112
+ end
113
+
114
+ it "should raise error on invalid environment" do
115
+ expect {
116
+ Config.config(:invalid_env)
117
+ }.to 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
+ expect(Config.logger).to eql my_logger
125
+ end
126
+
127
+ it "Access PayPal::SDK methods" do
128
+ expect(PayPal::SDK.configure).to eql PayPal::SDK::Core::Config.config
129
+ expect(PayPal::SDK.logger).to eql PayPal::SDK::Core::Config.logger
130
+ PayPal::SDK.logger = PayPal::SDK.logger
131
+ expect(PayPal::SDK.logger).to 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
+ expect(test_object.config).to be_a Config
142
+ end
143
+
144
+ it "Change environment" do
145
+ test_object = TestConfig.new
146
+ test_object.set_config("test")
147
+ expect(test_object.config).to eql Config.config("test")
148
+ expect(test_object.config).not_to 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
+ expect(test_object.config).not_to 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
+ expect(test_object.config.username).to eql "test"
161
+ test_object.set_config( :password => "test")
162
+ expect(test_object.config.password).to eql "test"
163
+ expect(test_object.config.username).to 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
+ expect(test_object.config.ssl_options[:ca_file]).to eql "test_path"
170
+ test_object.set_config( :ssl_options => { :verify_mode => 1 } )
171
+ expect(test_object.config.ssl_options[:verify_mode]).to eql 1
172
+ expect(test_object.config.ssl_options[:ca_file]).to 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
+ expect {
181
+ test_object.config
182
+ }.to raise_error
183
+ test_object.set_config( :username => "test" )
184
+ expect(test_object.config).to be_a Config
185
+ ensure
186
+ Config.configurations = backup_configurations
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe PayPal::SDK::Core::Logging do
5
+ Logging = PayPal::SDK::Core::Logging
6
+
7
+ class TestLogging
8
+ include Logging
9
+ end
10
+
11
+ before :each do
12
+ @logger_file = StringIO.new
13
+ Logging.logger = Logger.new(@logger_file)
14
+ @test_logging = TestLogging.new
15
+ end
16
+
17
+ it "get logger object" do
18
+ expect(@test_logging.logger).to be_a Logger
19
+ end
20
+
21
+ it "write message to logger" do
22
+ test_message = "Example log message!!!"
23
+ @test_logging.logger.info(test_message)
24
+ @logger_file.rewind
25
+ expect(@logger_file.read).to match test_message
26
+ end
27
+
28
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe PayPal::SDK::OpenIDConnect do
4
+ OpenIDConnect = PayPal::SDK::OpenIDConnect
5
+
6
+ before :all do
7
+ OpenIDConnect.set_config( :client_id => "client_id", :openid_redirect_uri => "http://google.com" )
8
+ end
9
+
10
+ it "Validate user_agent" do
11
+ expect(OpenIDConnect::API.user_agent).to match "PayPalSDK/openid-connect-ruby"
12
+ end
13
+
14
+ describe "generate_authorize_url" do
15
+
16
+ it "generate autorize_url" do
17
+ url = OpenIDConnect::Tokeninfo.authorize_url
18
+ expect(url).to match "client_id=client_id"
19
+ expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
20
+ expect(url).to match "scope=openid"
21
+ end
22
+
23
+ describe "sandbox" do
24
+ before do
25
+ PayPal::SDK.configure(:mode => "sandbox")
26
+ end
27
+
28
+ it "generates a sandbox authorize url" do
29
+ url = OpenIDConnect::Tokeninfo.authorize_url
30
+ expect(url).to match "sandbox.paypal.com"
31
+ end
32
+ end
33
+ end
34
+
35
+ it "Override authorize_url params" do
36
+ url = OpenIDConnect.authorize_url(
37
+ :client_id => "new_client_id",
38
+ :redirect_uri => "http://example.com",
39
+ :scope => "openid profile")
40
+ expect(url).to match "client_id=new_client_id"
41
+ expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://example.com")}")
42
+ expect(url).to match Regexp.escape("scope=#{CGI.escape("openid profile")}")
43
+ end
44
+
45
+ it "Generate logout_url" do
46
+ url = OpenIDConnect.logout_url
47
+ expect(url).to match "logout=true"
48
+ expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
49
+ expect(url).not_to match "id_token"
50
+ end
51
+
52
+ it "Override logout_url params" do
53
+ url = OpenIDConnect.logout_url({
54
+ :redirect_uri => "http://example.com",
55
+ :id_token => "testing" })
56
+ expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://example.com")}")
57
+ expect(url).to match "id_token=testing"
58
+ end
59
+
60
+ describe "Validation" do
61
+ it "Create token" do
62
+ expect{
63
+ tokeninfo = OpenIDConnect::Tokeninfo.create("invalid-autorize-code")
64
+ }.to raise_error PayPal::SDK::Core::Exceptions::BadRequest
65
+ end
66
+
67
+ it "Refresh token" do
68
+ expect{
69
+ tokeninfo = OpenIDConnect::Tokeninfo.refresh("invalid-refresh-token")
70
+ }.to raise_error PayPal::SDK::Core::Exceptions::BadRequest
71
+ end
72
+
73
+ it "Get userinfo" do
74
+ expect{
75
+ userinfo = OpenIDConnect::Userinfo.get("invalid-access-token")
76
+ }.to raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
77
+ end
78
+ end
79
+
80
+ describe "Tokeninfo" do
81
+ before do
82
+ @tokeninfo = OpenIDConnect::Tokeninfo.new( :access_token => "test_access_token",
83
+ :refresh_token => "test_refresh_token",
84
+ :id_token => "test_id_token" )
85
+ end
86
+
87
+ it "create" do
88
+ allow(OpenIDConnect::Tokeninfo.api).to receive_messages( :post => { :access_token => "access_token" } )
89
+ tokeninfo = OpenIDConnect::Tokeninfo.create("authorize_code")
90
+ expect(tokeninfo).to be_a OpenIDConnect::Tokeninfo
91
+ expect(tokeninfo.access_token).to eql "access_token"
92
+ end
93
+
94
+ it "refresh" do
95
+ allow(@tokeninfo.api).to receive_messages( :post => { :access_token => "new_access_token" } )
96
+ expect(@tokeninfo.access_token).to eql "test_access_token"
97
+ @tokeninfo.refresh
98
+ expect(@tokeninfo.access_token).to eql "new_access_token"
99
+ end
100
+
101
+ it "userinfo" do
102
+ allow(@tokeninfo.api).to receive_messages( :post => { :name => "Testing" } )
103
+ userinfo = @tokeninfo.userinfo
104
+ expect(userinfo).to be_a OpenIDConnect::Userinfo
105
+ expect(userinfo.name).to eql "Testing"
106
+ end
107
+
108
+ describe "logout_url" do
109
+ it "Generate logout_url" do
110
+ url = @tokeninfo.logout_url
111
+ expect(url).to match "id_token=test_id_token"
112
+ expect(url).to match "logout=true"
113
+ expect(url).to match Regexp.escape("redirect_uri=#{CGI.escape("http://google.com")}")
114
+ end
115
+
116
+ describe "sandbox" do
117
+ before do
118
+ PayPal::SDK.configure(:mode => "sandbox")
119
+ end
120
+
121
+ it "generates a sandbox logout url" do
122
+ url = @tokeninfo.logout_url
123
+ expect(url).to match "sandbox.paypal.com"
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "Userinfo" do
130
+ it "get" do
131
+ allow(OpenIDConnect::Userinfo.api).to receive_messages( :post => { :name => "Testing" } )
132
+
133
+ userinfo = OpenIDConnect::Userinfo.get("access_token")
134
+ userinfo = OpenIDConnect::Userinfo.new( { :name => "Testing" } )
135
+ expect(userinfo).to be_a OpenIDConnect::Userinfo
136
+ expect(userinfo.name).to eql "Testing"
137
+
138
+ userinfo = OpenIDConnect::Userinfo.get( :access_token => "access_token" )
139
+ expect(userinfo).to be_a OpenIDConnect::Userinfo
140
+ expect(userinfo.name).to eql "Testing"
141
+ end
142
+
143
+ it "get", :integration => true do
144
+ api = PayPal::SDK::REST::API.new
145
+ access_token = api.token_hash()
146
+ userinfo = OpenIDConnect::Userinfo.get( access_token )
147
+ expect(userinfo).to be_a OpenIDConnect::Userinfo
148
+ expect(userinfo.email).to eql "jaypatel512-facilitator@hotmail.com"
149
+ end
150
+ end
151
+
152
+
153
+ end