astropay 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e80487af39218eec19c615eec9d73c397b8eff33
4
+ data.tar.gz: c164b9806b755a0ea97de5b1249fa2c2ece9bef0
5
+ SHA512:
6
+ metadata.gz: 7032b0de05157e2f0020bf59c7c71100c92a94a667e3ebbfdd0d19447e08516b18412641ef6d2a1555070d96458964424f77aeb3d3dd84327af73ac74d9f321b
7
+ data.tar.gz: 5fe0fecf84b23f68fa59868e0575ff6fea6cc8ac6838c0caecc90e73f13a1cffdeeea36d16f488a00dfabef93b03c927e387eb2f22643c8cf0f918297142a812
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in astropay.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Martin Fernandez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Astropay
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'astropay'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install astropay
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bilby91/astropay.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'astropay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "astropay"
8
+ spec.version = Astropay::VERSION
9
+ spec.authors = ["Martin Fernandez"]
10
+ spec.email = ["fmartin91@gmail.com"]
11
+
12
+ spec.summary = %q{ Astropay API client. }
13
+ spec.description = %q{ Astropay API client. }
14
+ spec.homepage = "https://www.github.com/bilby91/astropay"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "hasugar", "~> 0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "astropay"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ require 'astropay/version'
2
+
3
+ require 'hasugar'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+
8
+ require_relative 'astropay/configuration'
9
+ require_relative 'astropay/request'
10
+
11
+ require_relative 'astropay/api'
12
+ require_relative 'astropay/streamline'
13
+ require_relative 'astropay/apd'
14
+ require_relative 'astropay/webpaystatus'
15
+
16
+ module Astropay
17
+
18
+ class << self
19
+ attr_accessor :configuration
20
+ end
21
+
22
+ def self.configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ def self.configure
27
+ yield(configuration)
28
+ end
29
+
30
+ end
@@ -0,0 +1,25 @@
1
+ module Astropay
2
+
3
+ class APD < API
4
+
5
+ def live_url
6
+ 'https://astropaycard.com/api_curl/apd'
7
+ end
8
+
9
+ def test_url
10
+ 'https://sandbox.astropaycard.com/api_curl/apd'
11
+ end
12
+
13
+ def get_banks_for_country(country_code)
14
+ request_data = { 'country_code' => country_code }
15
+
16
+ request_data
17
+ .merge!(config.credentials)
18
+ .merge!('type' => 'json')
19
+
20
+ request('/get_banks_by_country', request_data)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ module Astropay
2
+
3
+ class API
4
+
5
+ include Request
6
+
7
+ attr_accessor :config
8
+
9
+ def initialize(configuration = nil)
10
+ @config = configuration || Astropay.configuration
11
+ end
12
+
13
+ def build_url(relative_url)
14
+ (config.sandbox ? test_url : live_url) + relative_url
15
+ end
16
+
17
+ def request(relative_url, params)
18
+ url = build_url(relative_url)
19
+
20
+ post(url, params)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,24 @@
1
+ module Astropay
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :x_login, :x_trans_key, :secret_key, :x_login_webpaystatus,
6
+ :x_trans_key_webpaystatus, :sandbox, :ssl_enabled
7
+
8
+ def credentials
9
+ {
10
+ 'x_login' => x_login,
11
+ 'x_trans_key' => x_trans_key
12
+ }
13
+ end
14
+
15
+ def webpaystatus_credentials
16
+ {
17
+ 'x_login_webpaystatus' => x_login_webpaystatus,
18
+ 'x_trans_key_webpaystatus' => x_trans_key_webpaystatus
19
+ }
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ module Astropay
2
+
3
+ module Request
4
+
5
+ def post(url, params)
6
+ uri = URI.parse(url)
7
+
8
+ http = Net::HTTP.new(uri.host, uri.port)
9
+
10
+ http.use_ssl = true
11
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
12
+
13
+ request = Net::HTTP::Post.new(uri.path)
14
+ request.set_form_data(params)
15
+
16
+ response = http.request(request)
17
+
18
+ JSON.parse(response.body)
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,65 @@
1
+ module Astropay
2
+
3
+ class Streamline < API
4
+
5
+ def live_url
6
+ 'https://astropaycard.com/api_curl/streamline'
7
+ end
8
+
9
+ def test_url
10
+ 'https://sandbox.astropaycard.com/api_curl/streamline'
11
+ end
12
+
13
+ def create_invoice(invoice_data)
14
+ request_data = invoice_data
15
+ .transform(
16
+ 'invoice' => 'x_invoice',
17
+ 'amount' => 'x_amount',
18
+ 'currency' => 'x_currency',
19
+ 'bank' => 'x_bank',
20
+ 'country' => 'x_country',
21
+ 'description' => 'x_description',
22
+ 'user_id' => 'x_iduser',
23
+ 'cpf' => 'x_cpf',
24
+ 'name' => 'x_name',
25
+ 'email' => 'x_email',
26
+ 'birthday' => 'x_bdate',
27
+ 'address' => 'x_address',
28
+ 'zip' => 'x_zip',
29
+ 'city' => 'x_city',
30
+ 'state' => 'x_state',
31
+ 'phone' => 'x_mobile',
32
+ 'return_url' => 'x_return',
33
+ 'confirm_url' => 'x_confirmation'
34
+ )
35
+
36
+ control_string = build_control_string(request_data)
37
+
38
+ request_data
39
+ .merge!(config.credentials)
40
+ .merge!('control' => control_string, 'type' => 'json' )
41
+
42
+ request('/NewInvoice', request_data)
43
+ end
44
+
45
+ def build_control_string(invoice_data)
46
+ canonical_string =
47
+ "#{invoice_data['x_invoice']}V"\
48
+ "#{invoice_data['x_amount']}I"\
49
+ "#{invoice_data['x_iduser']}2"\
50
+ "#{invoice_data['x_bank']}1"\
51
+ "#{invoice_data['x_cpf']}H"\
52
+ "#{invoice_data['x_bdate']}G"\
53
+ "#{invoice_data['x_email']}Y"\
54
+ "#{invoice_data['x_zip']}A"\
55
+ "#{invoice_data['x_address']}P"\
56
+ "#{invoice_data['x_city']}S"\
57
+ "#{invoice_data['x_state']}P"
58
+
59
+ control_string = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, [config.secret_key].pack('A*'), [canonical_string].pack('A*'))
60
+ control_string.upcase
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ module Astropay
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ module Astropay
2
+
3
+ class Webpaystatus < API
4
+
5
+ def live_url
6
+ 'https://www.astropaycard.com/apd'
7
+ end
8
+
9
+ def test_url
10
+ 'https://sandbox.astropaycard.com/apd'
11
+ end
12
+
13
+ def get_payment_status(invoice)
14
+ request_data = { 'x_invoice' => invoice }
15
+
16
+ request_data
17
+ .merge!(config.webpaystatus_credentials)
18
+ .merge!('type' => 'json')
19
+
20
+ request('/webpaystatus', request_data)
21
+ end
22
+
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: astropay
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Fernandez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hasugar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: ' Astropay API client. '
70
+ email:
71
+ - fmartin91@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - astropay.gemspec
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/astropay.rb
87
+ - lib/astropay/apd.rb
88
+ - lib/astropay/api.rb
89
+ - lib/astropay/configuration.rb
90
+ - lib/astropay/request.rb
91
+ - lib/astropay/streamline.rb
92
+ - lib/astropay/version.rb
93
+ - lib/astropay/webpaystatus.rb
94
+ homepage: https://www.github.com/bilby91/astropay
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Astropay API client.
118
+ test_files: []
119
+ has_rdoc: