Class: StarkBank::PaymentPreview

Inherits:
Utils::Resource show all
Defined in:
lib/payment_preview/payment_preview.rb,
lib/payment_preview/tax_preview.rb,
lib/payment_preview/boleto_preview.rb,
lib/payment_preview/brcode_preview.rb,
lib/payment_preview/utility_preview.rb

Overview

# PaymentPreview object

A PaymentPreview is used to get information from a payment code before confirming the payment. This resource can be used to preview BR Codes and bar codes of boleto, tax and utility payments

## Attributes (return-only):

  • id [string]: Main identification of the payment. This should be the BR Code for Pix payments and lines or bar codes for payment slips. ex: ‘34191.09008 63571.277308 71444.640008 5 81960000000062’, ‘00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T’Challa6009Sao Paulo62090505123456304B14A’

  • scheduled [DateTime or string]: intended payment date. Right now, this parameter only has effect on BrcodePreviews. ex: ‘2020-04-30’

  • type [string]: Payment type. ex: ‘brcode-payment’, ‘boleto-payment’, ‘utility-payment’ or ‘tax-payment’

  • payment [BrcodePreview, BoletoPreview, UtilityPreview or TaxPreview]: Information preview of the informed payment.

Defined Under Namespace

Classes: BoletoPreview, BrcodePreview, TaxPreview, UtilityPreview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(id: nil, scheduled: nil, type: nil, payment: nil) ⇒ PaymentPreview

Returns a new instance of PaymentPreview.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/payment_preview/payment_preview.rb', line 20

def initialize(id: nil, scheduled: nil, type: nil, payment: nil)
  super(id)
  @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
  @type = type
  @payment = payment
  return if type.nil?

  resource = {
    'brcode-payment': StarkBank::PaymentPreview::BrcodePreview.resource,
    'boleto-payment': StarkBank::PaymentPreview::BoletoPreview.resource,
    'tax-payment': StarkBank::PaymentPreview::TaxPreview.resource,
    'utility-payment': StarkBank::PaymentPreview::UtilityPreview.resource
  }[type.to_sym]

  @payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/payment_preview/payment_preview.rb', line 19

def id
  @id
end

#paymentObject (readonly)

Returns the value of attribute payment.



19
20
21
# File 'lib/payment_preview/payment_preview.rb', line 19

def payment
  @payment
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



19
20
21
# File 'lib/payment_preview/payment_preview.rb', line 19

def scheduled
  @scheduled
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/payment_preview/payment_preview.rb', line 19

def type
  @type
end

Class Method Details

.create(previews, user: nil) ⇒ Object

# Create PaymentPreviews

Send a list of PaymentPreviews objects for processing in the Stark Bank API

## Parameters (required):

  • previews [list of PaymentPreviews objects]: list of PaymentPreviews objects to be created in the API

## Parameters (optional):

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

## Return:

  • list of PaymentPreviews objects with updated attributes



49
50
51
# File 'lib/payment_preview/payment_preview.rb', line 49

def self.create(previews, user: nil)
  StarkBank::Utils::Rest.post(entities: previews, user: user, **resource)
end

.resourceObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/payment_preview/payment_preview.rb', line 53

def self.resource
  {
    resource_name: 'PaymentPreview',
    resource_maker: proc { |json|
      PaymentPreview.new(
        id: json['id'],
        scheduled: json['scheduled'],
        type: json['type'],
        payment: json['payment']
      )
    }
  }
end