astro_pay 0.0.1
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 +7 -0
- data/.gitignore +23 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/astro_pay.gemspec +28 -0
- data/lib/astro_pay/card.rb +197 -0
- data/lib/astro_pay/configuration.rb +18 -0
- data/lib/astro_pay/curl.rb +27 -0
- data/lib/astro_pay/direct.rb +107 -0
- data/lib/astro_pay/model.rb +27 -0
- data/lib/astro_pay/version.rb +3 -0
- data/lib/astro_pay.rb +69 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3380119adb5f9477cd644676f0449761c51b6c6b
|
4
|
+
data.tar.gz: 7ce4a5ee5c6a03aa912ba58c948f1d84783500c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a4826d178e62ce4c2d9d9d390db1d9a043c89c1e22e643cb864a030aa7a60a7174335c90b6dc5d983ba8db75fa9452c9b9f255088cf86818b77a36e674b1c59
|
7
|
+
data.tar.gz: 8953f9d2e80fae289ebbe577036c4ecf76ea6c22d1e7ee91b8ba52c2c344cb250cfcd4878ed0751f82388e886fcb32ba5a7d11bf0984d3d1399945a79cb0bf20
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Luis Galaviz
|
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
|
+
# AstroPay
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'astro_pay'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install astro_pay
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/astro_pay/fork )
|
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 a new Pull Request
|
data/Rakefile
ADDED
data/astro_pay.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'astro_pay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "astro_pay"
|
8
|
+
spec.version = AstroPay::VERSION
|
9
|
+
spec.authors = ["Luis Galaviz"]
|
10
|
+
spec.email = ["galaviz.lm@gmail.com"]
|
11
|
+
spec.summary = %q{Simple API connection to AstroPay.}
|
12
|
+
spec.description = %q{Allows you to connect to AstroPay Direct/Card API.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency('activemodel', ['>= 4.1'])
|
27
|
+
spec.add_runtime_dependency('activesupport', ['>= 4.1'])
|
28
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
=begin
|
2
|
+
Class of AstroPay Card
|
3
|
+
|
4
|
+
@author Luis Galaviz (galaviz.lm@gmail.com)
|
5
|
+
=end
|
6
|
+
|
7
|
+
module AstroPay
|
8
|
+
class Card < AstroPay::Model
|
9
|
+
|
10
|
+
# Input params
|
11
|
+
attr_accessor :approval_code, :number, :ccv, :exp_date
|
12
|
+
attr_accessor :amount, :unique_id, :invoice_num, :transaction_id
|
13
|
+
attr_accessor :additional_params, :type
|
14
|
+
|
15
|
+
def initialize(args={})
|
16
|
+
config = AstroPay.configuration
|
17
|
+
|
18
|
+
@x_login = config.card_x_login
|
19
|
+
@x_trans_key = config.card_x_trans_key
|
20
|
+
@sandbox = config.sandbox
|
21
|
+
|
22
|
+
base_url = "https://#{'sandbox-' if @sandbox}api.astropaycard.com/"
|
23
|
+
|
24
|
+
@x_version = "2.0" #AstroPay API version (default "2.0")
|
25
|
+
@x_delim_char = "|" #Field delimit character, the character that separates the fields (default "|")
|
26
|
+
@x_test_request = 'N' #Change to N for production
|
27
|
+
@x_duplicate_window = 30 #Time window of a transaction with the sames values is taken as duplicated (default 120)
|
28
|
+
@x_method = "CC"
|
29
|
+
@x_response_format = "json" #Response format: "string", "json", "xml" (default: string) (recommended: json)
|
30
|
+
|
31
|
+
@additional_params = Hash.new
|
32
|
+
|
33
|
+
super
|
34
|
+
|
35
|
+
@validator_url = "#{base_url}verif/validator"
|
36
|
+
@transtatus_url = "#{base_url}verif/transtatus"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Authorizes a transaction
|
40
|
+
#
|
41
|
+
# number AstroPay Card number (16 digits)
|
42
|
+
# ccv AstroPay Card security code (CVV)
|
43
|
+
# exp_date AstroPay Card expiration date
|
44
|
+
# amount Amount of the transaction
|
45
|
+
# unique_id Unique user ID of the merchant
|
46
|
+
# invoice_num Merchant transaction identificator, i.e. the order number
|
47
|
+
# additional_params Array of additional info that you would send to AstroPay for reference purpose.
|
48
|
+
# return json of params returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
|
49
|
+
def auth_transaction
|
50
|
+
data = full_params.merge(
|
51
|
+
'x_unique_id' => unique_id,
|
52
|
+
'x_invoice_num' => invoice_num,
|
53
|
+
'x_type' => "AUTH_ONLY"
|
54
|
+
)
|
55
|
+
|
56
|
+
astro_curl(@validator_url, data)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Caputures previous authorized transaction
|
60
|
+
#
|
61
|
+
# auth_code The x_auth_code returned by auth_transaction method
|
62
|
+
# number AstroPay Card number (16 digits)
|
63
|
+
# ccv AstroPay Card security code (CVV)
|
64
|
+
# exp_date AstroPay Card expiration date
|
65
|
+
# amount Amount of the transaction
|
66
|
+
# unique_id Unique user ID of the merchant
|
67
|
+
# invoice_num Merchant transaction identificator, i.e. the order number
|
68
|
+
# additional_params Array of additional info that you would send to AstroPay for reference purpose.
|
69
|
+
# return json returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
|
70
|
+
def capture_transaction
|
71
|
+
data = full_params.merge(
|
72
|
+
'x_unique_id' => unique_id,
|
73
|
+
'x_invoice_num' => invoice_num,
|
74
|
+
'x_auth_code' => approval_code,
|
75
|
+
'x_type' => "CAPTURE_ONLY"
|
76
|
+
)
|
77
|
+
|
78
|
+
astro_curl(@validator_url, data)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Authorize and capture a transaction at the same time (if it is possible)
|
82
|
+
#
|
83
|
+
# number AstroPay Card number (16 digits)
|
84
|
+
# ccv AstroPay Card security code (CVV)
|
85
|
+
# exp_date AstroPay Card expiration date
|
86
|
+
# amount Amount of the transaction
|
87
|
+
# unique_id Unique user ID of the merchant
|
88
|
+
# invoice_num Merchant transaction identificator, i.e. the order number
|
89
|
+
# additional_params Array of additional info that you would send to AstroPay for reference purpose.
|
90
|
+
# return json returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
|
91
|
+
def auth_capture_transaction
|
92
|
+
data = full_params.merge(
|
93
|
+
'x_unique_id' => unique_id,
|
94
|
+
'x_invoice_num' => invoice_num,
|
95
|
+
'x_type' => "AUTH_CAPTURE"
|
96
|
+
)
|
97
|
+
|
98
|
+
astro_curl(@validator_url, data)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Refund a transaction
|
102
|
+
#
|
103
|
+
# transaction_id merchant invoice number sent in previus call of capture_transaction or auth_transaction
|
104
|
+
# number AstroPay Card number (16 digits)
|
105
|
+
# ccv AstroPay Card security code (CVV)
|
106
|
+
# exp_date AstroPay Card expiration date
|
107
|
+
# amount Amount of the transaction
|
108
|
+
# additional_params Array of additional info that you would send to AstroPay for reference purpose.
|
109
|
+
# return json returned by AstroPay capture API. Please see section 3.2.2 "Response" of AstroPay Card integration manual for more info
|
110
|
+
def refund_transaction
|
111
|
+
data = full_params.merge(
|
112
|
+
'x_trans_id' => transaction_id,
|
113
|
+
'x_type' => "REFUND"
|
114
|
+
)
|
115
|
+
|
116
|
+
astro_curl(@validator_url, data)
|
117
|
+
end
|
118
|
+
|
119
|
+
# VOID a transaction
|
120
|
+
#
|
121
|
+
# transaction_id merchant invoice number sent in previus call of capture_transaction or auth_transaction
|
122
|
+
# number AstroPay Card number (16 digits)
|
123
|
+
# ccv AstroPay Card security code (CVV)
|
124
|
+
# exp_date AstroPay Card expiration date
|
125
|
+
# amount Amount of the transaction
|
126
|
+
# additional_params Array of additional info that you would send to AstroPay for reference purpose.
|
127
|
+
# return json returned by AstroPay capture API. Please see section 3.2.2 "Response" of AstroPay Card integration manual for more info
|
128
|
+
def void_transaction
|
129
|
+
data = full_params.merge(
|
130
|
+
'x_trans_id' => transaction_id,
|
131
|
+
'x_type' => "VOID"
|
132
|
+
)
|
133
|
+
|
134
|
+
astro_curl(@validator_url, data)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Checks the status of a transaction
|
138
|
+
#
|
139
|
+
# invoice_num The merchant id sent in the transaction
|
140
|
+
# type 0 for basic info, 1 for detailed info
|
141
|
+
# return json. Please see section 3.2.3 of APC integration manual from more details.
|
142
|
+
def check_transaction_status
|
143
|
+
data = basic_credentials.merge(
|
144
|
+
'x_trans_key' => @x_trans_key,
|
145
|
+
'x_invoice_num' => invoice_num,
|
146
|
+
'x_type' => (type || 0)
|
147
|
+
)
|
148
|
+
|
149
|
+
astro_curl(@transtatus_url, data)
|
150
|
+
end
|
151
|
+
|
152
|
+
def astro_curl(url, params_hash)
|
153
|
+
AstroPay::Curl.post(url, params_hash)
|
154
|
+
end
|
155
|
+
|
156
|
+
def calculate_control(transaction_id, amount)
|
157
|
+
Digest::MD5.hexdigest("#{@x_login}#{transaction_id}#{amount}");
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def basic_credentials
|
163
|
+
{
|
164
|
+
'x_login' => @x_login,
|
165
|
+
'x_tran_key' => @x_trans_key,
|
166
|
+
'x_delim_char' => @x_delim_char,
|
167
|
+
'x_test_request' => @x_test_request,
|
168
|
+
'x_response_format' => @x_response_format
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
def full_credentials
|
173
|
+
basic_credentials.merge(
|
174
|
+
'x_method' => @x_method,
|
175
|
+
'x_version' => @x_version,
|
176
|
+
'x_duplicate_window' => @x_duplicate_window
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
def basic_variables
|
181
|
+
{
|
182
|
+
'x_card_num' => number,
|
183
|
+
'x_card_code' => ccv,
|
184
|
+
'x_exp_date' => exp_date,
|
185
|
+
'x_amount' => amount
|
186
|
+
}
|
187
|
+
end
|
188
|
+
|
189
|
+
def full_params
|
190
|
+
full_credentials.merge(
|
191
|
+
additional_params
|
192
|
+
).merge(
|
193
|
+
basic_variables
|
194
|
+
)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AstroPay
|
2
|
+
class Configuration
|
3
|
+
#AstroPay Direct required attributes
|
4
|
+
attr_accessor :direct_x_login, :direct_x_trans_key, :direct_x_login_for_webpaystatus
|
5
|
+
attr_accessor :direct_x_trans_key_for_webpaystatus, :direct_secret_key
|
6
|
+
|
7
|
+
#AstroPay Direct required attributes
|
8
|
+
attr_accessor :card_x_login, :card_x_trans_key
|
9
|
+
|
10
|
+
#Optional attributes
|
11
|
+
attr_accessor :sandbox, :enable_ssl
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@sandbox = true
|
15
|
+
@enable_ssl = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AstroPay
|
2
|
+
class Curl
|
3
|
+
def self.enable_ssl
|
4
|
+
AstroPay.configuration.enable_ssl
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.post(url, params_hash)
|
8
|
+
uri = URI.parse(url)
|
9
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
10
|
+
|
11
|
+
unless enable_ssl
|
12
|
+
http.use_ssl = true
|
13
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
14
|
+
end
|
15
|
+
|
16
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
17
|
+
request.set_form_data(params_hash)
|
18
|
+
response = http.request(request)
|
19
|
+
|
20
|
+
begin
|
21
|
+
JSON.parse(response.body)
|
22
|
+
rescue
|
23
|
+
response.body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
=begin
|
2
|
+
Class of AstroPay Direct
|
3
|
+
|
4
|
+
@author Luis Galaviz (galaviz.lm@gmail.com)
|
5
|
+
=end
|
6
|
+
|
7
|
+
module AstroPay
|
8
|
+
class Direct < AstroPay::Model
|
9
|
+
|
10
|
+
# Input params
|
11
|
+
attr_accessor :invoice, :amount, :iduser, :bank, :country, :currency
|
12
|
+
attr_accessor :description, :cpf, :sub_code, :return_url, :confirmation_url
|
13
|
+
attr_accessor :response_type
|
14
|
+
|
15
|
+
def initialize(args={})
|
16
|
+
config = AstroPay.configuration
|
17
|
+
|
18
|
+
@x_login = config.direct_x_login
|
19
|
+
@x_trans_key = config.direct_x_trans_key
|
20
|
+
@x_login_for_webpaystatus = config.direct_x_login_for_webpaystatus
|
21
|
+
@x_trans_key_for_webpaystatus = config.direct_x_trans_key_for_webpaystatus
|
22
|
+
@secret_key = config.direct_secret_key
|
23
|
+
@sandbox = config.sandbox
|
24
|
+
@response_type = 'json'
|
25
|
+
|
26
|
+
super
|
27
|
+
|
28
|
+
subdomain = 'sandbox.' if @sandbox
|
29
|
+
|
30
|
+
@astro_urls = {
|
31
|
+
"create" => "https://#{subdomain}astropaycard.com/api_curl/apd/create",
|
32
|
+
"status" => "https://#{subdomain}astropaycard.com/apd/webpaystatus",
|
33
|
+
"exchange" => "https://#{subdomain}astropaycard.com/apd/webcurrencyexchange",
|
34
|
+
"banks" => "https://#{subdomain}astropaycard.com/api_curl/apd/get_banks_by_country"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def create
|
39
|
+
params_hash = {
|
40
|
+
'x_login' => @x_login,
|
41
|
+
'x_trans_key' => @x_trans_key,
|
42
|
+
'x_invoice' => invoice,
|
43
|
+
'x_amount' => amount,
|
44
|
+
'x_iduser' => iduser,
|
45
|
+
'x_bank' => bank,
|
46
|
+
'x_country' => country,
|
47
|
+
'x_sub_code' => sub_code,
|
48
|
+
'type' => response_type
|
49
|
+
}
|
50
|
+
|
51
|
+
message_to_control = "#{invoice}D#{amount}P#{iduser}A"
|
52
|
+
|
53
|
+
sha256 = OpenSSL::Digest::SHA256.new
|
54
|
+
control = OpenSSL::HMAC.hexdigest(sha256, [@secret_key].pack('A*'), [message_to_control].pack('A*'))
|
55
|
+
control = control.upcase
|
56
|
+
|
57
|
+
params_hash['control'] = control
|
58
|
+
params_hash['x_currency'] = currency if currency
|
59
|
+
params_hash['x_description'] = description if description
|
60
|
+
params_hash['x_cpf'] = cpf if cpf
|
61
|
+
params_hash['x_return'] = return_url if return_url
|
62
|
+
params_hash['x_confirmation'] = confirmation_url if confirmation_url
|
63
|
+
|
64
|
+
astro_curl(@astro_urls['create'], params_hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_banks_by_country
|
68
|
+
params_hash = {
|
69
|
+
#Mandatory
|
70
|
+
'x_login' => @x_login,
|
71
|
+
'x_trans_key' => @x_trans_key,
|
72
|
+
'country_code' => country,
|
73
|
+
'type' => response_type
|
74
|
+
}
|
75
|
+
|
76
|
+
astro_curl(@astro_urls['banks'], params_hash)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_invoice_status
|
80
|
+
params_hash = {
|
81
|
+
#Mandatory
|
82
|
+
'x_login' => @x_login_for_webpaystatus,
|
83
|
+
'x_trans_key' => @x_trans_key_for_webpaystatus,
|
84
|
+
'x_invoice' => invoice,
|
85
|
+
'x_response_format' => response_type
|
86
|
+
}
|
87
|
+
|
88
|
+
astro_curl(@astro_urls['status'], params_hash)
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_exchange
|
92
|
+
params_hash = {
|
93
|
+
#Mandatory
|
94
|
+
'x_login' => @x_login_for_webpaystatus,
|
95
|
+
'x_trans_key' => @x_trans_key_for_webpaystatus,
|
96
|
+
'x_country' => country,
|
97
|
+
'x_amount' => amount
|
98
|
+
}
|
99
|
+
|
100
|
+
astro_curl(@astro_urls['exchange'], params_hash)
|
101
|
+
end
|
102
|
+
|
103
|
+
def astro_curl(url, params_hash)
|
104
|
+
AstroPay::Curl.post(url, params_hash)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AstroPay
|
2
|
+
class Model
|
3
|
+
attr_accessor :error, :message
|
4
|
+
|
5
|
+
include ActiveModel::Validations
|
6
|
+
include ActiveModel::Conversion
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
self.attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes=(attributes = {})
|
14
|
+
attributes.each do |name, value|
|
15
|
+
begin
|
16
|
+
send("#{name.to_s.underscore}=", value)
|
17
|
+
rescue NoMethodError => e
|
18
|
+
puts "Unable to assign #{name.to_s.underscore} with value #{value}. No such method."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes
|
24
|
+
Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/astro_pay.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "astro_pay/version"
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'active_support/inflector'
|
7
|
+
require 'active_model'
|
8
|
+
|
9
|
+
require 'openssl'
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
require 'json'
|
13
|
+
require 'digest/md5'
|
14
|
+
|
15
|
+
require 'astro_pay/configuration'
|
16
|
+
require 'astro_pay/curl'
|
17
|
+
require 'astro_pay/model'
|
18
|
+
require 'astro_pay/card'
|
19
|
+
require 'astro_pay/direct'
|
20
|
+
|
21
|
+
module AstroPay
|
22
|
+
class << self
|
23
|
+
attr_writer :configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configuration
|
27
|
+
@configuration ||= Configuration.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.configure
|
31
|
+
yield(configuration)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.direct(*args)
|
35
|
+
Direct.new(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.card(*args)
|
39
|
+
Card.new(*args)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Optional:
|
43
|
+
# You can send a Hash containing the following accepted params:
|
44
|
+
# :description, :currency, :cpf, :return_url, :confirmation_url
|
45
|
+
def self.create_direct(invoice, amount, iduser, country, bank='', sub_code=1, args={})
|
46
|
+
direct(
|
47
|
+
args.merge(
|
48
|
+
invoice: invoice,
|
49
|
+
amount: amount,
|
50
|
+
iduser: iduser,
|
51
|
+
bank: bank,
|
52
|
+
country: country,
|
53
|
+
sub_code: sub_code
|
54
|
+
)
|
55
|
+
).create
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.create_card(number, ccv, exp_date, amount, unique_id, invoice_num, additional_params={})
|
59
|
+
card(
|
60
|
+
number: number,
|
61
|
+
ccv: ccv,
|
62
|
+
exp_date: exp_date,
|
63
|
+
amount: amount,
|
64
|
+
unique_id: unique_id,
|
65
|
+
invoice_num: invoice_num,
|
66
|
+
additional_params: additional_params
|
67
|
+
).auth_capture_transaction
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astro_pay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Galaviz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-14 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.1'
|
97
|
+
description: Allows you to connect to AstroPay Direct/Card API.
|
98
|
+
email:
|
99
|
+
- galaviz.lm@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- astro_pay.gemspec
|
110
|
+
- lib/astro_pay.rb
|
111
|
+
- lib/astro_pay/card.rb
|
112
|
+
- lib/astro_pay/configuration.rb
|
113
|
+
- lib/astro_pay/curl.rb
|
114
|
+
- lib/astro_pay/direct.rb
|
115
|
+
- lib/astro_pay/model.rb
|
116
|
+
- lib/astro_pay/version.rb
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Simple API connection to AstroPay.
|
141
|
+
test_files: []
|