cielo-api30 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cielo/api30.rb +13 -71
- data/lib/cielo/api30/address.rb +37 -36
- data/lib/cielo/api30/client.rb +67 -0
- data/lib/cielo/api30/credit_card.rb +42 -42
- data/lib/cielo/api30/customer.rb +39 -40
- data/lib/cielo/api30/environment.rb +31 -0
- data/lib/cielo/api30/merchant.rb +19 -0
- data/lib/cielo/api30/payment.rb +122 -111
- data/lib/cielo/api30/payment/status.rb +28 -0
- data/lib/cielo/api30/recurrent_payment.rb +35 -36
- data/lib/cielo/api30/request/cielo_error.rb +12 -4
- data/lib/cielo/api30/request/cielo_request.rb +24 -20
- data/lib/cielo/api30/request/create_sale_request.rb +10 -8
- data/lib/cielo/api30/request/query_sale_request.rb +10 -8
- data/lib/cielo/api30/request/update_sale_request.rb +15 -17
- data/lib/cielo/api30/return_info.rb +58 -0
- data/lib/cielo/api30/return_infos.yml +624 -0
- data/lib/cielo/api30/sale.rb +27 -28
- data/lib/cielo/api30/version.rb +4 -4
- metadata +9 -5
- data/lib/cielo/environment.rb +0 -31
- data/lib/cielo/merchant.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cdfaeeda0aba249fca064cd1d2762ff8da20f82
|
4
|
+
data.tar.gz: 695539f8e9fc66e62a3a711bfcafdcb61290253d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407905a79cb28ca242b004d3a290073ec69a00f5892a27a24f6b55af410b7e390811dad191b90bbe92575414669bba603c38981a6f8c1c5a370590f4059d8db8
|
7
|
+
data.tar.gz: 8bf935261dad5a61847bdd3752e3b74fc5ce3ddb3d1512c33a29b0775882609132241977c31d98beb9d7b78e7a833d3c0d4e25bca2ffe49dc8bbe65829130eac
|
data/lib/cielo/api30.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require "cielo/environment"
|
2
|
-
require "cielo/merchant"
|
1
|
+
require "cielo/api30/environment"
|
2
|
+
require "cielo/api30/merchant"
|
3
|
+
require "cielo/api30/client"
|
3
4
|
|
4
5
|
require "cielo/api30/address"
|
5
6
|
require "cielo/api30/credit_card"
|
@@ -13,76 +14,17 @@ require "cielo/api30/request/query_sale_request"
|
|
13
14
|
require "cielo/api30/request/update_sale_request"
|
14
15
|
|
15
16
|
module Cielo
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Create an instance of API by choosing the environment where the
|
22
|
-
# requests will be send
|
23
|
-
#
|
24
|
-
# @param merchant [Merchant] The merchant credentials
|
25
|
-
# @param environment [Environment] The environment
|
26
|
-
def initialize(
|
27
|
-
merchant,
|
28
|
-
environment = nil)
|
29
|
-
|
30
|
-
if (environment == nil)
|
31
|
-
environment = Environment.production()
|
32
|
-
end
|
33
|
-
|
34
|
-
@merchant = merchant
|
35
|
-
@environment = environment
|
36
|
-
end
|
37
|
-
|
38
|
-
# Send the Sale to be created and return the Sale with tid and the status
|
39
|
-
# returned by Cielo.
|
40
|
-
#
|
41
|
-
# @param sale [Sale] The preconfigured Sale
|
42
|
-
# @return [Sale] The Sale with authorization, tid, etc. returned by Cielo.
|
43
|
-
def create_sale(sale)
|
44
|
-
request = Cielo::Request::CreateSaleRequest.new(merchant, environment)
|
45
|
-
|
46
|
-
request.execute(sale)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Query a Sale on Cielo by paymentId
|
50
|
-
#
|
51
|
-
# @param payment_id [String] The payment_id to be queried
|
52
|
-
# @return [Sale] The Sale with authorization, tid, etc. returned by Cielo.
|
53
|
-
def get_sale(payment_id)
|
54
|
-
request = Cielo::Request::QuerySaleRequest.new(merchant, environment)
|
55
|
-
|
56
|
-
request.execute(payment_id)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Cancel a Payment on Cielo by paymentId and speficying the amount
|
60
|
-
#
|
61
|
-
# @param payment_id [String] The payment_id to be queried
|
62
|
-
# @param amount [Integer] Order value in cents
|
63
|
-
# @return [Payment] The cancelled payment
|
64
|
-
def cancel_payment(payment_id, amount=nil)
|
65
|
-
request = Cielo::Request::UpdateSaleRequest.new("void", merchant, environment)
|
66
|
-
|
67
|
-
request.amount = amount
|
68
|
-
|
69
|
-
request.execute(payment_id)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Capture a Sale on Cielo by paymentId and specifying the amount and the
|
73
|
-
# serviceTaxAmount
|
74
|
-
#
|
75
|
-
# @param payment_id [String] The payment_id to be captured
|
76
|
-
# @param amount [Integer] Amount of the authorization to be captured
|
77
|
-
# @param service_tax_amount [Integer] Amount of the authorization should be destined for the service charge
|
78
|
-
# @return [Payment] The captured payment
|
79
|
-
def capture_sale(payment_id, amount=nil, service_tax_amount=nil)
|
80
|
-
request = Cielo::Request::UpdateSaleRequest.new("capture", merchant, environment)
|
17
|
+
module API30
|
18
|
+
def self.root_path
|
19
|
+
File.dirname __dir__
|
20
|
+
end
|
81
21
|
|
82
|
-
|
83
|
-
|
22
|
+
def self.client(merchant, environment = nil)
|
23
|
+
Client.new(merchant, environment)
|
24
|
+
end
|
84
25
|
|
85
|
-
|
86
|
-
|
26
|
+
def self.merchant(merchant_id, merchant_key)
|
27
|
+
Merchant.new(merchant_id, merchant_key)
|
87
28
|
end
|
29
|
+
end
|
88
30
|
end
|
data/lib/cielo/api30/address.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Cielo
|
2
|
+
module API30
|
2
3
|
# Customer's address.
|
3
4
|
#
|
4
5
|
# @attr [String] street the customer's address
|
@@ -9,45 +10,45 @@ module Cielo
|
|
9
10
|
# @attr [String] state the state of customer's address
|
10
11
|
# @attr [String] country the country of customer's address
|
11
12
|
class Address
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
attr_accessor :street,
|
14
|
+
:number,
|
15
|
+
:complement,
|
16
|
+
:zip_code,
|
17
|
+
:city,
|
18
|
+
:state,
|
19
|
+
:country
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def to_json(*options)
|
22
|
+
hash = as_json(*options)
|
23
|
+
hash.reject! {|k,v| v.nil?}
|
24
|
+
hash.to_json(*options)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
address = Address.new
|
27
|
+
def self.from_json(data)
|
28
|
+
return if data.nil?
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
address = new
|
31
|
+
address.street = data["Street"]
|
32
|
+
address.number = data["Number"]
|
33
|
+
address.complement = data["Complement"]
|
34
|
+
address.zip_code = data["ZipCode"]
|
35
|
+
address.city = data["City"]
|
36
|
+
address.state = data["State"]
|
37
|
+
address.country = data["Country"]
|
38
|
+
address
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
41
|
+
def as_json(options={})
|
42
|
+
{
|
43
|
+
Street: @street,
|
44
|
+
Number: @number,
|
45
|
+
Complement: @complement,
|
46
|
+
ZipCode: @zip_code,
|
47
|
+
City: @city,
|
48
|
+
State: @state,
|
49
|
+
Country: @country
|
50
|
+
}
|
51
|
+
end
|
52
52
|
end
|
53
|
+
end
|
53
54
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Cielo
|
2
|
+
module API30
|
3
|
+
# The Cielo API SDK front-end
|
4
|
+
class Client
|
5
|
+
attr_accessor :merchant, :environment
|
6
|
+
private :merchant, :environment
|
7
|
+
|
8
|
+
# Create an instance of API client by choosing the environment where the
|
9
|
+
# requests will be send
|
10
|
+
#
|
11
|
+
# @param merchant [Merchant] The merchant credentials
|
12
|
+
# @param environment [Environment] The environment
|
13
|
+
def initialize(merchant, environment = nil)
|
14
|
+
environment ||= Environment.production
|
15
|
+
|
16
|
+
@merchant = merchant
|
17
|
+
@environment = environment
|
18
|
+
end
|
19
|
+
|
20
|
+
# Send the Sale to be created and return the Sale with tid and the status
|
21
|
+
# returned by Cielo.
|
22
|
+
#
|
23
|
+
# @param sale [Sale] The preconfigured Sale
|
24
|
+
# @return [Sale] The Sale with authorization, tid, etc. returned by Cielo.
|
25
|
+
def create_sale(sale)
|
26
|
+
Cielo::API30::Request::CreateSaleRequest.new(merchant, environment).execute(sale)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Query a Sale on Cielo by paymentId
|
30
|
+
#
|
31
|
+
# @param payment_id [String] The payment_id to be queried
|
32
|
+
# @return [Sale] The Sale with authorization, tid, etc. returned by Cielo.
|
33
|
+
def get_sale(payment_id)
|
34
|
+
Cielo::API30::Request::QuerySaleRequest.new(merchant, environment).execute(payment_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Cancel a Payment on Cielo by paymentId and speficying the amount
|
38
|
+
#
|
39
|
+
# @param payment_id [String] The payment_id to be queried
|
40
|
+
# @param amount [Integer] Order value in cents
|
41
|
+
# @return [Payment] The cancelled payment
|
42
|
+
def cancel_payment(payment_id, amount=nil)
|
43
|
+
request = Cielo::API30::Request::UpdateSaleRequest.new("void", merchant, environment)
|
44
|
+
|
45
|
+
request.amount = amount
|
46
|
+
|
47
|
+
request.execute(payment_id)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Capture a Sale on Cielo by paymentId and specifying the amount and the
|
51
|
+
# serviceTaxAmount
|
52
|
+
#
|
53
|
+
# @param payment_id [String] The payment_id to be captured
|
54
|
+
# @param amount [Integer] Amount of the authorization to be captured
|
55
|
+
# @param service_tax_amount [Integer] Amount of the authorization should be destined for the service charge
|
56
|
+
# @return [Payment] The captured payment
|
57
|
+
def capture_sale(payment_id, amount=nil, service_tax_amount=nil)
|
58
|
+
request = Cielo::API30::Request::UpdateSaleRequest.new("capture", merchant, environment)
|
59
|
+
|
60
|
+
request.amount = amount
|
61
|
+
request.service_tax_amount = service_tax_amount
|
62
|
+
|
63
|
+
request.execute(payment_id)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Cielo
|
2
|
+
module API30
|
2
3
|
# Credit card data
|
3
4
|
#
|
4
5
|
# @attr [String] card_number Credit card number
|
@@ -9,52 +10,51 @@ module Cielo
|
|
9
10
|
# @attr [String] brand Credit card brand
|
10
11
|
# @attr [String] card_token Card token
|
11
12
|
class CreditCard
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
attr_accessor :card_number,
|
14
|
+
:holder,
|
15
|
+
:expiration_date,
|
16
|
+
:security_code,
|
17
|
+
:save_card,
|
18
|
+
:brand,
|
19
|
+
:card_token
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def initialize(args = {})
|
22
|
+
@security_code = args[:security_code]
|
23
|
+
@brand = args[:brand]
|
24
|
+
@card_token = args[:token]
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def to_json(*options)
|
28
|
+
hash = as_json(*options)
|
29
|
+
hash.reject! {|k,v| v.nil?}
|
30
|
+
hash.to_json(*options)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
credit_card = CreditCard.new()
|
35
|
-
credit_card.card_number = data["CardNumber"] || nil
|
36
|
-
credit_card.holder = data["Holder"] || nil
|
37
|
-
credit_card.expiration_date = data["ExpirationDate"] || nil
|
38
|
-
credit_card.security_code = data["SecurityCode"] || nil
|
39
|
-
credit_card.save_card = data["SaveCard"] || nil
|
40
|
-
credit_card.brand = data["Brand"] || nil
|
41
|
-
credit_card.card_token = data["CardToken"] || nil
|
33
|
+
def self.from_json(data)
|
34
|
+
return if data.nil?
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
credit_card = new
|
37
|
+
credit_card.card_number = data["CardNumber"]
|
38
|
+
credit_card.holder = data["Holder"]
|
39
|
+
credit_card.expiration_date = data["ExpirationDate"]
|
40
|
+
credit_card.security_code = data["SecurityCode"]
|
41
|
+
credit_card.save_card = data["SaveCard"]
|
42
|
+
credit_card.brand = data["Brand"]
|
43
|
+
credit_card.card_token = data["CardToken"]
|
44
|
+
credit_card
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
47
|
+
def as_json(options={})
|
48
|
+
{
|
49
|
+
CardNumber: @card_number,
|
50
|
+
Holder: @holder,
|
51
|
+
ExpirationDate: @expiration_date,
|
52
|
+
SecurityCode: @security_code,
|
53
|
+
SaveCard: @save_card,
|
54
|
+
Brand: @brand,
|
55
|
+
CardToken: @card_token
|
56
|
+
}
|
57
|
+
end
|
59
58
|
end
|
59
|
+
end
|
60
60
|
end
|
data/lib/cielo/api30/customer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Cielo
|
2
|
+
module API30
|
2
3
|
# Customer data
|
3
4
|
#
|
4
5
|
# @attr [String] name Customer name
|
@@ -9,50 +10,48 @@ module Cielo
|
|
9
10
|
# @attr [Address] address Customer's address
|
10
11
|
# @attr [Address] deliveryAddress The delivery address
|
11
12
|
class Customer
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
attr_accessor :name,
|
14
|
+
:email,
|
15
|
+
:birth_date,
|
16
|
+
:identity,
|
17
|
+
:identity_type,
|
18
|
+
:address,
|
19
|
+
:delivery_adress
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def initialize(name)
|
22
|
+
@name = name
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def to_json(*options)
|
26
|
+
hash = as_json(*options)
|
27
|
+
hash.reject! {|k,v| v.nil?}
|
28
|
+
hash.to_json(*options)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
customer = Customer.new(data["Name"] || nil)
|
31
|
+
def self.from_json(data)
|
32
|
+
return if data.nil?
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
customer = new(data["Name"])
|
35
|
+
customer.email = data["Email"]
|
36
|
+
customer.birth_date = data["BirthDate"]
|
37
|
+
customer.identity = data["Identity"]
|
38
|
+
customer.identity_type = data["IdentityType"]
|
39
|
+
customer.address = Address.from_json(data["Address"])
|
40
|
+
customer.delivery_adress = Address.from_json(data["DeliveryAddress"])
|
41
|
+
customer
|
42
|
+
end
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
IdentityType: @identity_type,
|
53
|
-
Address: @address,
|
54
|
-
DeliveryAddress: @delivery_address
|
55
|
-
}
|
56
|
-
end
|
44
|
+
def as_json(options={})
|
45
|
+
{
|
46
|
+
Name: @name,
|
47
|
+
Email: @email,
|
48
|
+
BirthDate: @birth_date,
|
49
|
+
Identity: @identity,
|
50
|
+
IdentityType: @identity_type,
|
51
|
+
Address: @address,
|
52
|
+
DeliveryAddress: @delivery_address
|
53
|
+
}
|
54
|
+
end
|
57
55
|
end
|
56
|
+
end
|
58
57
|
end
|