1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/app/validators/stripe_card_token_validator.rb

16 lines
523 B
Ruby
Raw Normal View History

2020-06-10 11:33:03 +02:00
# frozen_string_literal: true
2020-06-10 11:33:03 +02:00
# validates the given card token through the Stripe API
class StripeCardTokenValidator
def validate(record)
2020-06-10 11:33:03 +02:00
return unless options[:token]
res = Stripe::Token.retrieve(options[:token], api_key: Setting.get('stripe_secret_key'))
if res[:id] != options[:token]
2022-12-28 17:51:27 +01:00
record.errors.add(:card_token, "A problem occurred while retrieving the card with the specified token: #{res.id}")
end
2020-06-10 11:33:03 +02:00
rescue Stripe::InvalidRequestError => e
2022-12-28 17:51:27 +01:00
record.errors.add(:card_token, e)
end
2020-06-10 11:33:03 +02:00
end