Class: OffsitePayments::Integrations::Latipay::RefundInterface

Inherits:
Interface
  • Object
show all
Defined in:
lib/offsite_payments/integrations/latipay.rb

Defined Under Namespace

Classes: RefundRequestError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Interface

base_url, #initialize, #sign, #verify_signature

Constructor Details

This class inherits a constructor from OffsitePayments::Integrations::Latipay::Interface

Class Method Details

.urlObject



147
148
149
150
# File 'lib/offsite_payments/integrations/latipay.rb', line 147

def self.url
  # according to latipay doc, this url does not have a version part.
  "https://api.latipay.net/refund"
end

Instance Method Details

#call(order_id, refund_amount, reference = '') ⇒ Object

Raises:

  • (ArgumentError)


152
153
154
155
156
157
158
159
160
161
# File 'lib/offsite_payments/integrations/latipay.rb', line 152

def call(order_id, refund_amount, reference = '')
  raise ArgumentError, "Order ID must be specified" if order_id.blank?
  raise ArgumentError, "Refund amount must be specified" if refund_amount.blank?
  options = { refund_amount: refund_amount, reference: reference, user_id: @user_id, order_id: order_id }
  options[:signature] = self.sign(options)
  raw_response = ssl_post(self.class.url, options.to_json, standard_headers)
  parsed_response = parse_response(raw_response)
  validate_response(parsed_response)
  parsed_response['message']
end

#validate_response(parsed_response) ⇒ Object

Raises:



163
164
165
# File 'lib/offsite_payments/integrations/latipay.rb', line 163

def validate_response(parsed_response)
  raise RefundRequestError, parsed_response unless parsed_response['code'] == 0
end