Class: StarkBank::BrcodePreview

Inherits:
Utils::Resource show all
Defined in:
lib/brcode_preview/brcode_preview.rb

Overview

# BrcodePreview object

A BrcodePreview is used to get information from a BR Code you received to check the informations before paying it.

## Attributes (return-only):

  • status [string]: Payment status. ex: ‘active’, ‘paid’, ‘canceled’ or ‘unknown’

  • name [string]: Payment receiver name. ex: ‘Tony Stark’

  • tax_id [string]: Payment receiver tax ID. ex: ‘012.345.678-90’

  • bank_code [string]: Payment receiver bank code. ex: ‘20018183’

  • branch_code [string]: Payment receiver branch code. ex: ‘0001’

  • account_number [string]: Payment receiver account number. ex: ‘1234567’

  • account_type [string]: Payment receiver account type. ex: ‘checking’

  • allow_change [bool]: If True, the payment is able to receive amounts that are diferent from the nominal one. ex: True or False

  • amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)

  • reconciliation_id [string]: Reconciliation ID linked to this payment. ex: ‘txId’, ‘payment-123’

Instance Attribute Summary collapse

Attributes inherited from Utils::Resource

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, reconciliation_id:) ⇒ BrcodePreview

Returns a new instance of BrcodePreview.



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

def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, reconciliation_id:)
  @status = status
  @name = name
  @tax_id = tax_id
  @bank_code = bank_code
  @branch_code = branch_code
  @account_number = 
  @account_type = 
  @allow_change = allow_change
  @amount = amount
  @reconciliation_id = reconciliation_id
end

Instance Attribute Details

#account_numberObject (readonly)

Returns the value of attribute account_number.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def 
  @account_number
end

#account_typeObject (readonly)

Returns the value of attribute account_type.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def 
  @account_type
end

#allow_changeObject (readonly)

Returns the value of attribute allow_change.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def allow_change
  @allow_change
end

#amountObject (readonly)

Returns the value of attribute amount.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def amount
  @amount
end

#bank_codeObject (readonly)

Returns the value of attribute bank_code.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def bank_code
  @bank_code
end

#branch_codeObject (readonly)

Returns the value of attribute branch_code.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def branch_code
  @branch_code
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def name
  @name
end

#reconciliation_idObject (readonly)

Returns the value of attribute reconciliation_id.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def reconciliation_id
  @reconciliation_id
end

#statusObject (readonly)

Returns the value of attribute status.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def status
  @status
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



24
25
26
# File 'lib/brcode_preview/brcode_preview.rb', line 24

def tax_id
  @tax_id
end

Class Method Details

.query(limit: nil, brcodes: nil, user: nil) ⇒ Object

# BrcodePreview is DEPRECATED: Please use PaymentPreview instead. Retrieve BrcodePreviews

Receive a generator of BrcodePreview objects previously created in the Stark Bank API

## Parameters (optional):

  • brcodes [list of strings]: List of brcodes to preview. ex: %w[00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T’Challa6009Sao Paulo62090505123456304B14A]

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • generator of BrcodePreview objects with updated attributes



49
50
51
52
53
54
55
56
57
# File 'lib/brcode_preview/brcode_preview.rb', line 49

def self.query(limit: nil, brcodes: nil, user: nil)
  warn "[DEPRECATION] `BrcodePreview` is deprecated.  Please use `PaymentPreview` instead."
  StarkBank::Utils::Rest.get_stream(
    user: user,
    limit: nil,
    brcodes: brcodes,
    **resource
  )
end

.resourceObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/brcode_preview/brcode_preview.rb', line 59

def self.resource
  {
    resource_name: 'BrcodePreview',
    resource_maker: proc { |json|
      BrcodePreview.new(
        status: json['status'],
        name: json['name'],
        tax_id: json['tax_id'],
        bank_code: json['bank_code'],
        branch_code: json['branch_code'],
        account_number: json['account_number'],
        account_type: json['account_type'],
        allow_change: json['allow_change'],
        amount: json['amount'],
        reconciliation_id: json['reconciliation_id']
      )
    }
  }
end