paypal-sdk-rest 0.5.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2RlZWM2YmZkOGMwNWUxYzM4MjE3MmY4YjIyZmY3OTgyNzk0ZmY0OA==
5
+ data.tar.gz: !binary |-
6
+ NzI0YmMyNTM5ZTNjYjQxYzlmOTFjNDBkMzk1ZTQ2N2U0NTE1NjMyNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTM3MDgxZjQyMjkxZDcyYTkwYWJhZGI2ZjFmZTFiM2RhNzYzMmUxODE1NGQx
10
+ NWM4NzYzOWRkYjlhOWFiMmRiMjkxMmI1NGQwMjMwYjExZDg0NjdmNWQ5YWEy
11
+ MzQ0YjExYTBjMDEzNGNjNjY4ZGYzMTk5OTZmNGI3YmM0NzY1Yzg=
12
+ data.tar.gz: !binary |-
13
+ MmZhMjVjYmE0NmI2N2Q4NTBiZGI3NjgyM2ExMjZmYmNiMGFjNjA4NGEzNTEw
14
+ YjYzMDFmZTVjZTBkNmViNWE3ZjU4NTk5YTRiNjM1OTY5ZGU1OTYzMTNhMzEy
15
+ YmRjMTY2ZjI4OGJjYjk2OGM1YWM3YThmNDYwYzMwNDRlOGEyMDM=
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'paypal-sdk-core', :git => "https://github.com/paypal/sdk-core-ruby.git"
6
+
7
+ gem 'rake', :require => false
8
+
9
+ group :test do
10
+ gem 'simplecov', :require => false
11
+ gem 'rspec'
12
+ end
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # REST SDK
2
+
3
+ The PayPal REST SDK provides Ruby APIs to create, process and manage rest.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'paypal-sdk-rest'
10
+
11
+ # gem 'paypal-sdk-core', :git => "https://github.com/paypal/sdk-core-ruby.git"
12
+ # gem 'paypal-sdk-rest', :git => "https://github.com/paypal/rest-api-sdk-ruby.git"
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install paypal-sdk-rest
21
+
22
+ ## Configuration
23
+
24
+ For Rails application:
25
+
26
+ rails g paypal:sdk:install
27
+
28
+ For other ruby application, create a configuration file(`config/paypal.yml`):
29
+
30
+ development: &default
31
+ client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
32
+ client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
33
+ mode: sandbox
34
+ # # with Proxy
35
+ # http_proxy: http://proxy-ipaddress:3129/
36
+ # # with CA File
37
+ # ssl_options:
38
+ # ca_file: config/cacert.pem
39
+ # # Override Endpoint
40
+ # rest_endpoint: https://api.sandbox.paypal.com
41
+ test:
42
+ <<: *default
43
+ production:
44
+ <<: *default
45
+ mode: live
46
+
47
+
48
+ Load Configurations from specified file:
49
+
50
+ PayPal::SDK::Core::Config.load('spec/config/paypal.yml', ENV['RACK_ENV'] || 'development')
51
+
52
+ Without configuration file:
53
+
54
+ PayPal::SDK::REST.set_config(
55
+ :client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
56
+ :client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
57
+ :mode => "sandbox", # "sandbox" or "live"
58
+ :ssl_options => { } )
59
+
60
+ Override configuration:
61
+
62
+ # Class level
63
+ Payment.set_config( :client_id => "123" )
64
+
65
+ # Object level
66
+ payment.set_config( :client_id => "123" )
67
+
68
+
69
+ ## Create Payment
70
+
71
+ ```ruby
72
+ require 'paypal-sdk-rest'
73
+ include PayPal::SDK::REST
74
+
75
+ PayPal::SDK::REST.set_config(
76
+ :client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
77
+ :client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
78
+ :mode => "sandbox" )
79
+
80
+ # Build Payment object
81
+ @payment = Payment.new({
82
+ :intent => "sale",
83
+ :payer => {
84
+ :payment_method => "credit_card",
85
+ :funding_instruments => [{
86
+ :credit_card => {
87
+ :type => "visa",
88
+ :number => "4417119669820331",
89
+ :expire_month => "11",
90
+ :expire_year => "2018",
91
+ :cvv2 => "874",
92
+ :first_name => "Joe",
93
+ :last_name => "Shopper",
94
+ :billing_address => {
95
+ :line1 => "52 N Main ST",
96
+ :city => "Johnstown",
97
+ :state => "OH",
98
+ :postal_code => "43210",
99
+ :country_code => "US" }}}]},
100
+ :transactions => [{
101
+ :amount => {
102
+ :total => "1.00",
103
+ :currency => "USD" },
104
+ :description => "This is the payment transaction description." }]})
105
+
106
+ # Make API call & get response
107
+ if @payment.create
108
+ @payment.id # Payment Id
109
+ else
110
+ @payment.error # Error Hash
111
+ end
112
+ ```
113
+
114
+ ## Get Payment
115
+
116
+ ```ruby
117
+ # Fetch Payment
118
+ payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
119
+
120
+ # Get List of REST
121
+ payment_history = Payment.all( :count => 10 )
122
+
123
+ payment_history.payments
124
+ ```
125
+
126
+ ## Execute Payment
127
+
128
+ ```ruby
129
+ payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
130
+
131
+ if payment.execute( :payer_id => "DUFRQ8GWYMJXC" )
132
+ # Success Message
133
+ else
134
+ payment.error # Error Hash
135
+ end
136
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run tests"
4
+ task :rspec do
5
+ cmd = "bundle exec rspec"
6
+ system(cmd) || raise("#{cmd} failed")
7
+ end
8
+
9
+ task :default => :rspec
@@ -0,0 +1,2 @@
1
+ require "paypal-sdk/rest"
2
+
@@ -0,0 +1,38 @@
1
+ require 'paypal-sdk-core'
2
+
3
+ module PayPal
4
+ module SDK
5
+ module REST
6
+ autoload :VERSION, "paypal-sdk/rest/version"
7
+ autoload :DataTypes, "paypal-sdk/rest/data_types"
8
+ autoload :API, "paypal-sdk/rest/api"
9
+ autoload :RequestDataType, "paypal-sdk/rest/request_data_type"
10
+ autoload :SetAPI, "paypal-sdk/rest/set_api"
11
+ autoload :GetAPI, "paypal-sdk/rest/get_api"
12
+ autoload :ErrorHash, "paypal-sdk/rest/error_hash"
13
+
14
+ include DataTypes
15
+ include Core::Exceptions
16
+
17
+ module ClassMethods
18
+ def method_missing(name, *args)
19
+ RequestDataType.send(name, *args)
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def new(*args)
25
+ API.new(*args)
26
+ end
27
+ include ClassMethods
28
+
29
+ def included(klass)
30
+ if klass.is_a? Module
31
+ klass.extend(ClassMethods)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'paypal-sdk-core'
2
+
3
+ module PayPal
4
+ module SDK
5
+ module REST
6
+ class API < Core::API::REST
7
+ # include Services
8
+
9
+ def initialize(environment = nil, options = {})
10
+ super("", environment, options)
11
+ end
12
+
13
+ class << self
14
+ def user_agent
15
+ @user_agent ||= "PayPalSDK/rest-sdk-ruby #{VERSION} (paypal-sdk-core #{PayPal::SDK::Core::VERSION}; ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}-#{RUBY_PLATFORM})"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,420 @@
1
+ # Stub objects for REST
2
+ # Auto generated code
3
+
4
+ require 'uuidtools'
5
+
6
+ require 'paypal-sdk-core'
7
+
8
+ module PayPal::SDK
9
+ module REST
10
+ module DataTypes
11
+
12
+ class DataType < Core::API::DataTypes::Base
13
+ attr_accessor :error
14
+ attr_writer :header, :request_id
15
+
16
+ def header
17
+ @header ||= {}
18
+ end
19
+
20
+ def request_id
21
+ @request_id ||= UUIDTools::UUID.random_create.to_s
22
+ end
23
+
24
+ def http_header
25
+ { "PayPal-Request-Id" => request_id.to_s }.merge(header)
26
+ end
27
+
28
+ def success?
29
+ @error.nil?
30
+ end
31
+
32
+ def merge!(values)
33
+ @error = nil
34
+ super
35
+ end
36
+
37
+ def self.load_members
38
+ end
39
+ end
40
+
41
+ class Resource < DataType
42
+ end
43
+
44
+ class EnumType < Core::API::DataTypes::Enum
45
+ end
46
+
47
+ class Refund < Resource
48
+ def self.load_members
49
+ object_of :id, String
50
+ object_of :create_time, String
51
+ object_of :update_time, String
52
+ object_of :state, String
53
+ object_of :amount, Amount
54
+ object_of :sale_id, String
55
+ object_of :capture_id, String
56
+ object_of :parent_payment, String
57
+ object_of :description, String
58
+ array_of :links, Link
59
+ end
60
+
61
+ include RequestDataType
62
+
63
+ class << self
64
+ def find(refundid)
65
+ raise ArgumentError.new("refundid required") if refundid.to_s.strip.empty?
66
+ url = sprintf("v1/payments/refund/%s", refundid.to_s.strip)
67
+ response = api.get(url)
68
+ new(response)
69
+ end
70
+ end
71
+ end
72
+
73
+
74
+
75
+ class Resource < DataType
76
+ def self.load_members
77
+ end
78
+ end
79
+
80
+
81
+
82
+ class Amount < Resource
83
+ def self.load_members
84
+ object_of :total, String
85
+ object_of :currency, String
86
+ object_of :details, AmountDetails
87
+ end
88
+ end
89
+
90
+
91
+
92
+ class AmountDetails < Resource
93
+ def self.load_members
94
+ object_of :subtotal, String
95
+ object_of :tax, String
96
+ object_of :shipping, String
97
+ object_of :fee, String
98
+ end
99
+ end
100
+
101
+
102
+
103
+ class Link < Resource
104
+ def self.load_members
105
+ object_of :href, String
106
+ object_of :rel, String
107
+ object_of :method, String
108
+ end
109
+ end
110
+
111
+
112
+
113
+ class Payment < Resource
114
+ def self.load_members
115
+ object_of :id, String
116
+ object_of :create_time, String
117
+ object_of :update_time, String
118
+ object_of :state, String
119
+ object_of :intent, String
120
+ object_of :payer, Payer
121
+ array_of :transactions, Transaction
122
+ object_of :redirect_urls, RedirectUrls
123
+ array_of :links, Link
124
+ end
125
+
126
+ include RequestDataType
127
+
128
+ class << self
129
+ def all(options = {})
130
+ url = "v1/payments/payment"
131
+ response = api.get(url, options)
132
+ PaymentHistory.new(response)
133
+ end
134
+ end
135
+
136
+ def create()
137
+ url = "v1/payments/payment"
138
+ response = api.post(url, self.to_hash, self.http_header)
139
+ self.merge!(response)
140
+ success?
141
+ end
142
+
143
+ class << self
144
+ def find(paymentid)
145
+ raise ArgumentError.new("paymentid required") if paymentid.to_s.strip.empty?
146
+ url = sprintf("v1/payments/payment/%s", paymentid.to_s.strip)
147
+ response = api.get(url)
148
+ new(response)
149
+ end
150
+ end
151
+
152
+ def execute(payment_execution)
153
+ raise ArgumentError.new("id required") if self.id.to_s.strip.empty?
154
+ url = sprintf("v1/payments/payment/%s/execute", self.id.to_s.strip)
155
+ payment_execution = PaymentExecution.new(payment_execution) unless payment_execution.is_a? PaymentExecution
156
+ response = api.post(url, payment_execution.to_hash, payment_execution.http_header)
157
+ self.merge!(response)
158
+ success?
159
+ end
160
+ end
161
+
162
+
163
+
164
+ class Payer < Resource
165
+ def self.load_members
166
+ object_of :payment_method, String
167
+ object_of :payer_info, PayerInfo
168
+ array_of :funding_instruments, FundingInstrument
169
+ end
170
+ end
171
+
172
+
173
+
174
+ class PayerInfo < Resource
175
+ def self.load_members
176
+ object_of :email, String
177
+ object_of :first_name, String
178
+ object_of :last_name, String
179
+ object_of :payer_id, String
180
+ object_of :shipping_address, Address
181
+ object_of :phone, String
182
+ end
183
+ end
184
+
185
+
186
+
187
+ class Address < Resource
188
+ def self.load_members
189
+ object_of :line1, String
190
+ object_of :line2, String
191
+ object_of :city, String
192
+ object_of :state, String
193
+ object_of :postal_code, String
194
+ object_of :country_code, String
195
+ object_of :type, String
196
+ object_of :phone, String
197
+ end
198
+ end
199
+
200
+
201
+
202
+ class FundingInstrument < Resource
203
+ def self.load_members
204
+ object_of :credit_card, CreditCard
205
+ object_of :credit_card_token, CreditCardToken
206
+ end
207
+ end
208
+
209
+
210
+
211
+ class CreditCard < Resource
212
+ def self.load_members
213
+ object_of :id, String
214
+ object_of :valid_until, String
215
+ object_of :state, String
216
+ object_of :payer_id, String
217
+ object_of :type, String
218
+ object_of :number, String
219
+ object_of :expire_month, String
220
+ object_of :expire_year, String
221
+ object_of :cvv2, String
222
+ object_of :first_name, String
223
+ object_of :last_name, String
224
+ object_of :billing_address, Address
225
+ array_of :links, Link
226
+ end
227
+
228
+ include RequestDataType
229
+
230
+ def create()
231
+ url = "v1/vault/credit-card"
232
+ response = api.post(url, self.to_hash, self.http_header)
233
+ self.merge!(response)
234
+ success?
235
+ end
236
+
237
+ class << self
238
+ def find(creditcardid)
239
+ raise ArgumentError.new("creditcardid required") if creditcardid.to_s.strip.empty?
240
+ url = sprintf("v1/vault/credit-card/%s", creditcardid.to_s.strip)
241
+ response = api.get(url)
242
+ new(response)
243
+ end
244
+ end
245
+ end
246
+
247
+
248
+
249
+ class CreditCardToken < Resource
250
+ def self.load_members
251
+ object_of :credit_card_id, String
252
+ object_of :payer_id, String
253
+ end
254
+ end
255
+
256
+
257
+
258
+ class Transaction < Resource
259
+ def self.load_members
260
+ object_of :amount, Amount
261
+ object_of :payee, Payee
262
+ object_of :description, String
263
+ object_of :item_list, ItemList
264
+ array_of :related_resources, SubTransaction
265
+ end
266
+ end
267
+
268
+
269
+
270
+ class Payee < Resource
271
+ def self.load_members
272
+ object_of :merchant_id, String
273
+ object_of :email, String
274
+ object_of :phone, String
275
+ end
276
+ end
277
+
278
+
279
+
280
+ class ItemList < Resource
281
+ def self.load_members
282
+ array_of :items, Item
283
+ object_of :shipping_address, ShippingAddress
284
+ end
285
+ end
286
+
287
+
288
+
289
+ class Item < Resource
290
+ def self.load_members
291
+ object_of :name, String
292
+ object_of :sku, String
293
+ object_of :price, String
294
+ object_of :currency, String
295
+ object_of :quantity, String
296
+ end
297
+ end
298
+
299
+
300
+
301
+ class ShippingAddress < Address
302
+ def self.load_members
303
+ object_of :recipient_name, String
304
+ end
305
+ end
306
+
307
+
308
+
309
+ class SubTransaction < Resource
310
+ def self.load_members
311
+ object_of :sale, Sale
312
+ object_of :authorization, Authorization
313
+ object_of :refund, Refund
314
+ object_of :capture, Capture
315
+ end
316
+ end
317
+
318
+
319
+
320
+ class Sale < Resource
321
+ def self.load_members
322
+ object_of :id, String
323
+ object_of :create_time, String
324
+ object_of :update_time, String
325
+ object_of :state, String
326
+ object_of :amount, Amount
327
+ object_of :parent_payment, String
328
+ array_of :links, Link
329
+ end
330
+
331
+ include RequestDataType
332
+
333
+ class << self
334
+ def find(saleid)
335
+ raise ArgumentError.new("saleid required") if saleid.to_s.strip.empty?
336
+ url = sprintf("v1/payments/sale/%s", saleid.to_s.strip)
337
+ response = api.get(url)
338
+ new(response)
339
+ end
340
+ end
341
+
342
+ def refund(refund)
343
+ raise ArgumentError.new("id required") if self.id.to_s.strip.empty?
344
+ url = sprintf("v1/payments/sale/%s/refund", self.id.to_s.strip)
345
+ refund = Refund.new(refund) unless refund.is_a? Refund
346
+ response = api.post(url, refund.to_hash, refund.http_header)
347
+ Refund.new(response)
348
+ end
349
+ end
350
+
351
+
352
+
353
+ class Authorization < Resource
354
+ def self.load_members
355
+ object_of :id, String
356
+ object_of :create_time, String
357
+ object_of :update_time, String
358
+ object_of :state, String
359
+ object_of :amount, Amount
360
+ object_of :parent_payment, String
361
+ array_of :links, Link
362
+ end
363
+ end
364
+
365
+
366
+
367
+ class Capture < Resource
368
+ def self.load_members
369
+ object_of :id, String
370
+ object_of :create_time, String
371
+ object_of :update_time, String
372
+ object_of :state, String
373
+ object_of :amount, Amount
374
+ object_of :parent_payment, String
375
+ object_of :authorization_id, String
376
+ object_of :description, String
377
+ array_of :links, Link
378
+ end
379
+ end
380
+
381
+
382
+
383
+ class RedirectUrls < Resource
384
+ def self.load_members
385
+ object_of :return_url, String
386
+ object_of :cancel_url, String
387
+ end
388
+ end
389
+
390
+
391
+
392
+ class PaymentExecution < Resource
393
+ def self.load_members
394
+ object_of :payer_id, String
395
+ array_of :transactions, Amount
396
+ end
397
+ end
398
+
399
+
400
+
401
+ class PaymentHistory < Resource
402
+ def self.load_members
403
+ array_of :payments, Payment
404
+ object_of :count, Integer
405
+ object_of :next_id, String
406
+ end
407
+ end
408
+
409
+
410
+
411
+
412
+
413
+ constants.each do |data_type_klass|
414
+ data_type_klass = const_get(data_type_klass)
415
+ data_type_klass.load_members if defined? data_type_klass.load_members
416
+ end
417
+
418
+ end
419
+ end
420
+ end