class Braspag::API

The Braspag API SDK front-end

Constants

VERSION

Versão da gem

Attributes

environment[RW]
merchant[RW]

Public Class Methods

new( merchant, environment = nil) click to toggle source

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

@param merchant [Merchant] The merchant credentials @param environment [Environment] The environment

# File lib/braspag/api.rb, line 26
def initialize(
    merchant,
    environment = nil)

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

    @merchant = merchant
    @environment = environment
end

Public Instance Methods

cancel_payment(payment_id, amount=nil) click to toggle source

Cancel a Payment on Braspag by paymentId and speficying the amount

@param paymentId [String] The paymentId to be queried @param amount [Integer] Order value in cents @return [Payment] The cancelled payment

# 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) click to toggle source

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

@param paymentId [String] The paymentId to be captured @param amount [Integer] Amount of the authorization to be captured @param serviceTaxAmount [Integer] Amount of the authorization should be destined for the service charge @return [Payment] The captured payment

# 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) click to toggle source

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

@param sale [Sale] The preconfigured Sale @return [Sale] The Sale with authorization, tid, etc. returned by Braspag.

# 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) click to toggle source

Query a Sale on Braspag by paymentId

@param paymentId [String] The paymentId to be queried @return [Sale] The Sale with authorization, tid, etc. returned by Braspag.

# File lib/braspag/api.rb, line 53
def get_sale(payment_id)
    request = Braspag::Request::QuerySaleRequest.new(merchant, environment)

    request.execute(payment_id)
end