Class: Cielo::API30::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cielo/api30/client.rb

Overview

The Cielo API SDK front-end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merchant, environment = nil) ⇒ Client

Create an instance of API client by choosing the environment where the requests will be send

Parameters:

  • merchant (Merchant)

    The merchant credentials

  • environment (Environment) (defaults to: nil)

    The environment



13
14
15
16
17
18
# File 'lib/cielo/api30/client.rb', line 13

def initialize(merchant, environment = nil)
  environment ||= Environment.production

  @merchant = merchant
  @environment = environment
end

Instance Attribute Details

#environment=(value) ⇒ Object

Sets the attribute environment

Parameters:

  • value

    the value to set the attribute environment to.



5
6
7
# File 'lib/cielo/api30/client.rb', line 5

def environment=(value)
  @environment = value
end

#merchant=(value) ⇒ Object

Sets the attribute merchant

Parameters:

  • value

    the value to set the attribute merchant to.



5
6
7
# File 'lib/cielo/api30/client.rb', line 5

def merchant=(value)
  @merchant = value
end

Instance Method Details

#cancel_payment(payment_id, amount = nil) ⇒ Payment

Cancel a Payment on Cielo by paymentId and speficying the amount

Parameters:

  • payment_id (String)

    The payment_id to be queried

  • amount (Integer) (defaults to: nil)

    Order value in cents

Returns:

  • (Payment)

    The cancelled payment



42
43
44
45
46
47
48
# File 'lib/cielo/api30/client.rb', line 42

def cancel_payment(payment_id, amount=nil)
  request = Cielo::API30::Request::UpdateSaleRequest.new("void", merchant, environment)

  request.amount = amount

  request.execute(payment_id)
end

#capture_sale(payment_id, amount = nil, service_tax_amount = nil) ⇒ Payment

Capture a Sale on Cielo by paymentId and specifying the amount and the serviceTaxAmount

Parameters:

  • payment_id (String)

    The payment_id to be captured

  • amount (Integer) (defaults to: nil)

    Amount of the authorization to be captured

  • service_tax_amount (Integer) (defaults to: nil)

    Amount of the authorization should be destined for the service charge

Returns:

  • (Payment)

    The captured payment



57
58
59
60
61
62
63
64
# File 'lib/cielo/api30/client.rb', line 57

def capture_sale(payment_id, amount=nil, service_tax_amount=nil)
  request = Cielo::API30::Request::UpdateSaleRequest.new("capture", merchant, environment)

  request.amount = amount
  request.service_tax_amount = service_tax_amount

  request.execute(payment_id)
end

#create_sale(sale) ⇒ Sale

Send the Sale to be created and return the Sale with tid and the status returned by Cielo.

Parameters:

  • sale (Sale)

    The preconfigured Sale

Returns:

  • (Sale)

    The Sale with authorization, tid, etc. returned by Cielo.



25
26
27
# File 'lib/cielo/api30/client.rb', line 25

def create_sale(sale)
  Cielo::API30::Request::CreateSaleRequest.new(merchant, environment).execute(sale)
end

#get_sale(payment_id) ⇒ Sale

Query a Sale on Cielo by paymentId

Parameters:

  • payment_id (String)

    The payment_id to be queried

Returns:

  • (Sale)

    The Sale with authorization, tid, etc. returned by Cielo.



33
34
35
# File 'lib/cielo/api30/client.rb', line 33

def get_sale(payment_id)
  Cielo::API30::Request::QuerySaleRequest.new(merchant, environment).execute(payment_id)
end