activewepay 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activewepay.rb +42 -51
- data/lib/activewepay/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f68d55d385d5dd9e010b81dd7c358b9ea80e9ea1
|
4
|
+
data.tar.gz: 9189370a7c07c48269b75214540131a1e204d11d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e13dff3fc5f48c8a3cdc20a30f1d9335a4060106f5795154c7b23abc5820943288c69fdd70c1f115702520a96a5ade9a8bb34582a4e0f8786f83b97f905bb09
|
7
|
+
data.tar.gz: 9db4070c3c851be4ea86165086d1fb9675ce5000b91034e467ed895fb08eaebeddaf2196480fe6c3a8a327e285e13772c496b49bcf878ea12c233b96634e70c5
|
data/lib/activewepay.rb
CHANGED
@@ -9,19 +9,18 @@ require 'active_model'
|
|
9
9
|
|
10
10
|
module ActiveWepay
|
11
11
|
class Base
|
12
|
-
extend ActiveModel::Model
|
13
12
|
include ActiveModel::Model
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
attr_reader :errors, :oauth_token, :id, :amount, :redirect_uri, :callback_uri, :response, :name
|
14
|
+
attr_accessor :oauth_token
|
15
|
+
attr_reader :errors, :id, :amount, :redirect_uri, :callback_uri, :response, :name
|
18
16
|
|
19
|
-
|
20
17
|
STAGE_API_ENDPOINT = "https://stage.wepayapi.com/v2"
|
21
18
|
STAGE_UI_ENDPOINT = "https://stage.wepay.com/v2"
|
22
19
|
|
23
20
|
PRODUCTION_API_ENDPOINT = "https://wepayapi.com/v2"
|
24
21
|
PRODUCTION_UI_ENDPOINT = "https://www.wepay.com/v2"
|
22
|
+
|
23
|
+
validate :validate_response
|
25
24
|
|
26
25
|
def initialize(options)
|
27
26
|
@errors = ActiveModel::Errors.new(self)
|
@@ -37,49 +36,42 @@ module ActiveWepay
|
|
37
36
|
end
|
38
37
|
|
39
38
|
# make a call to the WePay API
|
40
|
-
def call(
|
41
|
-
if Rails.env == 'development'
|
42
|
-
|
43
|
-
|
39
|
+
def call(path, access_token = false, params = false)
|
40
|
+
if Rails.env == 'development' || Rails.env == 'test'
|
41
|
+
api_endpoint = STAGE_API_ENDPOINT
|
42
|
+
ui_endpoint = STAGE_UI_ENDPOINT
|
44
43
|
else
|
45
|
-
|
46
|
-
|
44
|
+
api_endpoint = PRODUCTION_API_ENDPOINT
|
45
|
+
ui_endpoint = PRODUCTION_UI_ENDPOINT
|
47
46
|
end
|
48
47
|
|
49
48
|
# get the url
|
50
|
-
url = URI.parse(
|
51
|
-
p url
|
49
|
+
url = URI.parse(api_endpoint + path)
|
52
50
|
# construct the call data and access token
|
53
51
|
call = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json', 'User-Agent' => 'WePay Ruby SDK'})
|
54
52
|
if params
|
55
53
|
call.body = params.to_json
|
56
54
|
end
|
55
|
+
|
57
56
|
if access_token
|
58
|
-
call.add_field('Authorization: Bearer', access_token)
|
57
|
+
call.add_field('Authorization: Bearer', access_token)
|
59
58
|
end
|
59
|
+
|
60
60
|
# create the request object
|
61
61
|
request = Net::HTTP.new(url.host, url.port)
|
62
62
|
request.use_ssl = true
|
63
63
|
# make the call
|
64
64
|
response = request.start {|http| http.request(call) }
|
65
65
|
# returns JSON response as ruby hash
|
66
|
-
@response = JSON.parse(response.body, :symbolize_names => true)
|
66
|
+
@response = JSON.parse!(response.body, :symbolize_names => true)
|
67
67
|
|
68
|
-
set_instance_variables(response)
|
69
|
-
|
70
68
|
self
|
71
69
|
end
|
72
70
|
|
73
71
|
private
|
74
|
-
|
75
|
-
def set_instance_variables(hash)
|
76
|
-
hash.each do |key, value|
|
77
|
-
instance_variable_set "@#{key}".to_sym, value rescue false
|
78
|
-
end
|
79
|
-
end
|
80
72
|
|
81
73
|
def validate_response
|
82
|
-
if @response[:error]
|
74
|
+
if @response && @response[:error]
|
83
75
|
@errors.add(@response[:error].to_sym, @response[:error_description])
|
84
76
|
end
|
85
77
|
end
|
@@ -100,11 +92,11 @@ module ActiveWepay
|
|
100
92
|
validates_presence_of :oauth_token
|
101
93
|
|
102
94
|
def self.create(options)
|
103
|
-
|
95
|
+
account = self.new(options)
|
104
96
|
|
105
97
|
theme = { name: 'Black and White', primary_color: 'FFFFFF', secondary_color: '000000', background_color: 'FFFFFF', button_color: 'FFFFFF' }
|
106
|
-
|
107
|
-
:name =>
|
98
|
+
account.call('/account/create', account.oauth_token, {
|
99
|
+
:name => account.name,
|
108
100
|
:description => 'Automatically generated by Vocalem',
|
109
101
|
:theme_object => theme
|
110
102
|
})
|
@@ -116,25 +108,24 @@ module ActiveWepay
|
|
116
108
|
validates_presence_of :oauth_token
|
117
109
|
|
118
110
|
def self.create(options)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
amount: @checkout.amount,
|
111
|
+
checkout = self.new(options)
|
112
|
+
checkout.call('/checkout/create', checkout.oauth_token, {
|
113
|
+
account_id: checkout.account_id,
|
114
|
+
amount: checkout.amount,
|
124
115
|
short_description: 'Payment',
|
125
116
|
type: 'DONATION',
|
126
117
|
mode: 'iframe',
|
127
|
-
app_fee:
|
128
|
-
redirect_uri:
|
129
|
-
callback_uri:
|
118
|
+
app_fee: checkout.amount * 0.021,
|
119
|
+
redirect_uri: checkout.redirect_uri,
|
120
|
+
callback_uri: checkout.callback_uri
|
130
121
|
})
|
131
122
|
end
|
132
123
|
|
133
124
|
def self.find(options)
|
134
|
-
|
135
|
-
|
125
|
+
checkout = self.new(options)
|
126
|
+
checkout.information
|
136
127
|
end
|
137
|
-
|
128
|
+
|
138
129
|
def information
|
139
130
|
validates_presence_of :id
|
140
131
|
|
@@ -170,14 +161,14 @@ module ActiveWepay
|
|
170
161
|
|
171
162
|
validates_presence_of :account_id, :amount, :redirect_uri, :callback_uri
|
172
163
|
|
173
|
-
|
174
|
-
|
164
|
+
recurring = self.new(options)
|
165
|
+
recurring.call('/preapproval/create', recurring.oauth_token, {
|
175
166
|
short_description: 'Vocalem plan change',
|
176
|
-
account_id:
|
177
|
-
amount:
|
167
|
+
account_id: recurring.account_id,
|
168
|
+
amount: recurring.amount,
|
178
169
|
period: 'monthly',
|
179
|
-
redirect_uri:
|
180
|
-
callback_uri:
|
170
|
+
redirect_uri: recurring.redirect_uri,
|
171
|
+
callback_uri: recurring.callback_uri,
|
181
172
|
auto_recur: true,
|
182
173
|
mode: 'iframe'
|
183
174
|
})
|
@@ -186,10 +177,10 @@ module ActiveWepay
|
|
186
177
|
def self.find(options)
|
187
178
|
validates_presence_of :id
|
188
179
|
|
189
|
-
|
180
|
+
recurring = self.new(options)
|
190
181
|
|
191
|
-
|
192
|
-
preapproval_id:
|
182
|
+
recurring.call('/preapproval/', recurring.oauth_token, {
|
183
|
+
preapproval_id: recurring.id
|
193
184
|
})
|
194
185
|
end
|
195
186
|
|
@@ -207,11 +198,11 @@ module ActiveWepay
|
|
207
198
|
validates_presence_of :oauth_token, :account_id, :redirect_uri
|
208
199
|
|
209
200
|
def self.create(options)
|
210
|
-
|
201
|
+
withdrawal = self.new(options)
|
211
202
|
|
212
|
-
|
213
|
-
account_id:
|
214
|
-
redirect_uri:
|
203
|
+
withdrawal.call('/withdrawal/create', withdrawal.oauth_token, {
|
204
|
+
account_id: withdrawal.account_id,
|
205
|
+
redirect_uri: withdrawal.redirect_uri,
|
215
206
|
mode: 'iframe'
|
216
207
|
})
|
217
208
|
end
|
data/lib/activewepay/version.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activewepay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asher Cohen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: ActiveModel style WePay interface.
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -77,18 +77,18 @@ require_paths:
|
|
77
77
|
- lib
|
78
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.2.0
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
|
-
summary:
|
93
|
+
summary: "{ActiveModel style WePay interface.}"
|
94
94
|
test_files: []
|