Sha256: 0046a1351e8caae44c7a59e05f08dbf5c95937dfa7a451576ae99293fe0f6de5

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

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.5'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stripe-opal-0.0.5 lib/stripe-opal.rb