Class: EasyPing::Refund

Inherits:
Action
  • Object
show all
Defined in:
lib/easy_ping/action.rb

Constant Summary

Constants inherited from Action

Action::CHANNELS

Instance Attribute Summary

Attributes inherited from Action

#client, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Action

#from_notification

Methods included from Utils

#indifferent_hash, #indifferent_params

Constructor Details

#initialize(config) ⇒ Refund

Returns a new instance of Refund.



66
67
68
69
# File 'lib/easy_ping/action.rb', line 66

def initialize(config)
  super(config)
  @settings = config.to_options
end

Class Method Details

.create(*args) ⇒ Object



62
63
64
# File 'lib/easy_ping/action.rb', line 62

def self.create(*args)
  new(EasyPing::Base.config).refund(*args)
end

Instance Method Details

#all(*args) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/easy_ping/action.rb', line 100

def all(*args)
  params = indifferent_params(args, 'charge_id')

  # map keys to API request format
  params = compile params

  # set up charge id for refund action
  @charge_id = params.delete 'charge_id'

  raw_response = client.run :get, api_endpoint, params
  EasyPing::Model::Wrapper.parse! raw_response, config
end

#find(*args) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/easy_ping/action.rb', line 91

def find(*args)
  params = indifferent_params(args, 'charge_id', 'refund_id')
  @charge_id, @refund_id = params.values_at('charge_id', 'refund_id')

  # run request and parse return result
  raw_response = client.run :get, "#{api_endpoint}/#{@refund_id}"
  EasyPing::Model::Wrapper.parse! raw_response, config
end

#refund(*args) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/easy_ping/action.rb', line 71

def refund(*args)
  amount = args.first
  if Integer === amount
    params = indifferent_params(args, 'amount', 'description', 'charge_id')
  else
    params = indifferent_params(args, 'description', 'charge_id')
  end

  # map keys to API request format and verify options
  params = compile params
  verify! params, refund_requires

  # set up charge id for refund action
  @charge_id = params.delete 'charge_id'

  # run request and parse return result
  raw_response = client.run(:post, api_endpoint, params)
  EasyPing::Model::Wrapper.parse! raw_response, config
end