akatus 0.1.0 → 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.
- checksums.yaml +4 -4
- data/.gitignore +1 -16
- data/.rspec +2 -0
- data/LICENSE +1 -1
- data/Rakefile +6 -1
- data/akatus.gemspec +18 -11
- data/config/i18n.rb +3 -0
- data/lib/akatus.rb +34 -4
- data/lib/akatus/address.rb +11 -0
- data/lib/akatus/configuration.rb +43 -0
- data/lib/akatus/errors.rb +4 -0
- data/lib/akatus/formatters.rb +22 -0
- data/lib/akatus/installment.rb +6 -0
- data/lib/akatus/installment_options.rb +24 -0
- data/lib/akatus/item.rb +24 -0
- data/lib/akatus/payer.rb +35 -0
- data/lib/akatus/payment.rb +61 -0
- data/lib/akatus/payment_option.rb +6 -0
- data/lib/akatus/payment_types.rb +37 -0
- data/lib/akatus/phone.rb +6 -0
- data/lib/akatus/receiver.rb +6 -0
- data/lib/akatus/service.rb +34 -0
- data/lib/akatus/services/installments.rb +54 -0
- data/lib/akatus/services/payment_options.rb +95 -0
- data/lib/akatus/services/transaction.rb +50 -0
- data/lib/akatus/split_fee.rb +6 -0
- data/lib/akatus/transferrable.rb +58 -0
- data/lib/akatus/version.rb +1 -1
- data/locales/pt-BR.yml +69 -0
- data/spec/address_spec.rb +38 -0
- data/spec/factories/address_factories.rb +18 -0
- data/spec/factories/item_factories.rb +35 -0
- data/spec/factories/payer_factories.rb +8 -0
- data/spec/factories/phone_factories.rb +6 -0
- data/spec/item_spec.rb +42 -0
- data/spec/payer_spec.rb +31 -0
- data/spec/phone_spec.rb +23 -0
- data/spec/services/installments_spec.rb +36 -0
- data/spec/services/payment_options_spec.rb +22 -0
- data/spec/services/transaction_spec.rb +80 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/configuration.rb +7 -0
- data/spec/support/shared_examples/transferrable_example.rb +22 -0
- metadata +142 -12
- data/LICENSE.txt +0 -22
- data/lib/akatus/configuracao.rb +0 -40
- data/lib/akatus/formatadores.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e6394b4c41ed3be9c9d2e2c255926b7e94e7947
|
4
|
+
data.tar.gz: d083c49f1117259999bbfaec106da9441c53e7a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9f28c3bbfb32b77598d945bdfbd64cf18a4f6a49eb25740cf9e89e40ad95eb47f80eda86fa4188f5f7a621b40bbd09e0a82b407d0336fcaba92e0e01f6698c
|
7
|
+
data.tar.gz: 08dec081d6135e838f59568517ae3147824d3750b8e33b2db4fbdcddacf0e8c88c644b1abfe1146b4c280cb2b752b63fd1adb87f2b66c165326dd3ee35fccc62
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/LICENSE
CHANGED
data/Rakefile
CHANGED
data/akatus.gemspec
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'akatus/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'akatus'
|
8
8
|
spec.version = Akatus::VERSION
|
9
|
-
spec.
|
10
|
-
spec.email =
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.author = 'Kauplus'
|
10
|
+
spec.email = 'tech@kauplus.com.br'
|
11
|
+
spec.description = 'Built to support all types of checkout integration between Akatus and your application'
|
12
|
+
spec.summary = 'Ruby gem for the Akatus payment system'
|
13
|
+
spec.homepage = 'http://github.com/kauplus/akatus'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'activesupport'
|
22
|
-
spec.
|
23
|
-
spec.
|
22
|
+
spec.add_dependency 'i18n'
|
23
|
+
spec.add_dependency 'json'
|
24
|
+
spec.add_dependency 'rest-client'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
+
spec.add_development_dependency 'debugger'
|
28
|
+
spec.add_development_dependency 'factory_girl', '~> 4.3'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
24
31
|
end
|
data/config/i18n.rb
ADDED
data/lib/akatus.rb
CHANGED
@@ -1,6 +1,36 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
1
|
+
# External libraries
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'active_support/number_helper'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require 'i18n'
|
6
|
+
require 'json'
|
7
|
+
require 'rest-client'
|
8
|
+
|
9
|
+
# Configuration and modules
|
10
|
+
require 'akatus/configuration'
|
11
|
+
require 'akatus/errors'
|
12
|
+
require 'akatus/formatters'
|
13
|
+
require 'akatus/transferrable'
|
14
|
+
require 'akatus/version'
|
15
|
+
|
16
|
+
# Business classes
|
17
|
+
require 'akatus/address'
|
18
|
+
require 'akatus/installment'
|
19
|
+
require 'akatus/installment_options'
|
20
|
+
require 'akatus/item'
|
21
|
+
require 'akatus/payer'
|
22
|
+
require 'akatus/payment'
|
23
|
+
require 'akatus/payment_option'
|
24
|
+
require 'akatus/payment_types'
|
25
|
+
require 'akatus/phone'
|
26
|
+
require 'akatus/receiver'
|
27
|
+
require 'akatus/service'
|
28
|
+
require 'akatus/services/installments'
|
29
|
+
require 'akatus/services/payment_options'
|
30
|
+
require 'akatus/services/transaction'
|
31
|
+
require 'akatus/split_fee'
|
32
|
+
|
33
|
+
require_relative '../config/i18n'
|
4
34
|
|
5
35
|
module Akatus
|
6
|
-
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Akatus
|
4
|
+
|
5
|
+
def self.config
|
6
|
+
Configuration.instance
|
7
|
+
end
|
8
|
+
|
9
|
+
class Configuration
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
attr_accessor :api_key, :email, :env, :sandbox
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
|
16
|
+
@env = environment
|
17
|
+
conf = File.exists?(config_file_path) ? YAML.load_file(config_file_path)[@env] : {}
|
18
|
+
|
19
|
+
@sandbox = conf['sandbox'] == true
|
20
|
+
@api_key = conf['api_key']
|
21
|
+
@email = conf['email']
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def config_file_path
|
26
|
+
"#{Dir.pwd}/config/akatus.yml"
|
27
|
+
end
|
28
|
+
|
29
|
+
def environment
|
30
|
+
ENV['AKATUS_ENV'] || 'development'
|
31
|
+
end
|
32
|
+
|
33
|
+
def base_url
|
34
|
+
sandbox ? 'https://sandbox.akatus.com/' : 'https://www.akatus.com/'
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_url
|
38
|
+
base_url + "api/v1/"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Akatus
|
2
|
+
|
3
|
+
NUMERIC_FIELDS =
|
4
|
+
[
|
5
|
+
:price, :weight, :shipping_cost, :discount, :amount
|
6
|
+
]
|
7
|
+
|
8
|
+
INTEGER_FIELDS =
|
9
|
+
[
|
10
|
+
:quantity
|
11
|
+
]
|
12
|
+
|
13
|
+
STRING_FIELDS =
|
14
|
+
[
|
15
|
+
:reference
|
16
|
+
]
|
17
|
+
|
18
|
+
def self.format_number(val)
|
19
|
+
ActiveSupport::NumberHelper.number_to_rounded(val, :locale => :en, :precision => 2)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Akatus
|
2
|
+
class InstallmentOptions
|
3
|
+
include Transferrable
|
4
|
+
attr_accessor :description, :installments, :taken_installments
|
5
|
+
|
6
|
+
#
|
7
|
+
# Build an empty ("dummy") object.
|
8
|
+
#
|
9
|
+
def self.blank(payment)
|
10
|
+
|
11
|
+
# The only "option" is to pay the full amount in one installment.
|
12
|
+
installment_options = [
|
13
|
+
Installment.new({
|
14
|
+
:quantity => 1,
|
15
|
+
:unitary_amount => payment.total_amount,
|
16
|
+
:total_amount => payment.total_amount
|
17
|
+
})
|
18
|
+
]
|
19
|
+
|
20
|
+
new({ :taken_installments => 0, :installments => installment_options })
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/akatus/item.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Item
|
3
|
+
include Transferrable
|
4
|
+
transferrable_attrs :reference, :description, :quantity, :price, :weight,
|
5
|
+
:shipping_cost, :discount, :split_fee
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
opts = {
|
9
|
+
:shipping_cost => 0,
|
10
|
+
:discount => 0,
|
11
|
+
:weight => 0,
|
12
|
+
:quantity => 1
|
13
|
+
}.merge(opts)
|
14
|
+
super(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_amount
|
18
|
+
quantity * BigDecimal.new(price.to_s) +
|
19
|
+
BigDecimal.new(shipping_cost.to_s) -
|
20
|
+
BigDecimal.new(discount.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/akatus/payer.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Payer
|
3
|
+
include Transferrable
|
4
|
+
transferrable_attrs :name, :email
|
5
|
+
|
6
|
+
attr_accessor :addresses, :phones
|
7
|
+
|
8
|
+
def address=(val)
|
9
|
+
addresses ? addresses.unshift(val) : (@addresses = [val])
|
10
|
+
end
|
11
|
+
|
12
|
+
def address
|
13
|
+
addresses[0] if addresses
|
14
|
+
end
|
15
|
+
|
16
|
+
def phone=(val)
|
17
|
+
phones ? phones.unshift(val) : (@phones = [val])
|
18
|
+
end
|
19
|
+
|
20
|
+
def phone
|
21
|
+
phones[0] if phones
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_payload(include_root = true)
|
25
|
+
payload = super(true)
|
26
|
+
|
27
|
+
# Tweak Akatus' weird array format.
|
28
|
+
payload['pagador']['enderecos'] = { 'endereco' => addresses.map { |a| a.to_payload(false) } }
|
29
|
+
payload['pagador']['telefones'] = { 'telefone' => phones.map { |p| p.to_payload(false) } }
|
30
|
+
|
31
|
+
include_root ? payload : payload.values.first
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Payment
|
3
|
+
include Transferrable
|
4
|
+
|
5
|
+
attr_reader :receiver
|
6
|
+
|
7
|
+
attr_accessor :reference, :payer, :items, :payment_method,
|
8
|
+
:weight, :shipping_cost, :discount, :currency,
|
9
|
+
:id, :status, :transaction_id, :url, :error, :total_amount
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
options = {
|
13
|
+
:items => [],
|
14
|
+
:discount => 0,
|
15
|
+
:shipping_cost => 0,
|
16
|
+
:weight => 0
|
17
|
+
}.merge(opts)
|
18
|
+
super(options)
|
19
|
+
|
20
|
+
@receiver = Receiver.new({ :email => Akatus.config.email, :api_key => Akatus.config.api_key })
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_payload
|
24
|
+
hsh = {
|
25
|
+
'carrinho' => {
|
26
|
+
'produtos' => { 'produto' => items.map { |i| i.to_payload(false) } },
|
27
|
+
'transacao' => {
|
28
|
+
'peso' => Akatus.format_number(total_weight),
|
29
|
+
'frete' => Akatus.format_number(total_shipping_cost),
|
30
|
+
'desconto' => Akatus.format_number(total_discount),
|
31
|
+
'referencia' => reference,
|
32
|
+
'moeda' => 'BRL'
|
33
|
+
}.merge(payment_method.to_payload),
|
34
|
+
'recebedor' => receiver.to_payload(false),
|
35
|
+
'pagador' => payer.to_payload(false)
|
36
|
+
}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def total_weight
|
41
|
+
weight + items.inject(0) { |sum, item| sum + item.weight }
|
42
|
+
end
|
43
|
+
|
44
|
+
def total_shipping_cost
|
45
|
+
shipping_cost + items.inject(0) { |sum, item| sum + item.shipping_cost }
|
46
|
+
end
|
47
|
+
|
48
|
+
def total_discount
|
49
|
+
discount + items.inject(0) { |sum, item| sum + item.discount }
|
50
|
+
end
|
51
|
+
|
52
|
+
def total_items_amount
|
53
|
+
items.inject(0) { |sum, item| sum + item.total_amount }
|
54
|
+
end
|
55
|
+
|
56
|
+
def total_amount
|
57
|
+
total_items_amount - total_discount + total_shipping_cost
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Akatus
|
2
|
+
|
3
|
+
class PaymentType
|
4
|
+
include Transferrable
|
5
|
+
attr_accessor :type
|
6
|
+
end
|
7
|
+
|
8
|
+
class CreditCard < PaymentType
|
9
|
+
transferrable_attrs :brand, :number, :security_code, :installments, :expiration
|
10
|
+
|
11
|
+
attr_accessor :holder_name, :holder_cpf, :holder_phone
|
12
|
+
|
13
|
+
def to_payload
|
14
|
+
payload = super
|
15
|
+
payload['cartao_de_credito']['portador'] = {
|
16
|
+
:nome => holder_name,
|
17
|
+
:cpf => holder_cpf,
|
18
|
+
:telefone => holder_phone
|
19
|
+
}
|
20
|
+
payload['cartao_de_credito']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ElectronicFundsTransfer < PaymentType
|
25
|
+
transferrable_attrs :brand
|
26
|
+
def to_payload
|
27
|
+
{ :meio_de_pagamento => brand }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class BoletoBancario < PaymentType
|
32
|
+
attr_accessor :brand
|
33
|
+
def to_payload
|
34
|
+
{ :meio_de_pagamento => 'boleto' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|