Class: Braspag::API

Inherits:
Object
  • Object
show all
Defined in:
lib/braspag/api.rb,
lib/braspag/api/version.rb

Overview

The Braspag API SDK front-end

Constant Summary collapse

VERSION =

Versão da gem

"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merchant, environment = nil) ⇒ API

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

Parameters:

  • merchant (Merchant)

    The merchant credentials

  • environment (Environment) (defaults to: nil)

    The environment



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/braspag/api.rb', line 26

def initialize(
    merchant,
    environment = nil)

    if (environment == nil)
        environment = Environment.production()
    end

    @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.



18
19
20
# File 'lib/braspag/api.rb', line 18

def environment=(value)
  @environment = value
end

#merchant=(value) ⇒ Object

Sets the attribute merchant

Parameters:

  • value

    the value to set the attribute merchant to.



18
19
20
# File 'lib/braspag/api.rb', line 18

def merchant=(value)
  @merchant = value
end

Instance Method Details

#cancel_payment(payment_id, amount = nil) ⇒ Payment

Cancel a Payment on Braspag by paymentId and speficying the amount

Parameters:

  • paymentId (String)

    The paymentId to be queried

  • amount (Integer) (defaults to: nil)

    Order value in cents

Returns:

  • (Payment)

    The cancelled payment



64
65
66
67
68
69
70
# File 'lib/braspag/api.rb', line 64

def cancel_payment(payment_id, amount=nil)
    request = Braspag::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 Braspag by paymentId and specifying the amount and the serviceTaxAmount

Parameters:

  • paymentId (String)

    The paymentId to be captured

  • amount (Integer) (defaults to: nil)

    Amount of the authorization to be captured

  • serviceTaxAmount (Integer)

    Amount of the authorization should be destined for the service charge

Returns:

  • (Payment)

    The captured payment



79
80
81
82
83
84
85
86
# File 'lib/braspag/api.rb', line 79

def capture_sale(payment_id, amount=nil, service_tax_amount=nil)
    request = Braspag::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 Braspag.

Parameters:

  • sale (Sale)

    The preconfigured Sale

Returns:

  • (Sale)

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



43
44
45
46
47
# File 'lib/braspag/api.rb', line 43

def create_sale(sale)
    request = Braspag::Request::CreateSaleRequest.new(merchant, environment)

    request.execute(sale)
end

#get_sale(payment_id) ⇒ Sale

Query a Sale on Braspag by paymentId

Parameters:

  • paymentId (String)

    The paymentId to be queried

Returns:

  • (Sale)

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



53
54
55
56
57
# File 'lib/braspag/api.rb', line 53

def get_sale(payment_id)
    request = Braspag::Request::QuerySaleRequest.new(merchant, environment)

    request.execute(payment_id)
end