paypal-sdk-rest 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,214 +1,272 @@
1
- require 'spec_helper'
2
-
3
- describe "Payments" do
4
-
5
- PaymentAttributes = {
6
- "intent" => "sale",
7
- "payer" => {
8
- "payment_method" => "credit_card",
9
- "funding_instruments" => [ {
10
- "credit_card" => {
11
- "type" => "visa",
12
- "number" => "4417119669820331",
13
- "expire_month" => "11", "expire_year" => "2018",
14
- "cvv2" => "874",
15
- "first_name" => "Joe", "last_name" => "Shopper",
16
- "billing_address" => {
17
- "line1" => "52 N Main ST",
18
- "city" => "Johnstown",
19
- "state" => "OH",
20
- "postal_code" => "43210", "country_code" => "US" } } } ] },
21
- "transactions" => [ {
22
- "amount" => {
23
- "total" => "1.00",
24
- "currency" => "USD" },
25
- "description" => "This is the payment transaction description." } ] }
26
-
27
-
28
- it "Validate user-agent" do
29
- PayPal::SDK::REST::API.user_agent.should match "PayPalSDK/rest-sdk-ruby"
30
- end
31
-
32
- describe "Examples" do
33
- describe "REST" do
34
- it "Modifiy global configuration" do
35
- backup_config = PayPal::SDK::REST.api.config
36
- PayPal::SDK::REST.set_config( :client_id => "XYZ" )
37
- PayPal::SDK::REST.api.config.client_id.should eql "XYZ"
38
- PayPal::SDK::REST.set_config(backup_config)
39
- PayPal::SDK::REST.api.config.client_id.should_not eql "XYZ"
40
- end
41
- end
42
-
43
- describe "Payment" do
44
- it "Create" do
45
- payment = Payment.new(PaymentAttributes)
46
- # Create
47
- payment.create
48
- payment.error.should be_nil
49
- payment.id.should_not be_nil
50
- end
51
-
52
- it "Create with request_id" do
53
- payment = Payment.new(PaymentAttributes)
54
- payment.create
55
- payment.error.should be_nil
56
-
57
- request_id = payment.request_id
58
-
59
- new_payment = Payment.new(PaymentAttributes.merge( :request_id => request_id ))
60
- new_payment.create
61
- new_payment.error.should be_nil
62
-
63
- payment.id.should eql new_payment.id
64
-
65
- end
66
-
67
- it "Create with token" do
68
- api = API.new
69
- payment = Payment.new(PaymentAttributes.merge( :token => api.token ))
70
- Payment.api.should_not eql payment.api
71
- payment.create
72
- payment.error.should be_nil
73
- payment.id.should_not be_nil
74
- end
75
-
76
- it "Create with client_id and client_secret" do
77
- api = API.new
78
- payment = Payment.new(PaymentAttributes.merge( :client_id => api.config.client_id, :client_secret => api.config.client_secret))
79
- Payment.api.should_not eql payment.api
80
- payment.create
81
- payment.error.should be_nil
82
- payment.id.should_not be_nil
83
- end
84
-
85
- it "List" do
86
- payment_history = Payment.all( "count" => 5 )
87
- payment_history.error.should be_nil
88
- payment_history.count.should eql 5
89
- end
90
-
91
- it "Find" do
92
- payment_history = Payment.all( "count" => 1 )
93
- payment = Payment.find(payment_history.payments[0].id)
94
- payment.error.should be_nil
95
- end
96
-
97
- describe "Validation" do
98
-
99
- it "Create with empty values" do
100
- payment = Payment.new
101
- payment.create.should be_false
102
- end
103
-
104
- it "Find with invalid ID" do
105
- lambda {
106
- payment = Payment.find("Invalid")
107
- }.should raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
108
- end
109
-
110
- it "Find with nil" do
111
- lambda{
112
- payment = Payment.find(nil)
113
- }.should raise_error ArgumentError
114
- end
115
-
116
- it "Find with empty string" do
117
- lambda{
118
- payment = Payment.find("")
119
- }.should raise_error ArgumentError
120
- end
121
-
122
- it "Find record with expired token" do
123
- lambda {
124
- Payment.api.token
125
- Payment.api.token.sub!(/^/, "Expired")
126
- Payment.all(:count => 1)
127
- }.should_not raise_error
128
- end
129
- end
130
-
131
- describe "instance method" do
132
-
133
- it "Execute" do
134
- payment = Payment.find("PAY-6BL56416NR538963NKE3QC5Q")
135
- payment.execute( :payer_id => "HZH2W8NPXUE5W" )
136
- # payment.error.should be_nil
137
- pending "Test with capybara"
138
- end
139
- end
140
-
141
- end
142
-
143
- describe "Sale" do
144
- before :each do
145
- @payment = Payment.new(PaymentAttributes)
146
- @payment.create
147
- @payment.should be_success
148
- end
149
-
150
- it "Find" do
151
- sale = Sale.find(@payment.transactions[0].related_resources[0].sale.id)
152
- sale.error.should be_nil
153
- sale.should be_a Sale
154
- end
155
-
156
- describe "instance method" do
157
- it "Refund" do
158
- sale = @payment.transactions[0].related_resources[0].sale
159
- refund = sale.refund( :amount => { :total => "1.00", :currency => "USD" } )
160
- refund.error.should be_nil
161
-
162
- refund = Refund.find(refund.id)
163
- refund.error.should be_nil
164
- refund.should be_a Refund
165
- end
166
- end
167
- end
168
-
169
- describe "CreditCard" do
170
- it "Create" do
171
- credit_card = CreditCard.new({
172
- "type" => "visa",
173
- "number" => "4417119669820331",
174
- "expire_month" => "11", "expire_year" => "2018",
175
- "cvv2" => "874",
176
- "first_name" => "Joe", "last_name" => "Shopper",
177
- "billing_address" => {
178
- "line1" => "52 N Main ST",
179
- "city" => "Johnstown",
180
- "state" => "OH",
181
- "postal_code" => "43210", "country_code" => "US" }})
182
- credit_card.create
183
- credit_card.error.should be_nil
184
- credit_card.id.should_not be_nil
185
-
186
- credit_card = CreditCard.find(credit_card.id)
187
- credit_card.should be_a CreditCard
188
- credit_card.error.should be_nil
189
- end
190
-
191
- describe "Validation" do
192
- it "Create" do
193
- credit_card = CreditCard.new({
194
- "type" => "visa",
195
- "number" => "4111111111111111" })
196
- credit_card.create
197
- credit_card.error.should_not be_nil
198
-
199
- credit_card.error.name.should eql "VALIDATION_ERROR"
200
- credit_card.error["name"].should eql "VALIDATION_ERROR"
201
-
202
- credit_card.error.details[0].field.should eql "expire_year"
203
- credit_card.error.details[0].issue.should eql "Required field missing"
204
- credit_card.error.details[1].field.should eql "expire_month"
205
- credit_card.error.details[1].issue.should eql "Required field missing"
206
-
207
- credit_card.error["details"][0]["issue"].should eql "Required field missing"
208
- end
209
- end
210
-
211
- end
212
-
213
- end
214
- end
1
+ require 'spec_helper'
2
+
3
+ describe "Payments" do
4
+
5
+ PaymentAttributes = {
6
+ "intent" => "sale",
7
+ "payer" => {
8
+ "payment_method" => "credit_card",
9
+ "funding_instruments" => [ {
10
+ "credit_card" => {
11
+ "type" => "visa",
12
+ "number" => "4417119669820331",
13
+ "expire_month" => "11", "expire_year" => "2018",
14
+ "cvv2" => "874",
15
+ "first_name" => "Joe", "last_name" => "Shopper",
16
+ "billing_address" => {
17
+ "line1" => "52 N Main ST",
18
+ "city" => "Johnstown",
19
+ "state" => "OH",
20
+ "postal_code" => "43210", "country_code" => "US" } } } ] },
21
+ "transactions" => [ {
22
+ "amount" => {
23
+ "total" => "1.00",
24
+ "currency" => "USD" },
25
+ "description" => "This is the payment transaction description." } ] }
26
+
27
+
28
+ it "Validate user-agent" do
29
+ PayPal::SDK::REST::API.user_agent.should match "PayPalSDK/rest-sdk-ruby"
30
+ end
31
+
32
+ describe "Examples" do
33
+ describe "REST" do
34
+ it "Modifiy global configuration" do
35
+ backup_config = PayPal::SDK::REST.api.config
36
+ PayPal::SDK::REST.set_config( :client_id => "XYZ" )
37
+ PayPal::SDK::REST.api.config.client_id.should eql "XYZ"
38
+ PayPal::SDK::REST.set_config(backup_config)
39
+ PayPal::SDK::REST.api.config.client_id.should_not eql "XYZ"
40
+ end
41
+ end
42
+
43
+ describe "Payment" do
44
+ it "Create" do
45
+ payment = Payment.new(PaymentAttributes)
46
+ # Create
47
+ payment.create
48
+ payment.error.should be_nil
49
+ payment.id.should_not be_nil
50
+ end
51
+
52
+ it "Create with request_id" do
53
+ payment = Payment.new(PaymentAttributes)
54
+ payment.create
55
+ payment.error.should be_nil
56
+
57
+ request_id = payment.request_id
58
+
59
+ new_payment = Payment.new(PaymentAttributes.merge( :request_id => request_id ))
60
+ new_payment.create
61
+ new_payment.error.should be_nil
62
+
63
+ payment.id.should eql new_payment.id
64
+
65
+ end
66
+
67
+ it "Create with token" do
68
+ api = API.new
69
+ payment = Payment.new(PaymentAttributes.merge( :token => api.token ))
70
+ Payment.api.should_not eql payment.api
71
+ payment.create
72
+ payment.error.should be_nil
73
+ payment.id.should_not be_nil
74
+ end
75
+
76
+ it "Create with client_id and client_secret" do
77
+ api = API.new
78
+ payment = Payment.new(PaymentAttributes.merge( :client_id => api.config.client_id, :client_secret => api.config.client_secret))
79
+ Payment.api.should_not eql payment.api
80
+ payment.create
81
+ payment.error.should be_nil
82
+ payment.id.should_not be_nil
83
+ end
84
+
85
+ it "List" do
86
+ payment_history = Payment.all( "count" => 5 )
87
+ payment_history.error.should be_nil
88
+ payment_history.count.should eql 5
89
+ end
90
+
91
+ it "Find" do
92
+ payment_history = Payment.all( "count" => 1 )
93
+ payment = Payment.find(payment_history.payments[0].id)
94
+ payment.error.should be_nil
95
+ end
96
+
97
+ describe "Validation" do
98
+
99
+ it "Create with empty values" do
100
+ payment = Payment.new
101
+ payment.create.should be_false
102
+ end
103
+
104
+ it "Find with invalid ID" do
105
+ lambda {
106
+ payment = Payment.find("Invalid")
107
+ }.should raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
108
+ end
109
+
110
+ it "Find with nil" do
111
+ lambda{
112
+ payment = Payment.find(nil)
113
+ }.should raise_error ArgumentError
114
+ end
115
+
116
+ it "Find with empty string" do
117
+ lambda{
118
+ payment = Payment.find("")
119
+ }.should raise_error ArgumentError
120
+ end
121
+
122
+ it "Find record with expired token" do
123
+ lambda {
124
+ Payment.api.token
125
+ Payment.api.token.sub!(/^/, "Expired")
126
+ Payment.all(:count => 1)
127
+ }.should_not raise_error
128
+ end
129
+ end
130
+
131
+ describe "instance method" do
132
+
133
+ it "Execute" do
134
+ payment = Payment.find("PAY-2XC06729XY607624MKGTR3GQ")
135
+ payment.execute( :payer_id => "TWLK53YN7GDM6" )
136
+ # payment.error.should be_nil
137
+ pending "Test with capybara"
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ describe "Sale" do
144
+ before :each do
145
+ @payment = Payment.new(PaymentAttributes)
146
+ @payment.create
147
+ @payment.should be_success
148
+ end
149
+
150
+ it "Find" do
151
+ sale = Sale.find(@payment.transactions[0].related_resources[0].sale.id)
152
+ sale.error.should be_nil
153
+ sale.should be_a Sale
154
+ end
155
+
156
+ describe "instance method" do
157
+ it "Refund" do
158
+ sale = @payment.transactions[0].related_resources[0].sale
159
+ refund = sale.refund( :amount => { :total => "1.00", :currency => "USD" } )
160
+ refund.error.should be_nil
161
+
162
+ refund = Refund.find(refund.id)
163
+ refund.error.should be_nil
164
+ refund.should be_a Refund
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "Authorize" do
170
+ before :each do
171
+ @payment = Payment.new(PaymentAttributes.merge( :intent => "authorize" ))
172
+ @payment.create
173
+ @payment.error.should be_nil
174
+ end
175
+
176
+ it "Find" do
177
+ authorize = Authorization.find(@payment.transactions[0].related_resources[0].authorization.id)
178
+ authorize.error.should be_nil
179
+ authorize.should be_a Authorization
180
+ end
181
+
182
+ it "Capture" do
183
+ authorize = @payment.transactions[0].related_resources[0].authorization
184
+ capture = authorize.capture({:amount => { :currency => "USD", :total => "1.00" } })
185
+ capture.error.should be_nil
186
+ end
187
+
188
+ it "Void" do
189
+ authorize = @payment.transactions[0].related_resources[0].authorization
190
+ authorize.void()
191
+ authorize.error.should be_nil
192
+ end
193
+
194
+ end
195
+
196
+ describe "Capture" do
197
+ before :each do
198
+ @payment = Payment.new(PaymentAttributes.merge( :intent => "authorize" ))
199
+ @payment.create
200
+ @payment.error.should be_nil
201
+ authorize = @payment.transactions[0].related_resources[0].authorization
202
+ @capture = authorize.capture({:amount => { :currency => "USD", :total => "1.00" } })
203
+ @capture.error.should be_nil
204
+ end
205
+
206
+ it "Find" do
207
+ capture = Capture.find(@capture.id)
208
+ capture.error.should be_nil
209
+ capture.should be_a Capture
210
+ end
211
+
212
+ it "Refund" do
213
+ refund = @capture.refund({})
214
+ refund.error.should be_nil
215
+ end
216
+ end
217
+
218
+ describe "CreditCard" do
219
+ it "Create" do
220
+ credit_card = CreditCard.new({
221
+ "type" => "visa",
222
+ "number" => "4417119669820331",
223
+ "expire_month" => "11", "expire_year" => "2018",
224
+ "cvv2" => "874",
225
+ "first_name" => "Joe", "last_name" => "Shopper",
226
+ "billing_address" => {
227
+ "line1" => "52 N Main ST",
228
+ "city" => "Johnstown",
229
+ "state" => "OH",
230
+ "postal_code" => "43210", "country_code" => "US" }})
231
+ credit_card.create
232
+ credit_card.error.should be_nil
233
+ credit_card.id.should_not be_nil
234
+
235
+ credit_card = CreditCard.find(credit_card.id)
236
+ credit_card.should be_a CreditCard
237
+ credit_card.error.should be_nil
238
+ end
239
+
240
+ it "Delete" do
241
+ credit_card = CreditCard.new({
242
+ "type" => "visa",
243
+ "number" => "4417119669820331",
244
+ "expire_month" => "11", "expire_year" => "2018" })
245
+ credit_card.create.should be_true
246
+ credit_card.delete.should be_true
247
+ end
248
+
249
+ describe "Validation" do
250
+ it "Create" do
251
+ credit_card = CreditCard.new({
252
+ "type" => "visa",
253
+ "number" => "4111111111111111" })
254
+ credit_card.create
255
+ credit_card.error.should_not be_nil
256
+
257
+ credit_card.error.name.should eql "VALIDATION_ERROR"
258
+ credit_card.error["name"].should eql "VALIDATION_ERROR"
259
+
260
+ credit_card.error.details[0].field.should eql "expire_year"
261
+ credit_card.error.details[0].issue.should eql "Required field missing"
262
+ credit_card.error.details[1].field.should eql "expire_month"
263
+ credit_card.error.details[1].issue.should eql "Required field missing"
264
+
265
+ credit_card.error["details"][0]["issue"].should eql "Required field missing"
266
+ end
267
+ end
268
+
269
+ end
270
+
271
+ end
272
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,24 +1,24 @@
1
- require 'bundler/setup'
2
-
3
- if ENV['COVERAGE']
4
- require 'simplecov'
5
- SimpleCov.start do
6
- add_filter "/spec/"
7
- end
8
- end
9
-
10
- Bundler.require :default, :test
11
- PayPal::SDK::Core::Config.load(File.expand_path('../config/paypal.yml', __FILE__), 'test')
12
-
13
- require 'paypal-sdk-rest'
14
-
15
- include PayPal::SDK::REST
16
- include PayPal::SDK::Core::Logging
17
-
18
- # Set logger for http
19
- http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
20
- Payment.api.http.set_debug_output(http_log)
21
-
22
- RSpec.configure do |config|
23
- # config.include PayPal::SDK::REST::DataTypes
24
- end
1
+ require 'bundler/setup'
2
+
3
+ if ENV['COVERAGE']
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ end
8
+ end
9
+
10
+ Bundler.require :default, :test
11
+ PayPal::SDK::Core::Config.load(File.expand_path('../config/paypal.yml', __FILE__), 'test')
12
+
13
+ require 'paypal-sdk-rest'
14
+
15
+ include PayPal::SDK::REST
16
+ include PayPal::SDK::Core::Logging
17
+
18
+ # Set logger for http
19
+ http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
20
+ Payment.api.http.set_debug_output(http_log)
21
+
22
+ RSpec.configure do |config|
23
+ # config.include PayPal::SDK::REST::DataTypes
24
+ end
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal-sdk-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - PayPal
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-26 00:00:00.000000000 Z
12
+ date: 2013-05-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: paypal-sdk-core
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
19
- version: 0.2.3
21
+ version: 0.2.4
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
- version: 0.2.3
29
+ version: 0.2.4
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: uuidtools
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -46,51 +51,52 @@ executables: []
46
51
  extensions: []
47
52
  extra_rdoc_files: []
48
53
  files:
54
+ - spec/config/cacert.pem
55
+ - spec/config/cert_key.pem
56
+ - spec/config/paypal.yml
49
57
  - spec/log/http.log
50
58
  - spec/payments_examples_spec.rb
51
59
  - spec/spec_helper.rb
52
- - spec/config/cacert.pem
53
- - spec/config/paypal.yml
54
- - spec/config/cert_key.pem
55
- - lib/paypal-sdk-rest.rb
56
- - lib/paypal-sdk/rest.rb
60
+ - lib/paypal-sdk/rest/api.rb
61
+ - lib/paypal-sdk/rest/data_types.rb
57
62
  - lib/paypal-sdk/rest/error_hash.rb
58
63
  - lib/paypal-sdk/rest/get_api.rb
59
- - lib/paypal-sdk/rest/api.rb
60
- - lib/paypal-sdk/rest/version.rb
61
- - lib/paypal-sdk/rest/set_api.rb
62
64
  - lib/paypal-sdk/rest/request_data_type.rb
63
- - lib/paypal-sdk/rest/data_types.rb
65
+ - lib/paypal-sdk/rest/set_api.rb
66
+ - lib/paypal-sdk/rest/version.rb
67
+ - lib/paypal-sdk/rest.rb
68
+ - lib/paypal-sdk-rest.rb
64
69
  - Rakefile
65
70
  - README.md
66
71
  - Gemfile
67
72
  homepage: https://developer.paypal.com
68
73
  licenses: []
69
- metadata: {}
70
74
  post_install_message:
71
75
  rdoc_options: []
72
76
  require_paths:
73
77
  - lib
74
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
75
80
  requirements:
76
81
  - - ! '>='
77
82
  - !ruby/object:Gem::Version
78
83
  version: '0'
79
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
80
86
  requirements:
81
87
  - - ! '>='
82
88
  - !ruby/object:Gem::Version
83
89
  version: '0'
84
90
  requirements: []
85
91
  rubyforge_project:
86
- rubygems_version: 2.0.0
92
+ rubygems_version: 1.8.24
87
93
  signing_key:
88
- specification_version: 4
94
+ specification_version: 3
89
95
  summary: The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
90
96
  test_files:
97
+ - spec/config/cacert.pem
98
+ - spec/config/cert_key.pem
99
+ - spec/config/paypal.yml
91
100
  - spec/log/http.log
92
101
  - spec/payments_examples_spec.rb
93
102
  - spec/spec_helper.rb
94
- - spec/config/cacert.pem
95
- - spec/config/paypal.yml
96
- - spec/config/cert_key.pem
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWQ5ZjMxODJmNmY0OTc0MDhlOTU3ZDljYTJlZDQ3NWY5NTMxM2RmMg==
5
- data.tar.gz: !binary |-
6
- NDdjODVlMjZjYjg4YjY4ZTFkMjJjMzRjNGIxMjU2YWFlMmRhZDJhMQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MmZkMWJkNDViYTcyYzEzOTIzZDczODJlYjAwMzNkYjU2ZDMxZjUyNjYxOGYz
10
- YWQ1NTAyNzM5MjQ5ZTc0MzI2ZmMzYzZkODdiMmZiMjFhNjlmMzhkZTExMTg5
11
- NmY5MzE1ZDAwZTViNTk5NjRmZjU3ZTgwOGQwZjMxNzAyNDM4ZTc=
12
- data.tar.gz: !binary |-
13
- NmE4ZDNmMWUxOWJkZWViZTI1YTY0MTM3NDA1ZGFkNjUyMjNlMTI4ZDM1ZjM0
14
- NTUwYzAyMzM2NDM0NjQ5OTA5YjA1YTJlYzM1NDJmMjg1YmUzOThkYmVlYmQ1
15
- Y2U2MGQxYTVlMDUxMThiYTMxYzM3YWIxYzkyYjE3NDk2N2Y3MjM=