activewepay 1.0.2 → 1.0.3
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 +8 -8
- data/lib/activewepay/version.rb +1 -1
- data/lib/activewepay.rb +82 -55
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjI3ZWM3YjBiZjUyZDFjZWRhOTlkMjNmOTk5NTk0ZmU3NTNhZmU5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjNjYmZiMGRmZDg0NjMwNzQ4ZTFjMmU0MWUxZDU2NDk2Mzg3N2NmZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmI1MzliNjIzNGJiOWYxNWZhMWQwMmNjZjViNzlmZjM3MjNjZjE4NjhmYWU0
|
10
|
+
ZjhhMzQxYTVkNTZmOWJiZTQxMzZiYjhlNzU1M2RlMzhjOTUxZjI5NDQwYzhm
|
11
|
+
Y2VhMDg4NWY1NzNiOTdjNzEzZWRjYTQyZDUxODVhYTQ5MDE5OWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Zjk2MjBkM2Q4MGQ1MjQwYjI0NDE2ZTkxYTlhZjg5YWU0ZmYzZTA4YWYyNzIz
|
14
|
+
NmM2MzI3NmY2YTJkOGE3NjA2OGM2ZTQ2YWU0M2IwODIwZmY2ODk4M2NlYzhk
|
15
|
+
MGU4YTRkMjBjMzAxY2I3ZDdkOGRiZDZkMTQwZjEyYjFlNGY2MWU=
|
data/lib/activewepay/version.rb
CHANGED
data/lib/activewepay.rb
CHANGED
@@ -5,13 +5,18 @@ require 'json'
|
|
5
5
|
require 'net/http'
|
6
6
|
require 'net/https'
|
7
7
|
require 'cgi'
|
8
|
+
require 'active_model'
|
8
9
|
|
9
10
|
module ActiveWepay
|
10
11
|
class Base
|
11
12
|
extend ActiveModel::Translation
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
extend ActiveModel::Callbacks
|
14
|
+
include ActiveModel::Validations
|
15
|
+
|
16
|
+
validate :validate_response
|
17
|
+
|
18
|
+
attr_reader :errors, :oauth_token, :id, :amount, :account_id, :redirect_uri, :callback_uri, :response
|
19
|
+
|
15
20
|
|
16
21
|
STAGE_API_ENDPOINT = "https://stage.wepayapi.com/v2"
|
17
22
|
STAGE_UI_ENDPOINT = "https://stage.wepay.com/v2"
|
@@ -19,9 +24,16 @@ module ActiveWepay
|
|
19
24
|
PRODUCTION_API_ENDPOINT = "https://wepayapi.com/v2"
|
20
25
|
PRODUCTION_UI_ENDPOINT = "https://www.wepay.com/v2"
|
21
26
|
|
22
|
-
def initialize
|
27
|
+
def initialize(options)
|
23
28
|
@errors = ActiveModel::Errors.new(self)
|
24
|
-
|
29
|
+
|
30
|
+
options[:oauth_token] ? @oauth_token = options[:oauth_token] : false
|
31
|
+
options[:amount] ? @amount = options[:amount] : false
|
32
|
+
options[:account_id] ? @account_id = options[:account_id] : false
|
33
|
+
options[:redirect_uri] ? @redirect_uri = options[:redirect_uri] : false
|
34
|
+
options[:callback_uri] ? @callback_uri = options[:callback_uri] : false
|
35
|
+
options[:id] ? @id = options[:id] : false
|
36
|
+
options[:name] ? @name = options[:name] :false
|
25
37
|
end
|
26
38
|
|
27
39
|
# make a call to the WePay API
|
@@ -53,15 +65,17 @@ module ActiveWepay
|
|
53
65
|
# returns JSON response as ruby hash
|
54
66
|
@response = JSON.parse(response.body, :symbolize_names => true)
|
55
67
|
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
def validate_response
|
56
72
|
if @response[:error]
|
57
73
|
@errors.add(@response[:error].to_sym, @response[:error_description])
|
58
74
|
end
|
59
|
-
|
60
|
-
self
|
61
75
|
end
|
62
|
-
|
76
|
+
|
63
77
|
def method_missing(method_name, *args, &block)
|
64
|
-
if @response.keys.include? method_name.to_sym
|
78
|
+
if @response and @response.keys.include? method_name.to_sym
|
65
79
|
@response[method_name.to_sym]
|
66
80
|
else
|
67
81
|
super
|
@@ -70,13 +84,15 @@ module ActiveWepay
|
|
70
84
|
end
|
71
85
|
|
72
86
|
class Account < Base
|
73
|
-
|
74
|
-
|
75
|
-
|
87
|
+
|
88
|
+
validates_presence_of :oauth_token, :name
|
89
|
+
|
90
|
+
def self.create(options)
|
91
|
+
@account = self.new(options)
|
76
92
|
|
77
93
|
theme = { name: 'Black and White', primary_color: 'FFFFFF', secondary_color: '000000', background_color: 'FFFFFF', button_color: 'FFFFFF' }
|
78
|
-
@account.call('/account/create', @account.
|
79
|
-
:name => name,
|
94
|
+
@account.call('/account/create', @account.oauth_token, {
|
95
|
+
:name => @name,
|
80
96
|
:description => 'Automatically generated by Vocalem',
|
81
97
|
:theme_object => theme
|
82
98
|
})
|
@@ -84,43 +100,50 @@ module ActiveWepay
|
|
84
100
|
end
|
85
101
|
|
86
102
|
class Checkout < Base
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
103
|
+
|
104
|
+
validates_presence_of :oauth_token
|
105
|
+
|
106
|
+
def self.create(options)
|
107
|
+
|
108
|
+
@checkout = self.new(options)
|
109
|
+
@checkout.call('/checkout/create', @checkout.oauth_token, {
|
110
|
+
account_id: @checkout.account_id,
|
111
|
+
amount: @checkout.amount,
|
93
112
|
short_description: 'Payment',
|
94
113
|
type: 'DONATION',
|
95
114
|
mode: 'iframe',
|
96
|
-
app_fee: @checkout.
|
97
|
-
redirect_uri: @checkout.
|
98
|
-
callback_uri: @checkout.
|
115
|
+
app_fee: @checkout.amount * 0.021,
|
116
|
+
redirect_uri: @checkout.redirect_uri,
|
117
|
+
callback_uri: @checkout.callback_uri
|
99
118
|
})
|
100
119
|
end
|
101
120
|
|
102
|
-
def self.find(
|
103
|
-
@checkout = self.new
|
104
|
-
@checkout.id = id
|
105
|
-
@checkout.options[:oauth_token] = oauth_token
|
121
|
+
def self.find(options)
|
122
|
+
@checkout = self.new(options)
|
106
123
|
@checkout.information
|
107
124
|
end
|
108
125
|
|
109
126
|
def information
|
110
|
-
|
127
|
+
validates_presence_of :id
|
128
|
+
|
129
|
+
call('/checkout/', @oauth_token, {
|
111
130
|
checkout_id: @id
|
112
131
|
})
|
113
132
|
end
|
114
133
|
|
115
134
|
def cancel
|
116
|
-
|
135
|
+
validates_presence_of :id
|
136
|
+
|
137
|
+
self.call('/checkout/cancel/', @oauth_token, {
|
117
138
|
checkout_id: @id,
|
118
139
|
cancel_reason: 'Refund'
|
119
140
|
})
|
120
141
|
end
|
121
142
|
|
122
143
|
def refund
|
123
|
-
|
144
|
+
validates_presence_of :id
|
145
|
+
|
146
|
+
call('/checkout/refund', @oauth_token, {
|
124
147
|
checkout_id: @id,
|
125
148
|
refund_reason: 'Refunded'
|
126
149
|
})
|
@@ -128,51 +151,55 @@ module ActiveWepay
|
|
128
151
|
end
|
129
152
|
|
130
153
|
class Preapproval < Base
|
131
|
-
|
154
|
+
|
155
|
+
validates_presence_of :oauth_token
|
132
156
|
|
133
|
-
def self.create(options
|
134
|
-
|
135
|
-
|
136
|
-
|
157
|
+
def self.create(options)
|
158
|
+
|
159
|
+
validates_presence_of :account_id, :amount, :redirect_uri, :callback_uri
|
160
|
+
|
161
|
+
@recurring = self.new(options)
|
162
|
+
@recurring.call('/preapproval/create', @recurring.oauth_token, {
|
137
163
|
short_description: 'Vocalem plan change',
|
138
|
-
account_id: @recurring.
|
139
|
-
amount: @recurring.
|
164
|
+
account_id: @recurring.account_id,
|
165
|
+
amount: @recurring.amount,
|
140
166
|
period: 'monthly',
|
141
|
-
redirect_uri: @recurring.
|
142
|
-
callback_uri: @recurring.
|
167
|
+
redirect_uri: @recurring.redirect_uri,
|
168
|
+
callback_uri: @recurring.callback_uri,
|
143
169
|
auto_recur: true,
|
144
170
|
mode: 'iframe'
|
145
|
-
|
171
|
+
})
|
146
172
|
end
|
147
173
|
|
148
|
-
def self.find(
|
149
|
-
|
150
|
-
|
151
|
-
@recurring
|
174
|
+
def self.find(options)
|
175
|
+
validates_presence_of :id
|
176
|
+
|
177
|
+
@recurring = self.new(options)
|
152
178
|
|
153
|
-
@recurring.call('/preapproval/', @recurring.
|
179
|
+
@recurring.call('/preapproval/', @recurring.oauth_token, {
|
154
180
|
preapproval_id: id
|
155
|
-
|
181
|
+
})
|
156
182
|
end
|
157
183
|
|
158
184
|
def cancel
|
159
|
-
|
160
|
-
|
185
|
+
validates_presence_of :id
|
186
|
+
|
187
|
+
call('/preapproval/cancel', @oauth_token, {
|
161
188
|
preapproval_id: @id
|
162
189
|
})
|
163
190
|
end
|
164
191
|
end
|
165
192
|
|
166
193
|
class Withdrawal < Base
|
167
|
-
attr_accessor :options, :id, :oauth_token
|
168
194
|
|
169
|
-
|
170
|
-
|
171
|
-
|
195
|
+
validates_presence_of :oauth_token, :account_id, :redirect_uri
|
196
|
+
|
197
|
+
def self.create(options)
|
198
|
+
@withdrawal = self.new(options)
|
172
199
|
|
173
|
-
@withdrawal.call('/withdrawal/create', @withdrawal.
|
174
|
-
account_id: @withdrawal.
|
175
|
-
redirect_uri: @withdrawal.
|
200
|
+
@withdrawal.call('/withdrawal/create', @withdrawal.oauth_token, {
|
201
|
+
account_id: @withdrawal.account_id,
|
202
|
+
redirect_uri: @withdrawal.redirect_uri,
|
176
203
|
mode: 'iframe'
|
177
204
|
})
|
178
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asher Cohen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|