Class: Bs2Api::Payment::Confirmation

Inherits:
Base
  • Object
show all
Defined in:
lib/bs2_api/payment/confirmation.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#payment

Instance Method Summary collapse

Constructor Details

#initialize(payment, value: nil, client_id: Bs2Api.configuration.client_id, client_secret: Bs2Api.configuration.client_secret, proxy: nil) ⇒ Confirmation

Returns a new instance of Confirmation.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bs2_api/payment/confirmation.rb', line 6

def initialize(
  payment,
  value: nil,
  client_id: Bs2Api.configuration.client_id,
  client_secret: Bs2Api.configuration.client_secret,
  proxy: nil
)

  raise Bs2Api::Errors::ConfirmationError, 'invalid payment' unless payment.present? && payment.is_a?(Bs2Api::Entities::Payment)
  raise Bs2Api::Errors::ConfirmationError, 'invalid value' unless value.to_f.positive?

  @payment = payment
  @value = value.to_f
  @client_id = client_id
  @client_secret = client_secret
  @proxy = proxy
end

Instance Attribute Details

#successObject (readonly)

Returns the value of attribute success.



4
5
6
# File 'lib/bs2_api/payment/confirmation.rb', line 4

def success
  @success
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
# File 'lib/bs2_api/payment/confirmation.rb', line 24

def call
  response = post_request
  raise Bs2Api::Errors::ConfirmationError, ::Util::Response.parse_error(response) unless response.accepted?

  @success = true
  self
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bs2_api/payment/confirmation.rb', line 32

def success?
  !!@success
end