module Workarea decorate Payment, with: :klarna do decorated do embeds_one :klarna, class_name: "Workarea::Payment::Tender::Klarna", inverse_of: :payment delegate :redirect_url, to: :klarna, allow_nil: true end def set_klarna(attrs) build_klarna unless klarna klarna.attributes = attrs.slice( :authorization_token, :authorization_token_expires_at, :payment_method_category ) save end def clear_klarna self.klarna = nil end def eligible_for_klarna? address.present? && address.country&.continent.present? && address.country.continent.in?( Workarea.config.klarna_continent_keys.keys ) end end end