lib/active_merchant/billing/gateways/webpay.rb in activemerchant-1.37.0 vs lib/active_merchant/billing/gateways/webpay.rb in activemerchant-1.38.0
- old
+ new
@@ -19,11 +19,34 @@
def capture(money, credit_card, options = {})
raise NotImplementedError.new
end
+ def refund(money, identification, options = {})
+ post = {:amount => localized_amount(money)}
+ commit_options = generate_meta(options)
+
+ MultiResponse.run do |r|
+ r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, commit_options) }
+
+ return r unless options[:refund_fee_amount]
+
+ r.process { fetch_application_fees(identification, commit_options) }
+ r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r), commit_options) }
+ end
+ end
+
def refund_fee(identification, options, meta)
raise NotImplementedError.new
+ end
+
+ def localized_amount(money, currency = self.default_currency)
+ non_fractional_currency?(currency) ? (amount(money).to_f / 100).floor : amount(money)
+ end
+
+ def add_amount(post, money, options)
+ post[:currency] = (options[:currency] || currency(money)).downcase
+ post[:amount] = localized_amount(money, post[:currency].upcase)
end
def json_error(raw_response)
msg = 'Invalid response received from the WebPay API. Please contact support@webpay.jp if you continue to receive this message.'
msg += " (The raw response returned by the API was #{raw_response.inspect})"