activewepay 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/activewepay.gemspec +23 -0
- data/lib/activewepay/version.rb +3 -0
- data/lib/activewepay.rb +178 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDU2ODM4OGMyYWMxMWJkODBiYTQzMmIzYWEwOWE1YzA0ZGU4NTE4OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGJlYzI0MjRlOWYxZmVlMDFkZDhiMzQ3OWE4YzBhOTdiMmNiODQzZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWYyOTkyMThkMTRiZGEzYjMxN2QwMDRiZTdlMjdiYmU0YzA5YzZmNWU4Yjc2
|
10
|
+
ZTcxZDdmM2NlZTgwM2FlNTIxYmMyNDM2ZjcxMGE0NDFmOTA0OGQ4M2EwNTIx
|
11
|
+
NjkzOTg0OTA1YTE0YWVhODhlOWUzOTNjMDAyNGQyMDE1NDljY2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Yzk2MmQ3MWMzMTczYzVkNjBkMDZlNjRlNTUwY2ViN2UxYTczZDljYmM3MGVh
|
14
|
+
YmU4NTgyMGUyMWM0ZDk1MTBlMjRkNTRhZmE5ZjQ5MTA1NGVlZWFjNjhkNjFi
|
15
|
+
NjQxOTU5YjBmNzMzZTkwMmE2YjkxNzc1YThmNTVkMjZjMDk3YTQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Asher Cohen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Activewepay
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'activewepay'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install activewepay
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/activewepay.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activewepay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activewepay"
|
8
|
+
spec.version = Activewepay::VERSION
|
9
|
+
spec.authors = ["Asher Cohen"]
|
10
|
+
spec.email = ["asherlc@asherlc.com"]
|
11
|
+
spec.description = %q{ActiveModel style WePay interface.}
|
12
|
+
spec.summary = %q{{ActiveModel style WePay interface.}}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/activewepay.rb
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
require "activewepay/version"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
require 'net/https'
|
7
|
+
require 'cgi'
|
8
|
+
|
9
|
+
module ActiveWepay
|
10
|
+
class Base
|
11
|
+
extend ActiveModel::Translation
|
12
|
+
|
13
|
+
attr_accessor :options, :id, :oauth_token
|
14
|
+
attr_reader :response, :errors
|
15
|
+
|
16
|
+
STAGE_API_ENDPOINT = "https://stage.wepayapi.com/v2"
|
17
|
+
STAGE_UI_ENDPOINT = "https://stage.wepay.com/v2"
|
18
|
+
|
19
|
+
PRODUCTION_API_ENDPOINT = "https://wepayapi.com/v2"
|
20
|
+
PRODUCTION_UI_ENDPOINT = "https://www.wepay.com/v2"
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@errors = ActiveModel::Errors.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
# make a call to the WePay API
|
27
|
+
def call(call, access_token = false, params = false)
|
28
|
+
if Rails.env == 'development'
|
29
|
+
@api_endpoint = STAGE_API_ENDPOINT
|
30
|
+
@ui_endpoint = STAGE_UI_ENDPOINT
|
31
|
+
else
|
32
|
+
@api_endpoint = PRODUCTION_API_ENDPOINT
|
33
|
+
@ui_endpoint = PRODUCTION_UI_ENDPOINT
|
34
|
+
end
|
35
|
+
|
36
|
+
# get the url
|
37
|
+
url = URI.parse(@api_endpoint + call)
|
38
|
+
p url
|
39
|
+
# construct the call data and access token
|
40
|
+
call = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json', 'User-Agent' => 'WePay Ruby SDK'})
|
41
|
+
if params
|
42
|
+
call.body = params.to_json
|
43
|
+
end
|
44
|
+
if access_token
|
45
|
+
call.add_field('Authorization: Bearer', access_token);
|
46
|
+
end
|
47
|
+
# create the request object
|
48
|
+
request = Net::HTTP.new(url.host, url.port)
|
49
|
+
request.use_ssl = true
|
50
|
+
# make the call
|
51
|
+
response = request.start {|http| http.request(call) }
|
52
|
+
# returns JSON response as ruby hash
|
53
|
+
@response = JSON.parse(response.body, :symbolize_names => true)
|
54
|
+
|
55
|
+
if @response[:error]
|
56
|
+
@errors.add(@response[:error].to_sym, @response[:error_description])
|
57
|
+
end
|
58
|
+
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(method_name, *args, &block)
|
63
|
+
if @response.keys.include? method_name.to_sym
|
64
|
+
@response[method_name.to_sym]
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Account < Base
|
72
|
+
def self.create(oauth_token, name)
|
73
|
+
@account = self.new
|
74
|
+
theme = { name: 'Black and White', primary_color: 'FFFFFF', secondary_color: '000000', background_color: 'FFFFFF', button_color: 'FFFFFF' }
|
75
|
+
@account.call('/account/create', oauth_token, {
|
76
|
+
:name => name,
|
77
|
+
:description => 'Automatically generated by Vocalem',
|
78
|
+
:theme_object => theme
|
79
|
+
})
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Checkout < Base
|
84
|
+
def self.create(oauth_token, options = {})
|
85
|
+
@checkout = self.new
|
86
|
+
@checkout.oauth_token = oauth_token
|
87
|
+
@checkout.options = options
|
88
|
+
@checkout.call('/checkout/create', oauth_token, {
|
89
|
+
account_id: options[:organization].wepay_account_id,
|
90
|
+
amount: options[:amount],
|
91
|
+
short_description: 'Payment',
|
92
|
+
type: 'DONATION',
|
93
|
+
mode: 'iframe',
|
94
|
+
app_fee: options[:amount] * 0.021,
|
95
|
+
redirect_uri: options[:redirect_uri],
|
96
|
+
callback_uri: options[:callback_uri]
|
97
|
+
})
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.find(id, oauth_token)
|
101
|
+
@checkout = self.new
|
102
|
+
@checkout.id = id
|
103
|
+
@checkout.oauth_token = oauth_token
|
104
|
+
@checkout.information
|
105
|
+
end
|
106
|
+
|
107
|
+
def information
|
108
|
+
call('/checkout/', @oauth_token, {
|
109
|
+
checkout_id: @id
|
110
|
+
})
|
111
|
+
end
|
112
|
+
|
113
|
+
def cancel
|
114
|
+
self.call('/checkout/cancel/', @oauth_token, {
|
115
|
+
checkout_id: @id,
|
116
|
+
cancel_reason: 'Refund'
|
117
|
+
})
|
118
|
+
end
|
119
|
+
|
120
|
+
def refund
|
121
|
+
call('/checkout/refund', @oauth_token, {
|
122
|
+
checkout_id: @id,
|
123
|
+
refund_reason: 'Refunded'
|
124
|
+
})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class Preapproval < Base
|
129
|
+
attr_accessor :options, :id
|
130
|
+
|
131
|
+
def self.create(options)
|
132
|
+
@recurring = self.new
|
133
|
+
@recurring.options = options
|
134
|
+
@recurring.call('/preapproval/create', ENV['WEPAY_ACCESS_TOKEN'], {
|
135
|
+
short_description: 'Vocalem plan change',
|
136
|
+
account_id: ENV['WEPAY_ACCOUNT_ID'],
|
137
|
+
amount: options[:amount],
|
138
|
+
period: 'monthly',
|
139
|
+
redirect_uri: options[:redirect_uri],
|
140
|
+
callback_uri: options[:callback_uri],
|
141
|
+
auto_recur: true,
|
142
|
+
mode: 'iframe'
|
143
|
+
})
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.find(id)
|
147
|
+
@recurring = self.new
|
148
|
+
@recurring.id = id
|
149
|
+
|
150
|
+
@recurring.call('/preapproval/', ENV['WEPAY_ACCESS_TOKEN'], {
|
151
|
+
preapproval_id: id
|
152
|
+
})
|
153
|
+
end
|
154
|
+
|
155
|
+
def cancel
|
156
|
+
|
157
|
+
call('/preapproval/cancel', ENV['WEPAY_ACCESS_TOKEN'], {
|
158
|
+
preapproval_id: @id
|
159
|
+
})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class Withdrawal < Base
|
164
|
+
attr_accessor :options, :id, :oauth_token
|
165
|
+
|
166
|
+
def self.create(oauth_token, options)
|
167
|
+
@withdrawal = self.new
|
168
|
+
@withdrawal.options = options
|
169
|
+
@withdrawal.oauth_token = oauth_token
|
170
|
+
|
171
|
+
@withdrawal.call('/withdrawal/create', oauth_token, {
|
172
|
+
account_id: options[:organization].wepay_account_id,
|
173
|
+
redirect_uri: options[:redirect_uri],
|
174
|
+
mode: 'iframe'
|
175
|
+
})
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activewepay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Asher Cohen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ActiveModel style WePay interface.
|
42
|
+
email:
|
43
|
+
- asherlc@asherlc.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- activewepay.gemspec
|
54
|
+
- lib/activewepay.rb
|
55
|
+
- lib/activewepay/version.rb
|
56
|
+
homepage: ''
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: ! '{ActiveModel style WePay interface.}'
|
80
|
+
test_files: []
|