lib/pin_payment/refund.rb in pin_payment-0.5.1 vs lib/pin_payment/refund.rb in pin_payment-0.5.2

- old
+ new

@@ -5,12 +5,23 @@ # Uses the pin API to create a refund. # # @param [String, PinPayment::Charge] charge_or_token the charge (or token of the charge) to refund # @return [PinPayment::Refund] - def self.create charge_or_token + def self.create refund_data + charge_or_token = refund_data.is_a?(Hash) ? refund_data[:charge] : refund_data token = charge_or_token.is_a?(Charge) ? charge_or_token.token : charge_or_token - response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" }) + options = refund_data.is_a?(Hash) && refund_data[:amount] ? { amount: refund_data[:amount] } : {} + response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{token}/refunds" }, options) + new(response.delete('token'), response) + end + + # Fetches a refund using the Pin API. + # + # @param [String] token the charge token + # @return [PinPayment::Refund] + def self.find token + response = get(URI.parse(PinPayment.api_url).tap{ |uri| uri.path = "/1/refunds/#{token}" }) new(response.delete('token'), response) end # @return [Boolean] # TODO: API documentation only shows success as being "null" in the JSON