cielo-api30 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20f781ba136cf25d034ee8ea41ef5cf619c78396
4
- data.tar.gz: 451003ab6487d5e3171fc9e10f43a7e0b51b2428
3
+ metadata.gz: 0cdfaeeda0aba249fca064cd1d2762ff8da20f82
4
+ data.tar.gz: 695539f8e9fc66e62a3a711bfcafdcb61290253d
5
5
  SHA512:
6
- metadata.gz: 4a151af06303dea750ff77c4af1bb2e2bbba3a2efd77c6709a58299bc900a22fa860d871d61b87af88bc1701eea135de7047f0bc1c31385f4c9728ebd469f64b
7
- data.tar.gz: b571b0c947f409f627fdc5697ed9536bd751a3201a38a1ad0bd7165b7f7815974c681155e52338a39761b04548b6dbc59859937f7f569ed0c76cc8bdadffb903
6
+ metadata.gz: 407905a79cb28ca242b004d3a290073ec69a00f5892a27a24f6b55af410b7e390811dad191b90bbe92575414669bba603c38981a6f8c1c5a370590f4059d8db8
7
+ data.tar.gz: 8bf935261dad5a61847bdd3752e3b74fc5ce3ddb3d1512c33a29b0775882609132241977c31d98beb9d7b78e7a833d3c0d4e25bca2ffe49dc8bbe65829130eac
@@ -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
- # 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)
17
+ module API30
18
+ def self.root_path
19
+ File.dirname __dir__
20
+ end
81
21
 
82
- request.amount = amount
83
- request.service_tax_amount = service_tax_amount
22
+ def self.client(merchant, environment = nil)
23
+ Client.new(merchant, environment)
24
+ end
84
25
 
85
- request.execute(payment_id)
86
- end
26
+ def self.merchant(merchant_id, merchant_key)
27
+ Merchant.new(merchant_id, merchant_key)
87
28
  end
29
+ end
88
30
  end
@@ -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
- attr_accessor :street,
13
- :number,
14
- :complement,
15
- :zip_code,
16
- :city,
17
- :state,
18
- :country
13
+ attr_accessor :street,
14
+ :number,
15
+ :complement,
16
+ :zip_code,
17
+ :city,
18
+ :state,
19
+ :country
19
20
 
20
- def to_json(*options)
21
- hash = as_json(*options)
22
- hash.reject! {|k,v| v.nil?}
23
- hash.to_json(*options)
24
- end
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
- def self.from_json(data)
27
- if (data != nil)
28
- address = Address.new
27
+ def self.from_json(data)
28
+ return if data.nil?
29
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
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
- 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
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
- attr_accessor :card_number,
13
- :holder,
14
- :expiration_date,
15
- :security_code,
16
- :save_card,
17
- :brand,
18
- :card_token
13
+ attr_accessor :card_number,
14
+ :holder,
15
+ :expiration_date,
16
+ :security_code,
17
+ :save_card,
18
+ :brand,
19
+ :card_token
19
20
 
20
- def initialize(args = {})
21
- @security_code = args[:security_code]
22
- @brand = args[:brand]
23
- @token = args[:token]
24
- end
21
+ def initialize(args = {})
22
+ @security_code = args[:security_code]
23
+ @brand = args[:brand]
24
+ @card_token = args[:token]
25
+ end
25
26
 
26
- def to_json(*options)
27
- hash = as_json(*options)
28
- hash.reject! {|k,v| v.nil?}
29
- hash.to_json(*options)
30
- end
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
- 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
33
+ def self.from_json(data)
34
+ return if data.nil?
42
35
 
43
- return credit_card
44
- end
45
- end
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
- 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
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
@@ -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
- attr_accessor :name,
13
- :email,
14
- :birth_date,
15
- :identity,
16
- :identity_type,
17
- :address,
18
- :delivery_adress
13
+ attr_accessor :name,
14
+ :email,
15
+ :birth_date,
16
+ :identity,
17
+ :identity_type,
18
+ :address,
19
+ :delivery_adress
19
20
 
20
- def initialize(name)
21
- @name = name
22
- end
21
+ def initialize(name)
22
+ @name = name
23
+ end
23
24
 
24
- def to_json(*options)
25
- hash = as_json(*options)
26
- hash.reject! {|k,v| v.nil?}
27
- hash.to_json(*options)
28
- end
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
- def self.from_json(data)
31
- if (data != nil)
32
- customer = Customer.new(data["Name"] || nil)
31
+ def self.from_json(data)
32
+ return if data.nil?
33
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)
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
- 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
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