paypal-sdk-rest 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +12 -12
- data/README.md +181 -180
- data/Rakefile +9 -9
- data/lib/paypal-sdk-rest.rb +2 -2
- data/lib/paypal-sdk/rest.rb +38 -38
- data/lib/paypal-sdk/rest/api.rb +23 -23
- data/lib/paypal-sdk/rest/data_types.rb +878 -459
- data/lib/paypal-sdk/rest/error_hash.rb +39 -39
- data/lib/paypal-sdk/rest/get_api.rb +20 -20
- data/lib/paypal-sdk/rest/request_data_type.rb +56 -56
- data/lib/paypal-sdk/rest/set_api.rb +42 -42
- data/lib/paypal-sdk/rest/version.rb +7 -7
- data/spec/config/cacert.pem +171 -171
- data/spec/config/paypal.yml +8 -8
- data/spec/invoice_examples_spec.rb +38 -0
- data/spec/log/http.log +71 -0
- data/spec/payments_examples_spec.rb +275 -272
- data/spec/spec_helper.rb +24 -24
- metadata +27 -30
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c61ab8f4993fe76ff89a4d8f3c17d55ad5297eb
|
4
|
+
data.tar.gz: d642dbb0b0af4d058541fc3aa59a4225392394fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b44a9418edc862eb7727063a561f319b838d7e9b51d172ce9596552c4431e3942d57087691fa2d743925067becf8555e775529074e776759abbd9c30fa6ce912
|
7
|
+
data.tar.gz: 48c636eff51da37d96622d51425f9410132216fa1b25e37997571b1c4df3fec15d3fa136a6da2ce42dfc117e5c4f607041ac5fe1976204d934343c54d9cc5ccc
|
data/Gemfile
CHANGED
@@ -1,12 +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
|
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
CHANGED
@@ -1,180 +1,181 @@
|
|
1
|
-
# REST SDK
|
2
|
-
|
3
|
-
The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'paypal-sdk-rest'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
```sh
|
16
|
-
$ bundle
|
17
|
-
```
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
```sh
|
22
|
-
$ gem install paypal-sdk-rest
|
23
|
-
```
|
24
|
-
|
25
|
-
## Configuration
|
26
|
-
|
27
|
-
For Rails application:
|
28
|
-
|
29
|
-
```sh
|
30
|
-
rails g paypal:sdk:install
|
31
|
-
```
|
32
|
-
|
33
|
-
For other ruby application, create a configuration file(`config/paypal.yml`):
|
34
|
-
|
35
|
-
```yaml
|
36
|
-
development: &default
|
37
|
-
mode: sandbox
|
38
|
-
client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
39
|
-
client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
40
|
-
# # with Proxy
|
41
|
-
# http_proxy: http://proxy-ipaddress:3129/
|
42
|
-
# # with CA File
|
43
|
-
# ssl_options:
|
44
|
-
# ca_file: config/cacert.pem
|
45
|
-
# # Override Endpoint
|
46
|
-
# rest_endpoint: https://api.sandbox.paypal.com
|
47
|
-
test:
|
48
|
-
<<: *default
|
49
|
-
production:
|
50
|
-
mode: live
|
51
|
-
client_id: CLIENT_ID
|
52
|
-
client_secret: CLIENT_SECRET
|
53
|
-
```
|
54
|
-
|
55
|
-
|
56
|
-
Load Configurations from specified file:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
PayPal::SDK::Core::Config.load('spec/config/paypal.yml', ENV['RACK_ENV'] || 'development')
|
60
|
-
```
|
61
|
-
|
62
|
-
Without configuration file:
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
PayPal::SDK.configure(
|
66
|
-
:mode => "sandbox", # "sandbox" or "live"
|
67
|
-
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
|
68
|
-
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
|
69
|
-
:ssl_options => { } )
|
70
|
-
```
|
71
|
-
|
72
|
-
## Create Payment
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
require 'paypal-sdk-rest'
|
76
|
-
include PayPal::SDK::REST
|
77
|
-
|
78
|
-
PayPal::SDK::REST.set_config(
|
79
|
-
:mode => "sandbox", # "sandbox" or "live"
|
80
|
-
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
|
81
|
-
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM")
|
82
|
-
|
83
|
-
# Build Payment object
|
84
|
-
@payment = Payment.new({
|
85
|
-
:intent => "sale",
|
86
|
-
:payer => {
|
87
|
-
:payment_method => "credit_card",
|
88
|
-
:funding_instruments => [{
|
89
|
-
:credit_card => {
|
90
|
-
:type => "visa",
|
91
|
-
:number => "4417119669820331",
|
92
|
-
:expire_month => "11",
|
93
|
-
:expire_year => "2018",
|
94
|
-
:cvv2 => "874",
|
95
|
-
:first_name => "Joe",
|
96
|
-
:last_name => "Shopper",
|
97
|
-
:billing_address => {
|
98
|
-
:line1 => "52 N Main ST",
|
99
|
-
:city => "Johnstown",
|
100
|
-
:state => "OH",
|
101
|
-
:postal_code => "43210",
|
102
|
-
:country_code => "US" }}}]},
|
103
|
-
:transactions => [{
|
104
|
-
:item_list => {
|
105
|
-
:items => [{
|
106
|
-
:name => "item",
|
107
|
-
:sku => "item",
|
108
|
-
:price => "1",
|
109
|
-
:currency => "USD",
|
110
|
-
:quantity => 1 }]},
|
111
|
-
:amount => {
|
112
|
-
:total => "1.00",
|
113
|
-
:currency => "USD" },
|
114
|
-
:description => "This is the payment transaction description." }]})
|
115
|
-
|
116
|
-
# Create Payment and return the status(true or false)
|
117
|
-
if @payment.create
|
118
|
-
@payment.id # Payment Id
|
119
|
-
else
|
120
|
-
@payment.error # Error Hash
|
121
|
-
end
|
122
|
-
```
|
123
|
-
|
124
|
-
## Get Payment details
|
125
|
-
|
126
|
-
```ruby
|
127
|
-
# Fetch Payment
|
128
|
-
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
|
129
|
-
|
130
|
-
# Get List of Payments
|
131
|
-
payment_history = Payment.all( :count => 10 )
|
132
|
-
payment_history.payments
|
133
|
-
```
|
134
|
-
|
135
|
-
## Execute Payment
|
136
|
-
|
137
|
-
Only for [Payment](https://github.com/paypal/rest-api-sdk-ruby/blob/master/samples/payment/create_with_paypal.rb) with `payment_method` as `"paypal"`
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
|
141
|
-
|
142
|
-
if payment.execute( :payer_id => "DUFRQ8GWYMJXC" )
|
143
|
-
# Success Message
|
144
|
-
else
|
145
|
-
payment.error # Error Hash
|
146
|
-
end
|
147
|
-
```
|
148
|
-
|
149
|
-
## OpenID Connect
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
# Update client_id, client_secret and redirect_uri
|
153
|
-
PayPal::SDK.configure({
|
154
|
-
:openid_client_id => "client_id",
|
155
|
-
:openid_client_secret => "client_secret",
|
156
|
-
:openid_redirect_uri => "http://google.com"
|
157
|
-
})
|
158
|
-
include PayPal::SDK::OpenIDConnect
|
159
|
-
|
160
|
-
# Generate authorize URL to Get Authorize code
|
161
|
-
puts Tokeninfo.authorize_url( :scope => "openid profile" )
|
162
|
-
|
163
|
-
# Create tokeninfo by using Authorize Code from redirect_uri
|
164
|
-
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
|
165
|
-
|
166
|
-
# Refresh tokeninfo object
|
167
|
-
tokeninfo.refresh
|
168
|
-
|
169
|
-
# Create tokeninfo by using refresh token
|
170
|
-
tokeninfo = Tokeninfo.refresh("Replace with refresh_token")
|
171
|
-
|
172
|
-
# Get Userinfo
|
173
|
-
userinfo = tokeninfo.userinfo
|
174
|
-
|
175
|
-
# Get Userinfo by using access token
|
176
|
-
userinfo = Userinfo.get("Replace with access_token")
|
177
|
-
|
178
|
-
# Get logout url
|
179
|
-
logout_url = tokeninfo.logout_url
|
180
|
-
```
|
1
|
+
# REST SDK
|
2
|
+
|
3
|
+
The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'paypal-sdk-rest'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
$ gem install paypal-sdk-rest
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
For Rails application:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
rails g paypal:sdk:install
|
31
|
+
```
|
32
|
+
|
33
|
+
For other ruby application, create a configuration file(`config/paypal.yml`):
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
development: &default
|
37
|
+
mode: sandbox
|
38
|
+
client_id: EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
39
|
+
client_secret: EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
40
|
+
# # with Proxy
|
41
|
+
# http_proxy: http://proxy-ipaddress:3129/
|
42
|
+
# # with CA File
|
43
|
+
# ssl_options:
|
44
|
+
# ca_file: config/cacert.pem
|
45
|
+
# # Override Endpoint
|
46
|
+
# rest_endpoint: https://api.sandbox.paypal.com
|
47
|
+
test:
|
48
|
+
<<: *default
|
49
|
+
production:
|
50
|
+
mode: live
|
51
|
+
client_id: CLIENT_ID
|
52
|
+
client_secret: CLIENT_SECRET
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
Load Configurations from specified file:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
PayPal::SDK::Core::Config.load('spec/config/paypal.yml', ENV['RACK_ENV'] || 'development')
|
60
|
+
```
|
61
|
+
|
62
|
+
Without configuration file:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
PayPal::SDK.configure(
|
66
|
+
:mode => "sandbox", # "sandbox" or "live"
|
67
|
+
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
|
68
|
+
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM",
|
69
|
+
:ssl_options => { } )
|
70
|
+
```
|
71
|
+
|
72
|
+
## Create Payment
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
require 'paypal-sdk-rest'
|
76
|
+
include PayPal::SDK::REST
|
77
|
+
|
78
|
+
PayPal::SDK::REST.set_config(
|
79
|
+
:mode => "sandbox", # "sandbox" or "live"
|
80
|
+
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
|
81
|
+
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM")
|
82
|
+
|
83
|
+
# Build Payment object
|
84
|
+
@payment = Payment.new({
|
85
|
+
:intent => "sale",
|
86
|
+
:payer => {
|
87
|
+
:payment_method => "credit_card",
|
88
|
+
:funding_instruments => [{
|
89
|
+
:credit_card => {
|
90
|
+
:type => "visa",
|
91
|
+
:number => "4417119669820331",
|
92
|
+
:expire_month => "11",
|
93
|
+
:expire_year => "2018",
|
94
|
+
:cvv2 => "874",
|
95
|
+
:first_name => "Joe",
|
96
|
+
:last_name => "Shopper",
|
97
|
+
:billing_address => {
|
98
|
+
:line1 => "52 N Main ST",
|
99
|
+
:city => "Johnstown",
|
100
|
+
:state => "OH",
|
101
|
+
:postal_code => "43210",
|
102
|
+
:country_code => "US" }}}]},
|
103
|
+
:transactions => [{
|
104
|
+
:item_list => {
|
105
|
+
:items => [{
|
106
|
+
:name => "item",
|
107
|
+
:sku => "item",
|
108
|
+
:price => "1",
|
109
|
+
:currency => "USD",
|
110
|
+
:quantity => 1 }]},
|
111
|
+
:amount => {
|
112
|
+
:total => "1.00",
|
113
|
+
:currency => "USD" },
|
114
|
+
:description => "This is the payment transaction description." }]})
|
115
|
+
|
116
|
+
# Create Payment and return the status(true or false)
|
117
|
+
if @payment.create
|
118
|
+
@payment.id # Payment Id
|
119
|
+
else
|
120
|
+
@payment.error # Error Hash
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
## Get Payment details
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
# Fetch Payment
|
128
|
+
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
|
129
|
+
|
130
|
+
# Get List of Payments
|
131
|
+
payment_history = Payment.all( :count => 10 )
|
132
|
+
payment_history.payments
|
133
|
+
```
|
134
|
+
|
135
|
+
## Execute Payment
|
136
|
+
|
137
|
+
Only for [Payment](https://github.com/paypal/rest-api-sdk-ruby/blob/master/samples/payment/create_with_paypal.rb) with `payment_method` as `"paypal"`
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
|
141
|
+
|
142
|
+
if payment.execute( :payer_id => "DUFRQ8GWYMJXC" )
|
143
|
+
# Success Message
|
144
|
+
else
|
145
|
+
payment.error # Error Hash
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
## OpenID Connect
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
# Update client_id, client_secret and redirect_uri
|
153
|
+
PayPal::SDK.configure({
|
154
|
+
:openid_client_id => "client_id",
|
155
|
+
:openid_client_secret => "client_secret",
|
156
|
+
:openid_redirect_uri => "http://google.com"
|
157
|
+
})
|
158
|
+
include PayPal::SDK::OpenIDConnect
|
159
|
+
|
160
|
+
# Generate authorize URL to Get Authorize code
|
161
|
+
puts Tokeninfo.authorize_url( :scope => "openid profile" )
|
162
|
+
|
163
|
+
# Create tokeninfo by using Authorize Code from redirect_uri
|
164
|
+
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
|
165
|
+
|
166
|
+
# Refresh tokeninfo object
|
167
|
+
tokeninfo.refresh
|
168
|
+
|
169
|
+
# Create tokeninfo by using refresh token
|
170
|
+
tokeninfo = Tokeninfo.refresh("Replace with refresh_token")
|
171
|
+
|
172
|
+
# Get Userinfo
|
173
|
+
userinfo = tokeninfo.userinfo
|
174
|
+
|
175
|
+
# Get Userinfo by using access token
|
176
|
+
userinfo = Userinfo.get("Replace with access_token")
|
177
|
+
|
178
|
+
# Get logout url
|
179
|
+
logout_url = tokeninfo.logout_url
|
180
|
+
```
|
181
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/paypal/rest-api-sdk-ruby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
3
|
-
desc "Run tests"
|
4
|
-
task :rspec do
|
5
|
-
cmd = "bundle exec rspec -f d"
|
6
|
-
system(cmd) || raise("#{cmd} failed")
|
7
|
-
end
|
8
|
-
|
9
|
-
task :default => :rspec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Run tests"
|
4
|
+
task :rspec do
|
5
|
+
cmd = "bundle exec rspec -f d"
|
6
|
+
system(cmd) || raise("#{cmd} failed")
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default => :rspec
|
data/lib/paypal-sdk-rest.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "paypal-sdk/rest"
|
2
|
-
|
1
|
+
require "paypal-sdk/rest"
|
2
|
+
|
data/lib/paypal-sdk/rest.rb
CHANGED
@@ -1,38 +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
|
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
|