if RUBY_PLATFORM == 'opal' require 'native' module StripeOpal class Card def self.get_token(query_selector) new(query_selector).run.promise end attr_reader :query_selector, :promise, :callback def initialize(query_selector) @query_selector = query_selector @promise = Promise.new @callback = lambda { |a, b| resolve_or_reject(a, b) } end def run `Stripe.card.createToken(document.querySelector(#{query_selector}), #{self.callback});` self end def resolve_or_reject(status, response) status, response = Native(status), Native(response) if response[:error] promise.reject response, status else promise.resolve(response, status) end end end end else module StripeOpal VERSION = '0.0.3' end end