Class: CatarseMoip::V2::Refund

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
app/models/catarse_moip/v2/refund.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment) ⇒ Refund

Returns a new instance of Refund.



15
16
17
18
# File 'app/models/catarse_moip/v2/refund.rb', line 15

def initialize(payment)
  self.payment = payment
  self.refund_options = define_refund_options
end

Instance Attribute Details

#paymentObject

Returns the value of attribute payment.



8
9
10
# File 'app/models/catarse_moip/v2/refund.rb', line 8

def payment
  @payment
end

#refund_optionsObject

Returns the value of attribute refund_options.



8
9
10
# File 'app/models/catarse_moip/v2/refund.rb', line 8

def refund_options
  @refund_options
end

Class Method Details

.start(payment) ⇒ Object



10
11
12
13
# File 'app/models/catarse_moip/v2/refund.rb', line 10

def self.start(payment)
  _instance = new(payment)
  _instance.refund
end

Instance Method Details

#define_refund_optionsObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/catarse_moip/v2/refund.rb', line 26

def define_refund_options
  if refund_method == 'BANK_ACCOUNT'
    check_bank_account!
    {
      amount: amount_to_refund,
      method: refund_method,
      refundingInstrument: refund_instrument
    }
  else
    {}
  end
end

#refundObject



20
21
22
23
24
# File 'app/models/catarse_moip/v2/refund.rb', line 20

def refund
  self.class.post("/v2/payments/#{parsed_payment_id}/refunds", {
    body: self.refund_options.to_json
  }.merge!(basic_auth_params))
end