cielo-api30 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cielo/api30/address.rb +53 -0
- data/lib/cielo/api30/credit_card.rb +60 -0
- data/lib/cielo/api30/customer.rb +58 -0
- data/lib/cielo/api30/payment.rb +125 -0
- data/lib/cielo/api30/recurrent_payment.rb +46 -0
- data/lib/cielo/api30/request/cielo_error.rb +7 -0
- data/lib/cielo/api30/request/cielo_request.rb +43 -0
- data/lib/cielo/api30/request/create_sale_request.rb +20 -0
- data/lib/cielo/api30/request/query_sale_request.rb +20 -0
- data/lib/cielo/api30/request/update_sale_request.rb +36 -0
- data/lib/cielo/api30/sale.rb +37 -0
- data/lib/cielo/api30/version.rb +6 -0
- data/lib/cielo/api30.rb +88 -0
- data/lib/cielo/environment.rb +31 -0
- data/lib/cielo/merchant.rb +17 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20f781ba136cf25d034ee8ea41ef5cf619c78396
|
4
|
+
data.tar.gz: 451003ab6487d5e3171fc9e10f43a7e0b51b2428
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a151af06303dea750ff77c4af1bb2e2bbba3a2efd77c6709a58299bc900a22fa860d871d61b87af88bc1701eea135de7047f0bc1c31385f4c9728ebd469f64b
|
7
|
+
data.tar.gz: b571b0c947f409f627fdc5697ed9536bd751a3201a38a1ad0bd7165b7f7815974c681155e52338a39761b04548b6dbc59859937f7f569ed0c76cc8bdadffb903
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Cielo
|
2
|
+
# Customer's address.
|
3
|
+
#
|
4
|
+
# @attr [String] street the customer's address
|
5
|
+
# @attr [String] number the customer's address number
|
6
|
+
# @attr [String] complement any complement of customer's address
|
7
|
+
# @attr [String] zip_code the zip code of customer's address
|
8
|
+
# @attr [String] city the city of customer's address
|
9
|
+
# @attr [String] state the state of customer's address
|
10
|
+
# @attr [String] country the country of customer's address
|
11
|
+
class Address
|
12
|
+
attr_accessor :street,
|
13
|
+
:number,
|
14
|
+
:complement,
|
15
|
+
:zip_code,
|
16
|
+
:city,
|
17
|
+
:state,
|
18
|
+
:country
|
19
|
+
|
20
|
+
def to_json(*options)
|
21
|
+
hash = as_json(*options)
|
22
|
+
hash.reject! {|k,v| v.nil?}
|
23
|
+
hash.to_json(*options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_json(data)
|
27
|
+
if (data != nil)
|
28
|
+
address = Address.new
|
29
|
+
|
30
|
+
address.street = data["Street"] || nil
|
31
|
+
address.number = data["Number"] || nil
|
32
|
+
address.complement = data["Complement"] || nil
|
33
|
+
address.zip_code = data["ZipCode"] || nil
|
34
|
+
address.city = data["City"] || nil
|
35
|
+
address.state = data["State"] || nil
|
36
|
+
address.country = data["Country"] || nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
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
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Cielo
|
2
|
+
# Credit card data
|
3
|
+
#
|
4
|
+
# @attr [String] card_number Credit card number
|
5
|
+
# @attr [String] holder Holder name
|
6
|
+
# @attr [String] expiration_date Credit card expiration date
|
7
|
+
# @attr [String] security_code Credit card security code
|
8
|
+
# @attr [Boolean] save_card Whether or not to save the card
|
9
|
+
# @attr [String] brand Credit card brand
|
10
|
+
# @attr [String] card_token Card token
|
11
|
+
class CreditCard
|
12
|
+
attr_accessor :card_number,
|
13
|
+
:holder,
|
14
|
+
:expiration_date,
|
15
|
+
:security_code,
|
16
|
+
:save_card,
|
17
|
+
:brand,
|
18
|
+
:card_token
|
19
|
+
|
20
|
+
def initialize(args = {})
|
21
|
+
@security_code = args[:security_code]
|
22
|
+
@brand = args[:brand]
|
23
|
+
@token = args[:token]
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(*options)
|
27
|
+
hash = as_json(*options)
|
28
|
+
hash.reject! {|k,v| v.nil?}
|
29
|
+
hash.to_json(*options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.from_json(data)
|
33
|
+
if (data != nil)
|
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
|
42
|
+
|
43
|
+
return credit_card
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def as_json(options={})
|
49
|
+
{
|
50
|
+
CardNumber: @card_number,
|
51
|
+
Holder: @holder,
|
52
|
+
ExpirationDate: @expiration_date,
|
53
|
+
SecurityCode: @security_code,
|
54
|
+
SaveCard: @save_card,
|
55
|
+
Brand: @brand,
|
56
|
+
CardToken: @card_token
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Cielo
|
2
|
+
# Customer data
|
3
|
+
#
|
4
|
+
# @attr [String] name Customer name
|
5
|
+
# @attr [String] email Customer email
|
6
|
+
# @attr [String] birthDate Customer's birth date
|
7
|
+
# @attr [String] identity Customer id
|
8
|
+
# @attr [String] identityType The type of customer id
|
9
|
+
# @attr [Address] address Customer's address
|
10
|
+
# @attr [Address] deliveryAddress The delivery address
|
11
|
+
class Customer
|
12
|
+
attr_accessor :name,
|
13
|
+
:email,
|
14
|
+
:birth_date,
|
15
|
+
:identity,
|
16
|
+
:identity_type,
|
17
|
+
:address,
|
18
|
+
:delivery_adress
|
19
|
+
|
20
|
+
def initialize(name)
|
21
|
+
@name = name
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*options)
|
25
|
+
hash = as_json(*options)
|
26
|
+
hash.reject! {|k,v| v.nil?}
|
27
|
+
hash.to_json(*options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.from_json(data)
|
31
|
+
if (data != nil)
|
32
|
+
customer = Customer.new(data["Name"] || nil)
|
33
|
+
|
34
|
+
customer.email = data["Email"] || nil
|
35
|
+
customer.birth_date = data["BirthDate"] || nil
|
36
|
+
customer.identity = data["Identity"] || nil
|
37
|
+
customer.identity_type = data["IdentityType"] || nil
|
38
|
+
customer.address = Address.from_json(data["Address"] || nil)
|
39
|
+
customer.delivery_adress = Address.from_json(data["DeliveryAddress"] || nil)
|
40
|
+
|
41
|
+
return customer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def as_json(options={})
|
47
|
+
{
|
48
|
+
Name: @name,
|
49
|
+
Email: @email,
|
50
|
+
BirthDate: @birth_date,
|
51
|
+
Identity: @identity,
|
52
|
+
IdentityType: @identity_type,
|
53
|
+
Address: @address,
|
54
|
+
DeliveryAddress: @delivery_address
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Cielo
|
2
|
+
class Payment
|
3
|
+
PAYMENTTYPE_CREDITCARD = "CreditCard"
|
4
|
+
PAYMENTTYPE_DEBITCARD = "DebitCard"
|
5
|
+
PAYMENTTYPE_ELECTRONIC_TRANSFER = "ElectronicTransfer"
|
6
|
+
PAYMENTTYPE_BOLETO = "Boleto"
|
7
|
+
|
8
|
+
PROVIDER_BRADESCO = "Bradesco"
|
9
|
+
PROVIDER_BANCO_DO_BRASIL = "BancoDoBrasil"
|
10
|
+
PROVIDER_SIMULADO = "Simulado"
|
11
|
+
|
12
|
+
attr_accessor :service_tax_amount,
|
13
|
+
:installments,
|
14
|
+
:interest,
|
15
|
+
:capture,
|
16
|
+
:authenticate,
|
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
|
45
|
+
|
46
|
+
def initialize(amount, installments: 1)
|
47
|
+
@amount = amount
|
48
|
+
@installments = installments
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_json(*options)
|
52
|
+
hash = as_json(*options)
|
53
|
+
hash.reject! {|k,v| v.nil?}
|
54
|
+
hash.to_json(*options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.from_json(data)
|
58
|
+
if (data != nil)
|
59
|
+
payment = Payment.new(data["Amount"] || nil)
|
60
|
+
|
61
|
+
payment.service_tax_amount = data["ServiceTaxAmount"] || nil
|
62
|
+
payment.installments = data["Installments"] || nil
|
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
|
85
|
+
|
86
|
+
payment.links = data["Links"] || nil
|
87
|
+
payment.extra_data_collection = data["ExtraDataCollection"] || nil
|
88
|
+
|
89
|
+
payment.expiration_date = data["ExpirationDate"] || nil
|
90
|
+
payment.url = data["Url"] || nil
|
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
|
95
|
+
|
96
|
+
return payment
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def as_json(options={})
|
102
|
+
{
|
103
|
+
ServiceTaxAmount: @service_tax_amount,
|
104
|
+
Installments: @installments,
|
105
|
+
Interest: @interest,
|
106
|
+
Capture: @capture,
|
107
|
+
Authenticate: @authenticate,
|
108
|
+
Recurrent: @recurrent,
|
109
|
+
RecurrentPayment: @recurrent_payment,
|
110
|
+
CreditCard: @credit_card,
|
111
|
+
SoftDescriptor: @soft_descriptor,
|
112
|
+
ReturnUrl: @return_url,
|
113
|
+
Provider: @provider,
|
114
|
+
Type: @type,
|
115
|
+
Amount: @amount,
|
116
|
+
Currency: @currency,
|
117
|
+
Country: @country,
|
118
|
+
Number: @number,
|
119
|
+
BarCodeNumber: @bar_code_number,
|
120
|
+
DigitableLine: @digitable_line,
|
121
|
+
Address: @address
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Cielo
|
2
|
+
class RecurrentPayment
|
3
|
+
INTERVAL_MONTHLY = "Monthly"
|
4
|
+
INTERVAL_BIMONTHLY = "Bimonthly"
|
5
|
+
INTERVAL_QUARTERLY = "Quarterly"
|
6
|
+
INTERVAL_SEMIANNUAL = "SemiAnnual"
|
7
|
+
INTERVAL_ANNUAL = "Annual"
|
8
|
+
|
9
|
+
attr_accessor :authorize_now,
|
10
|
+
:start_date,
|
11
|
+
:end_date,
|
12
|
+
:interval
|
13
|
+
|
14
|
+
def initialize(authorize_now=true)
|
15
|
+
@authorize_now = authorize_now
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json(*options)
|
19
|
+
hash = as_json(*options)
|
20
|
+
hash.reject! {|k,v| v.nil?}
|
21
|
+
hash.to_json(*options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_json(data)
|
25
|
+
if (data != nil)
|
26
|
+
recurrent_payment = RecurrentPayment.new(data["AuthorizeNow"] || false)
|
27
|
+
|
28
|
+
recurrent_payment.start_date =data["StartDate"] || nil
|
29
|
+
recurrent_payment.end_date =data["EndDate"] || nil
|
30
|
+
recurrent_payment.interval =data["Interval"] || nil
|
31
|
+
|
32
|
+
return recurrent_payment
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def as_json(options={})
|
38
|
+
{
|
39
|
+
AuthorizeNow: @authorize_now,
|
40
|
+
StartDate: @start_date,
|
41
|
+
EndDate: @end_date,
|
42
|
+
Interval: @interval
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "uuidtools"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
require "cielo/api30/request/cielo_error"
|
6
|
+
|
7
|
+
module Cielo::Request
|
8
|
+
class CieloRequest
|
9
|
+
attr_accessor :merchant
|
10
|
+
private :merchant
|
11
|
+
|
12
|
+
def initialize(merchant)
|
13
|
+
@merchant = merchant
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def send_request(method, uri, data=nil)
|
18
|
+
body = nil
|
19
|
+
headers = {"User-Agent" => "CieloEcommerce/3.0 Ruby SDK",
|
20
|
+
"RequestId" => UUIDTools::UUID.random_create.to_s,
|
21
|
+
"MerchantId" => merchant.merchant_id,
|
22
|
+
"MerchantKey" => merchant.merchant_key}
|
23
|
+
|
24
|
+
if (data == nil)
|
25
|
+
headers["Content-Length"] = "0"
|
26
|
+
else
|
27
|
+
headers["Content-Type"] = "application/json"
|
28
|
+
body = data.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
client.use_ssl = true
|
33
|
+
|
34
|
+
response = client.send_request(method, uri.path, body, headers)
|
35
|
+
|
36
|
+
data = JSON.parse(response.body)
|
37
|
+
|
38
|
+
raise CieloError, "Error [" + data[0]["Code"].to_s + "] " + data[0]["Message"] if response.code.to_i >= 400
|
39
|
+
|
40
|
+
return data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "cielo/api30/request/cielo_request"
|
2
|
+
|
3
|
+
module Cielo::Request
|
4
|
+
class CreateSaleRequest < CieloRequest
|
5
|
+
attr_accessor :environment
|
6
|
+
private :environment
|
7
|
+
|
8
|
+
def initialize(merchant, environment)
|
9
|
+
super(merchant)
|
10
|
+
|
11
|
+
@environment = environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(sale)
|
15
|
+
uri = URI.parse(@environment.api + "1/sales")
|
16
|
+
|
17
|
+
Cielo::Sale.from_json(send_request("POST", uri, sale))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "cielo/api30/request/cielo_request"
|
2
|
+
|
3
|
+
module Cielo::Request
|
4
|
+
class QuerySaleRequest < CieloRequest
|
5
|
+
attr_accessor :environment
|
6
|
+
private :environment
|
7
|
+
|
8
|
+
def initialize(merchant, environment)
|
9
|
+
super(merchant)
|
10
|
+
|
11
|
+
@environment = environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(payment_id)
|
15
|
+
uri = URI.parse(@environment.api_query + "1/sales/" + payment_id)
|
16
|
+
|
17
|
+
Cielo::Sale.from_json(send_request("GET", uri))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "cielo/api30/request/cielo_request"
|
2
|
+
|
3
|
+
module Cielo::Request
|
4
|
+
class UpdateSaleRequest < CieloRequest
|
5
|
+
attr_accessor :environment,
|
6
|
+
:type,
|
7
|
+
:service_tax_amount,
|
8
|
+
:amount
|
9
|
+
|
10
|
+
private :environment, :type
|
11
|
+
|
12
|
+
def initialize(type, merchant, environment)
|
13
|
+
super(merchant)
|
14
|
+
|
15
|
+
@environment = environment
|
16
|
+
@type = type
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(payment_id)
|
20
|
+
uri = URI.parse(@environment.api + "1/sales/" + payment_id + "/" + type)
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
if (amount != nil)
|
24
|
+
params["amount"] = amount
|
25
|
+
end
|
26
|
+
|
27
|
+
if (service_tax_amount != nil)
|
28
|
+
params["serviceTaxAmount"] = service_tax_amount
|
29
|
+
end
|
30
|
+
|
31
|
+
uri.query = URI.encode_www_form(params)
|
32
|
+
|
33
|
+
Cielo::Payment.from_json(send_request("PUT", uri))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cielo
|
2
|
+
class Sale
|
3
|
+
attr_accessor :merchant_order_id,
|
4
|
+
:customer,
|
5
|
+
:payment
|
6
|
+
|
7
|
+
def initialize(merchant_order_id)
|
8
|
+
@merchant_order_id = merchant_order_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json(*options)
|
12
|
+
hash = as_json(*options)
|
13
|
+
hash.reject! {|k,v| v.nil?}
|
14
|
+
hash.to_json(*options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_json(data)
|
18
|
+
if (data != nil)
|
19
|
+
sale = Sale.new(data["MerchantOrderId"] || nil)
|
20
|
+
|
21
|
+
sale.customer = Customer.from_json(data["Customer"] || nil)
|
22
|
+
sale.payment = Payment.from_json(data["Payment"] || nil)
|
23
|
+
|
24
|
+
return sale
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def as_json(options={})
|
30
|
+
{
|
31
|
+
MerchantOrderId: @merchant_order_id,
|
32
|
+
Customer: @customer,
|
33
|
+
Payment: @payment
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/cielo/api30.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require "cielo/environment"
|
2
|
+
require "cielo/merchant"
|
3
|
+
|
4
|
+
require "cielo/api30/address"
|
5
|
+
require "cielo/api30/credit_card"
|
6
|
+
require "cielo/api30/customer"
|
7
|
+
require "cielo/api30/payment"
|
8
|
+
require "cielo/api30/recurrent_payment"
|
9
|
+
require "cielo/api30/sale"
|
10
|
+
|
11
|
+
require "cielo/api30/request/create_sale_request"
|
12
|
+
require "cielo/api30/request/query_sale_request"
|
13
|
+
require "cielo/api30/request/update_sale_request"
|
14
|
+
|
15
|
+
module Cielo
|
16
|
+
# The Cielo API SDK front-end
|
17
|
+
class API30
|
18
|
+
attr_accessor :merchant, :environment
|
19
|
+
private :merchant, :environment
|
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)
|
81
|
+
|
82
|
+
request.amount = amount
|
83
|
+
request.service_tax_amount = service_tax_amount
|
84
|
+
|
85
|
+
request.execute(payment_id)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Cielo
|
2
|
+
# API Environment URLs
|
3
|
+
#
|
4
|
+
# @attr [String] api API URL
|
5
|
+
# @attr [String] apiQuery API Query URL
|
6
|
+
class Environment
|
7
|
+
attr_accessor :api,
|
8
|
+
:api_query
|
9
|
+
|
10
|
+
def initialize(api, api_query)
|
11
|
+
@api = api
|
12
|
+
@api_query = api_query
|
13
|
+
end
|
14
|
+
|
15
|
+
# The production environment
|
16
|
+
#
|
17
|
+
# @return [Environment] a configured Environment for production
|
18
|
+
def self.production()
|
19
|
+
return Environment.new("https://api.cieloecommerce.cielo.com.br/",
|
20
|
+
"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
|
+
return Environment.new("https://apisandbox.cieloecommerce.cielo.com.br/",
|
28
|
+
"https://apiquerysandbox.cieloecommerce.cielo.com.br/")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Cielo
|
2
|
+
# Merchant identification on Cielo
|
3
|
+
#
|
4
|
+
# @attr [String] merchant_id the merchant identification number
|
5
|
+
# @attr [String] merchant_key the merchant identification key
|
6
|
+
class Merchant
|
7
|
+
attr_accessor :merchant_id,
|
8
|
+
:merchant_key
|
9
|
+
|
10
|
+
# @param merchant_id [String] the merchant identification number
|
11
|
+
# @param merchant_key [String] the merchant identification key
|
12
|
+
def initialize(merchant_id, merchant_key)
|
13
|
+
@merchant_id = merchant_id
|
14
|
+
@merchant_key = merchant_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cielo-api30
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cielo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: uuidtools
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
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.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
description: Integração com a API 3.0 da Cielo
|
70
|
+
email:
|
71
|
+
- desenvolvedores@cielo.com.br
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/cielo/api30.rb
|
77
|
+
- lib/cielo/api30/address.rb
|
78
|
+
- lib/cielo/api30/credit_card.rb
|
79
|
+
- lib/cielo/api30/customer.rb
|
80
|
+
- lib/cielo/api30/payment.rb
|
81
|
+
- lib/cielo/api30/recurrent_payment.rb
|
82
|
+
- lib/cielo/api30/request/cielo_error.rb
|
83
|
+
- lib/cielo/api30/request/cielo_request.rb
|
84
|
+
- lib/cielo/api30/request/create_sale_request.rb
|
85
|
+
- lib/cielo/api30/request/query_sale_request.rb
|
86
|
+
- lib/cielo/api30/request/update_sale_request.rb
|
87
|
+
- lib/cielo/api30/sale.rb
|
88
|
+
- lib/cielo/api30/version.rb
|
89
|
+
- lib/cielo/environment.rb
|
90
|
+
- lib/cielo/merchant.rb
|
91
|
+
homepage: https://github.com/developercielo/API-3.0-Ruby
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.0.0
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: SDK API 3.0 da Cielo
|
115
|
+
test_files: []
|