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
@@ -0,0 +1,31 @@
|
|
1
|
+
module Cielo
|
2
|
+
module API30
|
3
|
+
# API Environment URLs
|
4
|
+
#
|
5
|
+
# @attr [String] api API URL
|
6
|
+
# @attr [String] apiQuery API Query URL
|
7
|
+
class Environment
|
8
|
+
attr_accessor :api,
|
9
|
+
:api_query
|
10
|
+
|
11
|
+
def initialize(api, api_query)
|
12
|
+
@api = api
|
13
|
+
@api_query = api_query
|
14
|
+
end
|
15
|
+
|
16
|
+
# The production environment
|
17
|
+
#
|
18
|
+
# @return [Environment] a configured Environment for production
|
19
|
+
def self.production
|
20
|
+
new("https://api.cieloecommerce.cielo.com.br/", "https://apiquery.cieloecommerce.cielo.com.br/")
|
21
|
+
end
|
22
|
+
|
23
|
+
# The sandbox environment
|
24
|
+
#
|
25
|
+
# @return [Environment] a configured Environment for testing
|
26
|
+
def self.sandbox
|
27
|
+
new("https://apisandbox.cieloecommerce.cielo.com.br/", "https://apiquerysandbox.cieloecommerce.cielo.com.br/")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cielo
|
2
|
+
module API30
|
3
|
+
# Merchant identification on Cielo
|
4
|
+
#
|
5
|
+
# @attr [String] merchant_id the merchant identification number
|
6
|
+
# @attr [String] merchant_key the merchant identification key
|
7
|
+
class Merchant
|
8
|
+
attr_accessor :merchant_id,
|
9
|
+
:merchant_key
|
10
|
+
|
11
|
+
# @param merchant_id [String] the merchant identification number
|
12
|
+
# @param merchant_key [String] the merchant identification key
|
13
|
+
def initialize(merchant_id, merchant_key)
|
14
|
+
@merchant_id = merchant_id
|
15
|
+
@merchant_key = merchant_key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/cielo/api30/payment.rb
CHANGED
@@ -1,125 +1,136 @@
|
|
1
|
+
require "cielo/api30/payment/status"
|
2
|
+
require "cielo/api30/return_info"
|
3
|
+
|
1
4
|
module Cielo
|
5
|
+
module API30
|
2
6
|
class Payment
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
+
PAYMENTTYPE_CREDITCARD = "CreditCard"
|
8
|
+
PAYMENTTYPE_DEBITCARD = "DebitCard"
|
9
|
+
PAYMENTTYPE_ELECTRONIC_TRANSFER = "ElectronicTransfer"
|
10
|
+
PAYMENTTYPE_BOLETO = "Boleto"
|
11
|
+
|
12
|
+
PROVIDER_BRADESCO = "Bradesco"
|
13
|
+
PROVIDER_BANCO_DO_BRASIL = "BancoDoBrasil"
|
14
|
+
PROVIDER_SIMULADO = "Simulado"
|
15
|
+
|
16
|
+
attr_accessor :service_tax_amount,
|
17
|
+
:installments,
|
18
|
+
:interest,
|
19
|
+
:capture,
|
20
|
+
:authenticate,
|
21
|
+
:recurrent,
|
22
|
+
:recurrent_payment,
|
23
|
+
:credit_card,
|
24
|
+
:proof_of_sale,
|
25
|
+
:authorization_code,
|
26
|
+
:soft_descriptor,
|
27
|
+
:return_url,
|
28
|
+
:provider,
|
29
|
+
:payment_id,
|
30
|
+
:tid,
|
31
|
+
:type,
|
32
|
+
:amount,
|
33
|
+
:received_date,
|
34
|
+
:captured_amount,
|
35
|
+
:captured_date,
|
36
|
+
:currency,
|
37
|
+
:country,
|
38
|
+
:return_code,
|
39
|
+
:return_message,
|
40
|
+
:status,
|
41
|
+
:links,
|
42
|
+
:extra_data_collection,
|
43
|
+
:expiration_date,
|
44
|
+
:url,
|
45
|
+
:number,
|
46
|
+
:bar_code_number,
|
47
|
+
:digitable_line,
|
48
|
+
:address,
|
49
|
+
:return_info
|
7
50
|
|
8
|
-
|
9
|
-
|
10
|
-
|
51
|
+
def initialize(amount, installments: 1)
|
52
|
+
@amount = amount
|
53
|
+
@installments = installments
|
54
|
+
end
|
11
55
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:recurrent,
|
18
|
-
:recurrent_payment,
|
19
|
-
:credit_card,
|
20
|
-
:proof_of_sale,
|
21
|
-
:authorization_code,
|
22
|
-
:soft_descriptor,
|
23
|
-
:return_url,
|
24
|
-
:provider,
|
25
|
-
:payment_id,
|
26
|
-
:tid,
|
27
|
-
:type,
|
28
|
-
:amount,
|
29
|
-
:received_date,
|
30
|
-
:captured_amount,
|
31
|
-
:captured_date,
|
32
|
-
:currency,
|
33
|
-
:country,
|
34
|
-
:return_code,
|
35
|
-
:return_message,
|
36
|
-
:status,
|
37
|
-
:links,
|
38
|
-
:extra_data_collection,
|
39
|
-
:expiration_date,
|
40
|
-
:url,
|
41
|
-
:number,
|
42
|
-
:bar_code_number,
|
43
|
-
:digitable_line,
|
44
|
-
:address
|
56
|
+
def to_json(*options)
|
57
|
+
hash = as_json(*options)
|
58
|
+
hash.reject! {|k,v| v.nil?}
|
59
|
+
hash.to_json(*options)
|
60
|
+
end
|
45
61
|
|
46
|
-
|
47
|
-
|
48
|
-
@installments = installments
|
49
|
-
end
|
62
|
+
def self.from_json(data)
|
63
|
+
return if data.nil?
|
50
64
|
|
51
|
-
|
52
|
-
hash = as_json(*options)
|
53
|
-
hash.reject! {|k,v| v.nil?}
|
54
|
-
hash.to_json(*options)
|
55
|
-
end
|
65
|
+
payment = new(data["Amount"])
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
payment.service_tax_amount = data["ServiceTaxAmount"]
|
68
|
+
payment.installments = data["Installments"]
|
69
|
+
payment.interest = data["Interest"]
|
70
|
+
payment.capture = data["Capture"]
|
71
|
+
payment.authenticate = data["Authenticate"]
|
72
|
+
payment.recurrent = data["Recurrent"]
|
73
|
+
payment.recurrent_payment = RecurrentPayment.from_json(data["RecurrentPayment"])
|
74
|
+
payment.credit_card = CreditCard.from_json(data["CreditCard"])
|
75
|
+
payment.proof_of_sale = data["ProofOfSale"]
|
76
|
+
payment.authorization_code = data["AuthorizationCode"]
|
77
|
+
payment.soft_descriptor = data["SoftDescriptor"]
|
78
|
+
payment.return_url = data["ReturnUrl"]
|
79
|
+
payment.provider = data["Provider"]
|
80
|
+
payment.payment_id = data["PaymentId"]
|
81
|
+
payment.tid = data["Tid"]
|
82
|
+
payment.type = data["Type"]
|
83
|
+
payment.received_date = data["ReceivedDate"]
|
84
|
+
payment.captured_amount = data["CapturedAmount"]
|
85
|
+
payment.captured_date = data["CapturedDate"]
|
86
|
+
payment.currency = data["Currency"]
|
87
|
+
payment.country = data["Country"]
|
88
|
+
payment.return_code = data["ReturnCode"]
|
89
|
+
payment.return_message = data["ReturnMessage"]
|
90
|
+
payment.status = data["Status"]
|
60
91
|
|
61
|
-
|
62
|
-
|
63
|
-
payment.interest = data["Interest"] || nil
|
64
|
-
payment.capture = data["Capture"] || nil
|
65
|
-
payment.authenticate = data["Authenticate"] || nil
|
66
|
-
payment.recurrent = data["Recurrent"] || nil
|
67
|
-
payment.recurrent_payment = Cielo::RecurrentPayment.from_json(data["RecurrentPayment"] || nil)
|
68
|
-
payment.credit_card = Cielo::CreditCard.from_json(data["CreditCard"] || nil)
|
69
|
-
payment.proof_of_sale = data["ProofOfSale"] || nil
|
70
|
-
payment.authorization_code = data["AuthorizationCode"] || nil
|
71
|
-
payment.soft_descriptor = data["SoftDescriptor"] || nil
|
72
|
-
payment.return_url = data["ReturnUrl"] || nil
|
73
|
-
payment.provider = data["Provider"] || nil
|
74
|
-
payment.payment_id = data["PaymentId"] || nil
|
75
|
-
payment.tid = data["Tid"] || nil
|
76
|
-
payment.type = data["Type"] || nil
|
77
|
-
payment.received_date = data["ReceivedDate"] || nil
|
78
|
-
payment.captured_amount = data["CapturedAmount"] || nil
|
79
|
-
payment.captured_date = data["CapturedDate"] || nil
|
80
|
-
payment.currency = data["Currency"] || nil
|
81
|
-
payment.country = data["Country"] || nil
|
82
|
-
payment.return_code = data["ReturnCode"] || nil
|
83
|
-
payment.return_message = data["ReturnMessage"] || nil
|
84
|
-
payment.status = data["Status"] || nil
|
92
|
+
payment.links = data["Links"]
|
93
|
+
payment.extra_data_collection = data["ExtraDataCollection"]
|
85
94
|
|
86
|
-
|
87
|
-
|
95
|
+
payment.expiration_date = data["ExpirationDate"]
|
96
|
+
payment.url = data["Url"]
|
97
|
+
payment.number = data["Number"]
|
98
|
+
payment.bar_code_number = data["BarCodeNumber"]
|
99
|
+
payment.digitable_line = data["DigitableLine"]
|
100
|
+
payment.address = data["Address"]
|
101
|
+
payment.return_info = ReturnInfo.new(payment.return_code)
|
88
102
|
|
89
|
-
|
90
|
-
|
91
|
-
payment.number = data["Number"] || nil
|
92
|
-
payment.bar_code_number = data["BarCodeNumber"] || nil
|
93
|
-
payment.digitable_line = data["DigitableLine"] || nil
|
94
|
-
payment.address = data["Address"] || nil
|
103
|
+
payment
|
104
|
+
end
|
95
105
|
|
96
|
-
|
97
|
-
|
98
|
-
|
106
|
+
def success?
|
107
|
+
Status.success?(status)
|
108
|
+
end
|
99
109
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
110
|
+
def as_json(options={})
|
111
|
+
{
|
112
|
+
ServiceTaxAmount: @service_tax_amount,
|
113
|
+
Installments: @installments,
|
114
|
+
Interest: @interest,
|
115
|
+
Capture: @capture,
|
116
|
+
Authenticate: @authenticate,
|
117
|
+
Recurrent: @recurrent,
|
118
|
+
RecurrentPayment: @recurrent_payment,
|
119
|
+
CreditCard: @credit_card,
|
120
|
+
SoftDescriptor: @soft_descriptor,
|
121
|
+
ReturnUrl: @return_url,
|
122
|
+
Provider: @provider,
|
123
|
+
Type: @type,
|
124
|
+
Amount: @amount,
|
125
|
+
Currency: @currency,
|
126
|
+
Country: @country,
|
127
|
+
Number: @number,
|
128
|
+
BarCodeNumber: @bar_code_number,
|
129
|
+
DigitableLine: @digitable_line,
|
130
|
+
Address: @address,
|
131
|
+
ReturnInfo: @return_info
|
132
|
+
}
|
133
|
+
end
|
124
134
|
end
|
135
|
+
end
|
125
136
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Cielo
|
2
|
+
module API30
|
3
|
+
class Payment
|
4
|
+
module Status
|
5
|
+
NOT_FINISHED = 0
|
6
|
+
AUTHORIZED = 1
|
7
|
+
PAYMENT_CONFIRMED = 2
|
8
|
+
DENIED = 3
|
9
|
+
VOIDED = 10
|
10
|
+
REFUNDED = 11
|
11
|
+
PENDING = 12
|
12
|
+
ABORTED = 13
|
13
|
+
SCHEDULED = 20
|
14
|
+
|
15
|
+
def self.success?(code)
|
16
|
+
[
|
17
|
+
AUTHORIZED,
|
18
|
+
PAYMENT_CONFIRMED,
|
19
|
+
VOIDED,
|
20
|
+
REFUNDED,
|
21
|
+
PENDING,
|
22
|
+
SCHEDULED
|
23
|
+
].include?(code)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,46 +1,45 @@
|
|
1
1
|
module Cielo
|
2
|
+
module API30
|
2
3
|
class RecurrentPayment
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
INTERVAL_MONTHLY = "Monthly"
|
5
|
+
INTERVAL_BIMONTHLY = "Bimonthly"
|
6
|
+
INTERVAL_QUARTERLY = "Quarterly"
|
7
|
+
INTERVAL_SEMIANNUAL = "SemiAnnual"
|
8
|
+
INTERVAL_ANNUAL = "Annual"
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
attr_accessor :authorize_now,
|
11
|
+
:start_date,
|
12
|
+
:end_date,
|
13
|
+
:interval
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def initialize(authorize_now=true)
|
16
|
+
@authorize_now = authorize_now
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def to_json(*options)
|
20
|
+
hash = as_json(*options)
|
21
|
+
hash.reject! {|k,v| v.nil?}
|
22
|
+
hash.to_json(*options)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
recurrent_payment = RecurrentPayment.new(data["AuthorizeNow"] || false)
|
25
|
+
def self.from_json(data)
|
26
|
+
return if data.nil?
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
recurrent_payment = new(data["AuthorizeNow"])
|
29
|
+
recurrent_payment.start_date =data["StartDate"]
|
30
|
+
recurrent_payment.end_date =data["EndDate"]
|
31
|
+
recurrent_payment.interval =data["Interval"]
|
32
|
+
recurrent_payment
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
StartDate: @start_date,
|
41
|
-
EndDate: @end_date,
|
42
|
-
Interval: @interval
|
43
|
-
}
|
44
|
-
end
|
35
|
+
def as_json(options={})
|
36
|
+
{
|
37
|
+
AuthorizeNow: @authorize_now,
|
38
|
+
StartDate: @start_date,
|
39
|
+
EndDate: @end_date,
|
40
|
+
Interval: @interval
|
41
|
+
}
|
42
|
+
end
|
45
43
|
end
|
44
|
+
end
|
46
45
|
end
|
@@ -1,7 +1,15 @@
|
|
1
|
-
module Cielo
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Cielo
|
2
|
+
module API30
|
3
|
+
module Request
|
4
|
+
class CieloError < StandardError
|
5
|
+
attr_reader :code, :body
|
6
|
+
|
7
|
+
def initialize(code, body)
|
8
|
+
@code = code
|
9
|
+
@body = body
|
10
|
+
super("Error [#{code}] #{body}")
|
5
11
|
end
|
12
|
+
end
|
6
13
|
end
|
14
|
+
end
|
7
15
|
end
|
@@ -4,40 +4,44 @@ require "net/http"
|
|
4
4
|
|
5
5
|
require "cielo/api30/request/cielo_error"
|
6
6
|
|
7
|
-
module Cielo
|
8
|
-
|
7
|
+
module Cielo
|
8
|
+
module API30
|
9
|
+
module Request
|
10
|
+
class CieloRequest
|
9
11
|
attr_accessor :merchant
|
10
12
|
private :merchant
|
11
13
|
|
12
14
|
def initialize(merchant)
|
13
|
-
|
15
|
+
@merchant = merchant
|
14
16
|
end
|
15
17
|
|
16
18
|
protected
|
17
19
|
def send_request(method, uri, data=nil)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
body = nil
|
21
|
+
headers = {"User-Agent" => "CieloEcommerce/3.0 Ruby SDK",
|
22
|
+
"RequestId" => UUIDTools::UUID.random_create.to_s,
|
23
|
+
"MerchantId" => merchant.merchant_id,
|
24
|
+
"MerchantKey" => merchant.merchant_key}
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if data.nil?
|
27
|
+
headers["Content-Length"] = "0"
|
28
|
+
else
|
29
|
+
headers["Content-Type"] = "application/json"
|
30
|
+
body = data.to_json
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
34
|
+
client.use_ssl = true
|
33
35
|
|
34
|
-
|
36
|
+
response = client.send_request(method, uri.path, body, headers)
|
35
37
|
|
36
|
-
|
38
|
+
data = JSON.parse(response.body)
|
37
39
|
|
38
|
-
|
40
|
+
raise CieloError.new(data.first["Code"], data.first["Message"]) if response.code.to_i >= 400
|
39
41
|
|
40
|
-
|
42
|
+
data
|
41
43
|
end
|
44
|
+
end
|
42
45
|
end
|
46
|
+
end
|
43
47
|
end
|