getnet 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/README.md +0 -0
- data/lib/getnet.rb +36 -0
- data/lib/getnet/authorization.rb +32 -0
- data/lib/getnet/config.rb +12 -0
- data/lib/getnet/credit_card.rb +41 -0
- data/lib/getnet/payment/iframe.rb +75 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 98673ebaee2d1551f536e6c8ce352eefee0bf9d0d3d9ed4771080cb0f16fc0dc
|
|
4
|
+
data.tar.gz: 2c92007c2d7c604fb7aa2f85275105bb363fdd9f58bab899287a68f2ef243ca6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ee9bbdea8f5d17d694f9f72985889dc69e24ec5ca4010bf2674f3b0129504c9cb34bb12815e541c929f6a7735ea1adb916594e3fe5b69ace8f266c5b8aa21baf
|
|
7
|
+
data.tar.gz: 38114c8e9be3ebb72190b6eb621bc6422c5b599ab07d3065f6e9302f634d23f4cfc27521b63dd666257ba8a663ec2cac709567c287a642cfefd06d5fea172385
|
data/README.md
ADDED
|
File without changes
|
data/lib/getnet.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "bigdecimal"
|
|
2
|
+
require "forwardable"
|
|
3
|
+
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "json"
|
|
7
|
+
|
|
8
|
+
require "getnet/config"
|
|
9
|
+
require "getnet/authorization"
|
|
10
|
+
require "getnet/credit_card"
|
|
11
|
+
require "getnet/payment/iframe"
|
|
12
|
+
|
|
13
|
+
module Getnet
|
|
14
|
+
class << self
|
|
15
|
+
extend Forwardable
|
|
16
|
+
def_delegators :configuration, :client_id, :client_secret, :seller_id, :environment
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.configuration
|
|
20
|
+
@configuration ||= Getnet::Config.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.base_uri
|
|
24
|
+
environment == :sandbox ?
|
|
25
|
+
"https://api-sandbox.getnet.com.br" :
|
|
26
|
+
"https://api-homologacao.getnet.com.br"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.uri_path(path)
|
|
30
|
+
base_uri + path
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.configure
|
|
34
|
+
yield configuration
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Getnet
|
|
2
|
+
class Authorization
|
|
3
|
+
attr_accessor :token
|
|
4
|
+
attr_accessor :token_type
|
|
5
|
+
attr_accessor :full_token
|
|
6
|
+
|
|
7
|
+
def self.authenticate
|
|
8
|
+
self.new.run
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def run
|
|
12
|
+
uri = URI(Getnet.uri_path("/auth/oauth/v2/token"))
|
|
13
|
+
|
|
14
|
+
req = Net::HTTP::Post.new uri
|
|
15
|
+
req.set_form_data( 'scope' => 'oob', 'grant_type' => 'client_credentials')
|
|
16
|
+
req.basic_auth Getnet.client_id, Getnet.client_secret
|
|
17
|
+
req['Accept'] = "application/json, text/plain, */*"
|
|
18
|
+
req['Content-type'] = "application/x-www-form-urlencoded"
|
|
19
|
+
|
|
20
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
21
|
+
http.use_ssl = true
|
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
23
|
+
res = http.request(req)
|
|
24
|
+
result = JSON.parse(res.body)
|
|
25
|
+
|
|
26
|
+
@token = result['access_token']
|
|
27
|
+
@token_type = result['token_type']
|
|
28
|
+
@full_token = "#{@token_type} #{@token}"
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Getnet
|
|
2
|
+
class CreditCard
|
|
3
|
+
attr_reader :card_token
|
|
4
|
+
attr_reader :card_number
|
|
5
|
+
|
|
6
|
+
def initialize(card_number)
|
|
7
|
+
@card_number = card_number
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.call(card_number)
|
|
11
|
+
new(card_number).get_token
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_token
|
|
15
|
+
uri = URI(Getnet.uri_path('/v1/tokens/card'))
|
|
16
|
+
|
|
17
|
+
req = Net::HTTP::Post.new uri
|
|
18
|
+
req.body = {"card_number" => card_number}.to_json
|
|
19
|
+
req.content_type = "application/json"
|
|
20
|
+
req['Authorization'] = authorization.full_token
|
|
21
|
+
req['Accept'] = "application/json, text/plain, */*"
|
|
22
|
+
|
|
23
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
24
|
+
http.use_ssl = true
|
|
25
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
26
|
+
|
|
27
|
+
res = http.request(req)
|
|
28
|
+
|
|
29
|
+
result = JSON.parse(res.body)
|
|
30
|
+
|
|
31
|
+
@card_token = result['number_token']
|
|
32
|
+
@card_token
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def authorization
|
|
38
|
+
@authorization ||= Getnet::Authorization.authenticate
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Getnet
|
|
2
|
+
module Payment
|
|
3
|
+
class Iframe
|
|
4
|
+
PAYMENT_IFRAME_ATTRIBUTES = %W{
|
|
5
|
+
sellerid
|
|
6
|
+
token
|
|
7
|
+
amount
|
|
8
|
+
customerid
|
|
9
|
+
orderid
|
|
10
|
+
button_class
|
|
11
|
+
customer_first_name
|
|
12
|
+
customer_last_name
|
|
13
|
+
customer_document_type
|
|
14
|
+
customer_document_number
|
|
15
|
+
customer_email
|
|
16
|
+
customer_address_street
|
|
17
|
+
customer_address_street_number
|
|
18
|
+
customer_address_neighborhood
|
|
19
|
+
customer_address_city
|
|
20
|
+
customer_address_state
|
|
21
|
+
customer_address_zipcode
|
|
22
|
+
customer_country
|
|
23
|
+
items
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
attr_writer :attributes
|
|
27
|
+
|
|
28
|
+
def initialize()
|
|
29
|
+
@attributes = {}
|
|
30
|
+
PAYMENT_IFRAME_ATTRIBUTES.each do |attr|
|
|
31
|
+
@attributes[attr.to_sym] = nil
|
|
32
|
+
end
|
|
33
|
+
@attributes[:amount] = 0
|
|
34
|
+
@attributes[:items] = []
|
|
35
|
+
@attributes[:sellerid] = Getnet.seller_id
|
|
36
|
+
@attributes[:token] = authorization.full_token
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.attributes
|
|
40
|
+
PAYMENT_IFRAME_ATTRIBUTES
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def setup
|
|
44
|
+
yield @attributes
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def add_item(item ={})
|
|
48
|
+
@attributes[:items] << item
|
|
49
|
+
@attributes[:amount] = @attributes[:amount] + item[:value] * item[:quantity]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def [](key)
|
|
53
|
+
if key.is_a?(Symbol) || key.is_a?(String)
|
|
54
|
+
return @attributes[key.to_sym]
|
|
55
|
+
else
|
|
56
|
+
raise ArgumentError, "Invalid attribute name"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def []=(key, value)
|
|
61
|
+
if key.is_a?(Symbol) || key.is_a?(String)
|
|
62
|
+
@attributes[key.to_sym] = value
|
|
63
|
+
else
|
|
64
|
+
raise ArgumentError, "Invalid attribute name"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def authorization
|
|
71
|
+
@authorization ||= Getnet::Authorization.authenticate
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: getnet
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Valentin F. Paes
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Biblioteca de integração com a API do serviço de pagamentos da Getnet
|
|
14
|
+
email: valentin.paes0@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- README.md
|
|
20
|
+
- lib/getnet.rb
|
|
21
|
+
- lib/getnet/authorization.rb
|
|
22
|
+
- lib/getnet/config.rb
|
|
23
|
+
- lib/getnet/credit_card.rb
|
|
24
|
+
- lib/getnet/payment/iframe.rb
|
|
25
|
+
homepage: https://rubygems.org/gems/getnet
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata: {}
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 2.6.0
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubygems_version: 3.0.1
|
|
45
|
+
signing_key:
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Biblioteca de integração com a Getnet
|
|
48
|
+
test_files: []
|