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.
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,179 +1,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
- ## OpenID Connect
149
-
150
- ```ruby
151
- # Update client_id, client_secret and redirect_uri
152
- PayPal::SDK.configure({
153
- :openid_client_id => "client_id",
154
- :openid_client_secret => "client_secret",
155
- :openid_redirect_uri => "http://google.com"
156
- })
157
- include PayPal::SDK::OpenIDConnect
158
-
159
- # Generate authorize URL to Get Authorize code
160
- puts Tokeninfo.authorize_url( :scope => "openid profile" )
161
-
162
- # Create tokeninfo by using Authorize Code from redirect_uri
163
- tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
164
-
165
- # Refresh tokeninfo object
166
- tokeninfo.refresh
167
-
168
- # Create tokeninfo by using refresh token
169
- tokeninfo = Tokeninfo.refresh("Replace with refresh_token")
170
-
171
- # Get Userinfo
172
- userinfo = tokeninfo.userinfo
173
-
174
- # Get Userinfo by using access token
175
- userinfo = Userinfo.get("Replace with access_token")
176
-
177
- # Get logout url
178
- put tokeninfo.logout_url
179
- ```
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
+ ```
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
@@ -1,23 +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} (#{sdk_library_details})"
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
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} (#{sdk_library_details})"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+