solidus_open_pay 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.circleci/config.yml +61 -0
 - data/.github/stale.yml +1 -0
 - data/.gitignore +22 -0
 - data/.rspec +2 -0
 - data/.rubocop.yml +249 -0
 - data/Gemfile +49 -0
 - data/LICENSE +26 -0
 - data/README.md +37 -0
 - data/Rakefile +11 -0
 - data/app/assets/images/solidus_open_pay/.gitkeep +0 -0
 - data/app/assets/javascripts/spree/backend/solidus_open_pay.js +2 -0
 - data/app/assets/javascripts/spree/frontend/solidus_open_pay.js +2 -0
 - data/app/assets/stylesheets/spree/backend/solidus_openpay.css +3 -0
 - data/app/assets/stylesheets/spree/frontend/solidus_openpay.css +3 -0
 - data/app/models/concerns/solidus_open_pay/attributes_access.rb +83 -0
 - data/app/models/solidus_open_pay/builders/charge.rb +72 -0
 - data/app/models/solidus_open_pay/gateway.rb +98 -0
 - data/app/models/solidus_open_pay/payment_method.rb +30 -0
 - data/app/models/solidus_open_pay/payment_source.rb +25 -0
 - data/app/models/solidus_open_pay/response.rb +63 -0
 - data/app/views/checkouts/payment/_open_pay.html.erb +171 -0
 - data/app/views/spree/admin/payments/source_views/_open_pay.html.erb +21 -0
 - data/app/views/spree/api/payments/source_views/_open_pay.json.jbuilder +3 -0
 - data/app/views/spree/checkout/payment/_open_pay.html.erb +183 -0
 - data/bin/console +17 -0
 - data/bin/rails +7 -0
 - data/bin/rails-engine +13 -0
 - data/bin/rails-sandbox +16 -0
 - data/bin/rake +7 -0
 - data/bin/sandbox +86 -0
 - data/bin/setup +8 -0
 - data/config/locales/en.yml +44 -0
 - data/config/locales/es-MX.yml +44 -0
 - data/config/locales/es.yml +44 -0
 - data/config/routes.rb +7 -0
 - data/db/migrate/20241120003957_add_open_pay_sources.rb +23 -0
 - data/lib/generators/solidus_open_pay/install/install_generator.rb +113 -0
 - data/lib/generators/solidus_open_pay/install/templates/config/initializers/solidus_open_pay.rb +6 -0
 - data/lib/solidus_open_pay/configuration.rb +27 -0
 - data/lib/solidus_open_pay/engine.rb +38 -0
 - data/lib/solidus_open_pay/testing_support/factories.rb +34 -0
 - data/lib/solidus_open_pay/version.rb +5 -0
 - data/lib/solidus_open_pay.rb +5 -0
 - data/lib/tasks/solidus_openpay_tasks.rake +6 -0
 - data/solidus_open_pay.gemspec +39 -0
 - data/spec/models/solidus_open_pay/payment_method_spec.rb +417 -0
 - data/spec/solidus_open_pay_spec_helper.rb +5 -0
 - data/spec/spec_helper.rb +34 -0
 - data/spec/support/factory_bot.rb +10 -0
 - data/spec/support/solidus.rb +18 -0
 - data/spec/support/solidus_open_pay/gateway_helpers.rb +27 -0
 - metadata +197 -0
 
| 
         @@ -0,0 +1,98 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'openpay'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module SolidusOpenPay
         
     | 
| 
      
 6 
     | 
    
         
            +
              class Gateway
         
     | 
| 
      
 7 
     | 
    
         
            +
                attr_reader :client
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize(options)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @client = OpenpayApi.new(
         
     | 
| 
      
 11 
     | 
    
         
            +
                    options.fetch(:merchant_id, nil),
         
     | 
| 
      
 12 
     | 
    
         
            +
                    options.fetch(:private_key, nil),
         
     | 
| 
      
 13 
     | 
    
         
            +
                    options.fetch(:country, nil).presence || !options.fetch(:test_mode, nil)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  )
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @options = options
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def authorize(amount_in_cents, source, options = {})
         
     | 
| 
      
 19 
     | 
    
         
            +
                  resource_builder = ::SolidusOpenPay::Builders::Charge.new(
         
     | 
| 
      
 20 
     | 
    
         
            +
                    source: source,
         
     | 
| 
      
 21 
     | 
    
         
            +
                    amount: amount_in_cents,
         
     | 
| 
      
 22 
     | 
    
         
            +
                    options: options
         
     | 
| 
      
 23 
     | 
    
         
            +
                  )
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  response = client.create(:charges).create(
         
     | 
| 
      
 26 
     | 
    
         
            +
                    resource_builder.payload
         
     | 
| 
      
 27 
     | 
    
         
            +
                  )
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  source&.update(
         
     | 
| 
      
 30 
     | 
    
         
            +
                    authorization_id: response.try(:[], 'id')
         
     | 
| 
      
 31 
     | 
    
         
            +
                  )
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(response)
         
     | 
| 
      
 34 
     | 
    
         
            +
                rescue ::OpenpayTransactionException,
         
     | 
| 
      
 35 
     | 
    
         
            +
                       ::OpenpayException,
         
     | 
| 
      
 36 
     | 
    
         
            +
                       ::OpenpayConnectionException => e
         
     | 
| 
      
 37 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(e)
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def capture(_amount_in_cents, authorization_id, options = {})
         
     | 
| 
      
 41 
     | 
    
         
            +
                  response = client.create(:charges).capture(
         
     | 
| 
      
 42 
     | 
    
         
            +
                    authorization_id
         
     | 
| 
      
 43 
     | 
    
         
            +
                  )
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  json_response = JSON.parse(response.body)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  source = options[:originator].try(:source)
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  source&.update(
         
     | 
| 
      
 49 
     | 
    
         
            +
                    capture_id: json_response.try(:[], 'id'),
         
     | 
| 
      
 50 
     | 
    
         
            +
                    authorization_id: json_response.try(:[], 'authorization')
         
     | 
| 
      
 51 
     | 
    
         
            +
                  )
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(json_response)
         
     | 
| 
      
 54 
     | 
    
         
            +
                rescue ::OpenpayTransactionException,
         
     | 
| 
      
 55 
     | 
    
         
            +
                       ::OpenpayException,
         
     | 
| 
      
 56 
     | 
    
         
            +
                       ::OpenpayConnectionException => e
         
     | 
| 
      
 57 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(e)
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                def purchase(amount_in_cents, source, options = {})
         
     | 
| 
      
 61 
     | 
    
         
            +
                  resource_builder = ::SolidusOpenPay::Builders::Charge.new(
         
     | 
| 
      
 62 
     | 
    
         
            +
                    source: source,
         
     | 
| 
      
 63 
     | 
    
         
            +
                    amount: amount_in_cents,
         
     | 
| 
      
 64 
     | 
    
         
            +
                    options: options.merge({ capture: true })
         
     | 
| 
      
 65 
     | 
    
         
            +
                  )
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  response = client.create(:charges).create(
         
     | 
| 
      
 68 
     | 
    
         
            +
                    resource_builder.payload
         
     | 
| 
      
 69 
     | 
    
         
            +
                  )
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  source&.update(
         
     | 
| 
      
 72 
     | 
    
         
            +
                    capture_id: response.try(:[], 'id'),
         
     | 
| 
      
 73 
     | 
    
         
            +
                    authorization_id: response.try(:[], 'authorization')
         
     | 
| 
      
 74 
     | 
    
         
            +
                  )
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(response)
         
     | 
| 
      
 77 
     | 
    
         
            +
                rescue ::OpenpayTransactionException,
         
     | 
| 
      
 78 
     | 
    
         
            +
                       ::OpenpayException,
         
     | 
| 
      
 79 
     | 
    
         
            +
                       ::OpenpayConnectionException => e
         
     | 
| 
      
 80 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(e)
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                def void(authorization_id, _options = {})
         
     | 
| 
      
 84 
     | 
    
         
            +
                  response = client.create(:charges).refund(
         
     | 
| 
      
 85 
     | 
    
         
            +
                    authorization_id,
         
     | 
| 
      
 86 
     | 
    
         
            +
                    {}
         
     | 
| 
      
 87 
     | 
    
         
            +
                  )
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(response)
         
     | 
| 
      
 90 
     | 
    
         
            +
                rescue ::OpenpayTransactionException,
         
     | 
| 
      
 91 
     | 
    
         
            +
                       ::OpenpayException,
         
     | 
| 
      
 92 
     | 
    
         
            +
                       ::OpenpayConnectionException => e
         
     | 
| 
      
 93 
     | 
    
         
            +
                  SolidusOpenPay::Response.build(e)
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                alias_method :credit, :void
         
     | 
| 
      
 97 
     | 
    
         
            +
              end
         
     | 
| 
      
 98 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module SolidusOpenPay
         
     | 
| 
      
 4 
     | 
    
         
            +
              class PaymentMethod < ::Spree::PaymentMethod
         
     | 
| 
      
 5 
     | 
    
         
            +
                preference :merchant_id, :string
         
     | 
| 
      
 6 
     | 
    
         
            +
                preference :private_key, :string
         
     | 
| 
      
 7 
     | 
    
         
            +
                preference :public_key, :string
         
     | 
| 
      
 8 
     | 
    
         
            +
                preference :country, :string
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def partial_name
         
     | 
| 
      
 11 
     | 
    
         
            +
                  'open_pay'
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def source_required?
         
     | 
| 
      
 15 
     | 
    
         
            +
                  true
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def payment_source_class
         
     | 
| 
      
 19 
     | 
    
         
            +
                  PaymentSource
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def gateway_class
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Gateway
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def payment_profiles_supported?
         
     | 
| 
      
 27 
     | 
    
         
            +
                  false
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module SolidusOpenPay
         
     | 
| 
      
 4 
     | 
    
         
            +
              class PaymentSource < ::Spree::PaymentSource
         
     | 
| 
      
 5 
     | 
    
         
            +
                include ::SolidusOpenPay::AttributesAccess
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                self.table_name = 'open_pay_sources'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def actions
         
     | 
| 
      
 10 
     | 
    
         
            +
                  %w[capture void credit]
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def can_capture?(payment)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  payment.pending? || payment.checkout?
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def can_void?(payment)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  can_capture?(payment)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                def can_credit?(payment)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  payment.completed? && payment.credit_allowed.positive?
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'active_merchant/billing/response'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module SolidusOpenPay
         
     | 
| 
      
 6 
     | 
    
         
            +
              class Response < ::ActiveMerchant::Billing::Response
         
     | 
| 
      
 7 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 8 
     | 
    
         
            +
                  private :new
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  def build(result)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    if success?(result)
         
     | 
| 
      
 12 
     | 
    
         
            +
                      build_success(result)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    else
         
     | 
| 
      
 14 
     | 
    
         
            +
                      build_failure(result)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    end
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  private
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  def success?(result)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    result.try(:[], 'id').present? &&
         
     | 
| 
      
 22 
     | 
    
         
            +
                      result.try(:[], 'error_message').blank?
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def build_success(result)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    new(
         
     | 
| 
      
 27 
     | 
    
         
            +
                      true,
         
     | 
| 
      
 28 
     | 
    
         
            +
                      result['description'],
         
     | 
| 
      
 29 
     | 
    
         
            +
                      result,
         
     | 
| 
      
 30 
     | 
    
         
            +
                      authorization: result['id']
         
     | 
| 
      
 31 
     | 
    
         
            +
                    )
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  def build_failure(result)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    response = JSON.parse(result.json_body)
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    new(
         
     | 
| 
      
 38 
     | 
    
         
            +
                      false,
         
     | 
| 
      
 39 
     | 
    
         
            +
                      error_message(response),
         
     | 
| 
      
 40 
     | 
    
         
            +
                      response,
         
     | 
| 
      
 41 
     | 
    
         
            +
                      {}
         
     | 
| 
      
 42 
     | 
    
         
            +
                    )
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  def error_message(result)
         
     | 
| 
      
 46 
     | 
    
         
            +
                    error_message = transaction_error_message(result['error_code'])
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    [
         
     | 
| 
      
 49 
     | 
    
         
            +
                      error_message.to_s,
         
     | 
| 
      
 50 
     | 
    
         
            +
                      "(#{result['error_code']})"
         
     | 
| 
      
 51 
     | 
    
         
            +
                    ].join(' ')
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  def transaction_error_message(error_code)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    I18n.t(
         
     | 
| 
      
 56 
     | 
    
         
            +
                      error_code,
         
     | 
| 
      
 57 
     | 
    
         
            +
                      scope: 'solidus_open_pay.gateway_rejection_reasons',
         
     | 
| 
      
 58 
     | 
    
         
            +
                      default: 'Error'
         
     | 
| 
      
 59 
     | 
    
         
            +
                    )
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,171 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <div class="gateway-payment-method flex flex-col gap-y-6 w-full">
         
     | 
| 
      
 2 
     | 
    
         
            +
              <% param_prefix = "payment_source[#{payment_method.id}]" %>
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              <%= hidden_field_tag :token_id,
         
     | 
| 
      
 5 
     | 
    
         
            +
                                   '',
         
     | 
| 
      
 6 
     | 
    
         
            +
                                   id: 'token_id',
         
     | 
| 
      
 7 
     | 
    
         
            +
                                   name: "payment_source[#{payment_method.id}][token_id]",
         
     | 
| 
      
 8 
     | 
    
         
            +
                                   'data-openpay-card': 'token_id' %>
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              <div class='text-input' data-hook='card_name'>
         
     | 
| 
      
 11 
     | 
    
         
            +
                <%= label_tag "name_on_card_#{payment_method.id}",
         
     | 
| 
      
 12 
     | 
    
         
            +
                              t('spree.name_on_card') %>
         
     | 
| 
      
 13 
     | 
    
         
            +
                <%= text_field_tag "#{param_prefix}[name]",
         
     | 
| 
      
 14 
     | 
    
         
            +
                                   '',
         
     | 
| 
      
 15 
     | 
    
         
            +
                                   {
         
     | 
| 
      
 16 
     | 
    
         
            +
                                     id: "name_on_card_#{payment_method.id}",
         
     | 
| 
      
 17 
     | 
    
         
            +
                                     autocomplete: 'cc-name',
         
     | 
| 
      
 18 
     | 
    
         
            +
                                     class: 'cardName',
         
     | 
| 
      
 19 
     | 
    
         
            +
                                     placeholder: I18n.t('solidus_open_pay.form.placeholder.card_name'),
         
     | 
| 
      
 20 
     | 
    
         
            +
                                     'data-openpay-card': 'holder_name'
         
     | 
| 
      
 21 
     | 
    
         
            +
                                    } %>
         
     | 
| 
      
 22 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              <div class='text-input card_number' data-hook='card_number'>
         
     | 
| 
      
 25 
     | 
    
         
            +
                <%= label_tag 'card_number',
         
     | 
| 
      
 26 
     | 
    
         
            +
                          t('spree.card_number') %>
         
     | 
| 
      
 27 
     | 
    
         
            +
                <%= text_field_tag "#{param_prefix}[number]",
         
     | 
| 
      
 28 
     | 
    
         
            +
                                   '',
         
     | 
| 
      
 29 
     | 
    
         
            +
                                   {
         
     | 
| 
      
 30 
     | 
    
         
            +
                                     id: 'card_number',
         
     | 
| 
      
 31 
     | 
    
         
            +
                                     class: 'required',
         
     | 
| 
      
 32 
     | 
    
         
            +
                                      size: 19,
         
     | 
| 
      
 33 
     | 
    
         
            +
                                      maxlength: 19,
         
     | 
| 
      
 34 
     | 
    
         
            +
                                      autocomplete: 'cc-number',
         
     | 
| 
      
 35 
     | 
    
         
            +
                                      type: 'tel',
         
     | 
| 
      
 36 
     | 
    
         
            +
                                      placeholder: I18n.t('solidus_open_pay.form.placeholder.card_number'),
         
     | 
| 
      
 37 
     | 
    
         
            +
                                      'data-openpay-card': 'card_number'
         
     | 
| 
      
 38 
     | 
    
         
            +
                                    } %>
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                <span id='card_type' style='display:none;'>
         
     | 
| 
      
 41 
     | 
    
         
            +
                  ( <span id='looks_like' ><%= t('spree.card_type_is') %> <span id='type'></span></span>
         
     | 
| 
      
 42 
     | 
    
         
            +
                    <span id='unrecognized'><%= t('spree.unrecognized_card_type') %></span>
         
     | 
| 
      
 43 
     | 
    
         
            +
                  )
         
     | 
| 
      
 44 
     | 
    
         
            +
                </span>
         
     | 
| 
      
 45 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              <div class='flex flex-col gap-6 sm:flex-row'>
         
     | 
| 
      
 48 
     | 
    
         
            +
                <div class='text-input w-full card_expiration' data-hook='card_expiration'>
         
     | 
| 
      
 49 
     | 
    
         
            +
                  <%= label_tag 'card_expiry',
         
     | 
| 
      
 50 
     | 
    
         
            +
                                t('spree.expiration') %>
         
     | 
| 
      
 51 
     | 
    
         
            +
                  <%= text_field_tag "#{param_prefix}[expiration_month]",
         
     | 
| 
      
 52 
     | 
    
         
            +
                                     '',
         
     | 
| 
      
 53 
     | 
    
         
            +
                                     id: 'card-expiry-month',
         
     | 
| 
      
 54 
     | 
    
         
            +
                                     class: 'w-auto required text-center',
         
     | 
| 
      
 55 
     | 
    
         
            +
                                     placeholder: 'MM',
         
     | 
| 
      
 56 
     | 
    
         
            +
                                     maxlength: 2,
         
     | 
| 
      
 57 
     | 
    
         
            +
                                     type: 'tel',
         
     | 
| 
      
 58 
     | 
    
         
            +
                                     data: { 'openpay-card': 'expiration_month' } %>
         
     | 
| 
      
 59 
     | 
    
         
            +
                  <span> / </span>
         
     | 
| 
      
 60 
     | 
    
         
            +
                  <%= text_field_tag "#{param_prefix}[expiration_year]",
         
     | 
| 
      
 61 
     | 
    
         
            +
                                     '',
         
     | 
| 
      
 62 
     | 
    
         
            +
                                     id: 'card-expiry-year',
         
     | 
| 
      
 63 
     | 
    
         
            +
                                     class: 'w-auto required text-center',
         
     | 
| 
      
 64 
     | 
    
         
            +
                                     placeholder: 'YY',
         
     | 
| 
      
 65 
     | 
    
         
            +
                                     maxlength: 2,
         
     | 
| 
      
 66 
     | 
    
         
            +
                                     type: 'tel',
         
     | 
| 
      
 67 
     | 
    
         
            +
                                     data: { 'openpay-card': 'expiration_year' } %>
         
     | 
| 
      
 68 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                <div class='text-input w-full card_code' data-hook='card_code'>
         
     | 
| 
      
 71 
     | 
    
         
            +
                  <%= label_tag 'card_code',
         
     | 
| 
      
 72 
     | 
    
         
            +
                                t('spree.card_code') %>
         
     | 
| 
      
 73 
     | 
    
         
            +
                  <%= text_field_tag "#{param_prefix}[verification_value]",
         
     | 
| 
      
 74 
     | 
    
         
            +
                                     '',
         
     | 
| 
      
 75 
     | 
    
         
            +
                                     {
         
     | 
| 
      
 76 
     | 
    
         
            +
                                       id: 'card_code',
         
     | 
| 
      
 77 
     | 
    
         
            +
                                       class: 'required cardCode',
         
     | 
| 
      
 78 
     | 
    
         
            +
                                       size: 5,
         
     | 
| 
      
 79 
     | 
    
         
            +
                                       type: 'tel',
         
     | 
| 
      
 80 
     | 
    
         
            +
                                       autocomplete: 'off',
         
     | 
| 
      
 81 
     | 
    
         
            +
                                       placeholder: I18n.t('solidus_open_pay.form.placeholder.card_code'),
         
     | 
| 
      
 82 
     | 
    
         
            +
                                       'data-openpay-card': 'cvv2'
         
     | 
| 
      
 83 
     | 
    
         
            +
                                     } %>
         
     | 
| 
      
 84 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 85 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 86 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            <%= hidden_field_tag :device_session_id,
         
     | 
| 
      
 89 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 90 
     | 
    
         
            +
                                 id: 'device-session-id',
         
     | 
| 
      
 91 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][device_session_id]" %>
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            <%= hidden_field_tag :cc_brand,
         
     | 
| 
      
 94 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 95 
     | 
    
         
            +
                                 id: 'cc-brand',
         
     | 
| 
      
 96 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][brand]" %>
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            <%= hidden_field_tag :cc_points_card,
         
     | 
| 
      
 99 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 100 
     | 
    
         
            +
                                 id: 'cc-points-card',
         
     | 
| 
      
 101 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][points_card]" %>
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
            <%= hidden_field_tag :cc_points_type,
         
     | 
| 
      
 104 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 105 
     | 
    
         
            +
                                 id: 'cc-points-type',
         
     | 
| 
      
 106 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][points_type]" %>
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 109 
     | 
    
         
            +
                    src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
         
     | 
| 
      
 110 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 111 
     | 
    
         
            +
                    src='https://openpay.s3.amazonaws.com/openpay.v1.min.js'></script>
         
     | 
| 
      
 112 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 113 
     | 
    
         
            +
                    src='https://openpay.s3.amazonaws.com/openpay-data.v1.min.js'></script>
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            <script type='text/javascript'>
         
     | 
| 
      
 116 
     | 
    
         
            +
              $(document).ready(function() {
         
     | 
| 
      
 117 
     | 
    
         
            +
                // Initialize OpenPay
         
     | 
| 
      
 118 
     | 
    
         
            +
                OpenPay.setId('<%= payment_method.preferred_merchant_id %>');
         
     | 
| 
      
 119 
     | 
    
         
            +
                OpenPay.setApiKey('<%= payment_method.preferred_public_key %>');
         
     | 
| 
      
 120 
     | 
    
         
            +
                OpenPay.setSandboxMode('<%= payment_method.preferred_test_mode %>');
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                var paymentForm = document.getElementById('checkout_form_payment');
         
     | 
| 
      
 123 
     | 
    
         
            +
                var submitButton = document.querySelector('.button-primary');
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                submitButton.addEventListener('click', function(event) {
         
     | 
| 
      
 126 
     | 
    
         
            +
                  event.preventDefault();
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  // Disable submit button
         
     | 
| 
      
 129 
     | 
    
         
            +
                  submitButton.disabled = true;
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                  // Set values
         
     | 
| 
      
 132 
     | 
    
         
            +
                  var deviceDataId = OpenPay.deviceData.setup(
         
     | 
| 
      
 133 
     | 
    
         
            +
                    paymentForm,
         
     | 
| 
      
 134 
     | 
    
         
            +
                    'deviceIdField'
         
     | 
| 
      
 135 
     | 
    
         
            +
                  );
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                  document.getElementById('device-session-id').value = deviceDataId;
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                  OpenPay.token.extractFormAndCreate(
         
     | 
| 
      
 140 
     | 
    
         
            +
                    paymentForm,
         
     | 
| 
      
 141 
     | 
    
         
            +
                    sucess_callbak,
         
     | 
| 
      
 142 
     | 
    
         
            +
                    error_callbak,
         
     | 
| 
      
 143 
     | 
    
         
            +
                    OpenPay.getId()
         
     | 
| 
      
 144 
     | 
    
         
            +
                  );
         
     | 
| 
      
 145 
     | 
    
         
            +
                });
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
                var sucess_callbak = function(response) {
         
     | 
| 
      
 148 
     | 
    
         
            +
                  var data = response.data
         
     | 
| 
      
 149 
     | 
    
         
            +
                  var token_id = data.id;
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                  document.getElementById('token_id').value = token_id;
         
     | 
| 
      
 152 
     | 
    
         
            +
                  document.getElementById('cc-brand').value = data.card.brand;
         
     | 
| 
      
 153 
     | 
    
         
            +
                  document.getElementById('cc-points-card').value = data.card.points_card;
         
     | 
| 
      
 154 
     | 
    
         
            +
                  document.getElementById('cc-points-type').value = data.card.points_type;
         
     | 
| 
      
 155 
     | 
    
         
            +
                  document.getElementById('checkout_form_payment').submit();
         
     | 
| 
      
 156 
     | 
    
         
            +
                };
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                var error_callbak = function(response) {
         
     | 
| 
      
 159 
     | 
    
         
            +
                  var desc = '';
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
                  if (response.data.description != undefined) {
         
     | 
| 
      
 162 
     | 
    
         
            +
                    desc = response.data.description
         
     | 
| 
      
 163 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 164 
     | 
    
         
            +
                    desc = response.message;
         
     | 
| 
      
 165 
     | 
    
         
            +
                  };
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                  alert('ERROR [' + response.status + '] ' + desc);
         
     | 
| 
      
 168 
     | 
    
         
            +
                  submitButton.disabled = false;
         
     | 
| 
      
 169 
     | 
    
         
            +
                };
         
     | 
| 
      
 170 
     | 
    
         
            +
              })
         
     | 
| 
      
 171 
     | 
    
         
            +
             </script>
         
     | 
| 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <fieldset data-hook='credit_card'>
         
     | 
| 
      
 2 
     | 
    
         
            +
              <legend align='center'><%= I18n.t('spree.credit_card') %></legend>
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              <div class='row'>
         
     | 
| 
      
 5 
     | 
    
         
            +
                <div class='alpha six columns'>
         
     | 
| 
      
 6 
     | 
    
         
            +
                  <dl>
         
     | 
| 
      
 7 
     | 
    
         
            +
                    <dt><%= I18n.t('solidus_open_pay.admin.card.brand') %>:</dt>
         
     | 
| 
      
 8 
     | 
    
         
            +
                    <dd><%= payment.source.brand.capitalize %></dd>
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                    <dt><%= I18n.t('solidus_open_pay.admin.card.card_number') %>:</dt>
         
     | 
| 
      
 11 
     | 
    
         
            +
                    <dd><%= payment.source.display_number %></dd>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    <dt><%= I18n.t('solidus_open_pay.admin.card.token_id') %>:</dt>
         
     | 
| 
      
 14 
     | 
    
         
            +
                    <dd><%= payment.source.token_id %></dd>
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    <dt><%= I18n.t('solidus_open_pay.admin.card.device_session_id') %>:</dt>
         
     | 
| 
      
 17 
     | 
    
         
            +
                    <dd><%= payment.source.device_session_id %></dd>
         
     | 
| 
      
 18 
     | 
    
         
            +
                  </dl>
         
     | 
| 
      
 19 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 20 
     | 
    
         
            +
              </div>
         
     | 
| 
      
 21 
     | 
    
         
            +
            </fieldset>
         
     | 
| 
         @@ -0,0 +1,183 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <%= image_tag 'credit_cards/credit_card.gif', id: 'credit-card-image' %>
         
     | 
| 
      
 2 
     | 
    
         
            +
            <% param_prefix = "payment_source[#{payment_method.id}]" %>
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            <%= hidden_field_tag :token_id,
         
     | 
| 
      
 5 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 6 
     | 
    
         
            +
                                 id: 'token_id',
         
     | 
| 
      
 7 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][token_id]",
         
     | 
| 
      
 8 
     | 
    
         
            +
                                 'data-openpay-card': 'token_id' %>
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            <div class='field field-required card_name' data-hook='card_name'>
         
     | 
| 
      
 11 
     | 
    
         
            +
              <%= label_tag "name_on_card_#{payment_method.id}",
         
     | 
| 
      
 12 
     | 
    
         
            +
                            t('spree.name_on_card') %>
         
     | 
| 
      
 13 
     | 
    
         
            +
              <%= text_field_tag "#{param_prefix}[name]",
         
     | 
| 
      
 14 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 15 
     | 
    
         
            +
                                 {
         
     | 
| 
      
 16 
     | 
    
         
            +
                                   id: "name_on_card_#{payment_method.id}",
         
     | 
| 
      
 17 
     | 
    
         
            +
                                   autocomplete: 'cc-name',
         
     | 
| 
      
 18 
     | 
    
         
            +
                                   class: 'cardName',
         
     | 
| 
      
 19 
     | 
    
         
            +
                                   placeholder: I18n.t('solidus_open_pay.form.placeholder.card_name'),
         
     | 
| 
      
 20 
     | 
    
         
            +
                                   'data-openpay-card': 'holder_name'
         
     | 
| 
      
 21 
     | 
    
         
            +
                                  } %>
         
     | 
| 
      
 22 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            <div class='field field-required card_number' data-hook='card_number'>
         
     | 
| 
      
 25 
     | 
    
         
            +
              <%= label_tag 'card_number',
         
     | 
| 
      
 26 
     | 
    
         
            +
                        t('spree.card_number') %>
         
     | 
| 
      
 27 
     | 
    
         
            +
              <%= text_field_tag "#{param_prefix}[number]",
         
     | 
| 
      
 28 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 29 
     | 
    
         
            +
                                 {
         
     | 
| 
      
 30 
     | 
    
         
            +
                                   id: 'card_number',
         
     | 
| 
      
 31 
     | 
    
         
            +
                                   class: 'required',
         
     | 
| 
      
 32 
     | 
    
         
            +
                                    size: 19,
         
     | 
| 
      
 33 
     | 
    
         
            +
                                    maxlength: 19,
         
     | 
| 
      
 34 
     | 
    
         
            +
                                    autocomplete: 'cc-number',
         
     | 
| 
      
 35 
     | 
    
         
            +
                                    type: 'tel',
         
     | 
| 
      
 36 
     | 
    
         
            +
                                    placeholder: I18n.t('solidus_open_pay.form.placeholder.card_number'),
         
     | 
| 
      
 37 
     | 
    
         
            +
                                    'data-openpay-card': 'card_number'
         
     | 
| 
      
 38 
     | 
    
         
            +
                                  } %>
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              <span id='card_type' style='display:none;'>
         
     | 
| 
      
 41 
     | 
    
         
            +
                ( <span id='looks_like' ><%= t('spree.card_type_is') %> <span id='type'></span></span>
         
     | 
| 
      
 42 
     | 
    
         
            +
                  <span id='unrecognized'><%= t('spree.unrecognized_card_type') %></span>
         
     | 
| 
      
 43 
     | 
    
         
            +
                )
         
     | 
| 
      
 44 
     | 
    
         
            +
              </span>
         
     | 
| 
      
 45 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            <div class='field field-required card_expiration' data-hook='card_expiration'>
         
     | 
| 
      
 48 
     | 
    
         
            +
              <%= label_tag 'card_expiry',
         
     | 
| 
      
 49 
     | 
    
         
            +
                            t('spree.expiration') %>
         
     | 
| 
      
 50 
     | 
    
         
            +
              <%= text_field_tag "#{param_prefix}[expiration_month]",
         
     | 
| 
      
 51 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 52 
     | 
    
         
            +
                                 id: 'card-expiry-month',
         
     | 
| 
      
 53 
     | 
    
         
            +
                                 class: 'required text-center',
         
     | 
| 
      
 54 
     | 
    
         
            +
                                 placeholder: 'MM',
         
     | 
| 
      
 55 
     | 
    
         
            +
                                 maxlength: 2,
         
     | 
| 
      
 56 
     | 
    
         
            +
                                 type: 'tel',
         
     | 
| 
      
 57 
     | 
    
         
            +
                                 data: { 'openpay-card': 'expiration_month' } %>
         
     | 
| 
      
 58 
     | 
    
         
            +
              <span> / </span>
         
     | 
| 
      
 59 
     | 
    
         
            +
              <%= text_field_tag "#{param_prefix}[expiration_year]",
         
     | 
| 
      
 60 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 61 
     | 
    
         
            +
                                 id: 'card-expiry-year',
         
     | 
| 
      
 62 
     | 
    
         
            +
                                 class: 'required text-center',
         
     | 
| 
      
 63 
     | 
    
         
            +
                                 placeholder: 'YY',
         
     | 
| 
      
 64 
     | 
    
         
            +
                                 maxlength: 2,
         
     | 
| 
      
 65 
     | 
    
         
            +
                                 type: 'tel',
         
     | 
| 
      
 66 
     | 
    
         
            +
                                 data: { 'openpay-card': 'expiration_year' } %>
         
     | 
| 
      
 67 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            <div class='field field-required card_code' data-hook='card_code'>
         
     | 
| 
      
 70 
     | 
    
         
            +
              <%= label_tag 'card_code',
         
     | 
| 
      
 71 
     | 
    
         
            +
                            t('spree.card_code') %>
         
     | 
| 
      
 72 
     | 
    
         
            +
              <%= text_field_tag "#{param_prefix}[verification_value]",
         
     | 
| 
      
 73 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 74 
     | 
    
         
            +
                                 {
         
     | 
| 
      
 75 
     | 
    
         
            +
                                   id: 'card_code',
         
     | 
| 
      
 76 
     | 
    
         
            +
                                   class: 'required cardCode',
         
     | 
| 
      
 77 
     | 
    
         
            +
                                   size: 5,
         
     | 
| 
      
 78 
     | 
    
         
            +
                                   type: 'tel',
         
     | 
| 
      
 79 
     | 
    
         
            +
                                   autocomplete: 'off',
         
     | 
| 
      
 80 
     | 
    
         
            +
                                   placeholder: I18n.t('solidus_open_pay.form.placeholder.card_code'),
         
     | 
| 
      
 81 
     | 
    
         
            +
                                   'data-openpay-card': 'cvv2'
         
     | 
| 
      
 82 
     | 
    
         
            +
                                 } %>
         
     | 
| 
      
 83 
     | 
    
         
            +
              <%= link_to "(#{t('spree.what_is_this')})",
         
     | 
| 
      
 84 
     | 
    
         
            +
                          spree.cvv_path,
         
     | 
| 
      
 85 
     | 
    
         
            +
                          target: '_blank',
         
     | 
| 
      
 86 
     | 
    
         
            +
                          'data-hook': 'cvv_link',
         
     | 
| 
      
 87 
     | 
    
         
            +
                          id: 'cvv_link' %>
         
     | 
| 
      
 88 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            <%= hidden_field_tag :device_session_id,
         
     | 
| 
      
 91 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 92 
     | 
    
         
            +
                                 id: 'device-session-id',
         
     | 
| 
      
 93 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][device_session_id]" %>
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            <%= hidden_field_tag :cc_brand,
         
     | 
| 
      
 96 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 97 
     | 
    
         
            +
                                 id: 'cc-brand',
         
     | 
| 
      
 98 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][brand]" %>
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            <%= hidden_field_tag :cc_points_card,
         
     | 
| 
      
 101 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 102 
     | 
    
         
            +
                                 id: 'cc-points-card',
         
     | 
| 
      
 103 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][points_card]" %>
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            <%= hidden_field_tag :cc_points_type,
         
     | 
| 
      
 106 
     | 
    
         
            +
                                 '',
         
     | 
| 
      
 107 
     | 
    
         
            +
                                 id: 'cc-points-type',
         
     | 
| 
      
 108 
     | 
    
         
            +
                                 name: "payment_source[#{payment_method.id}][points_type]" %>
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            <br class='space' />
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            <div class='form-buttons' data-hook='buttons'>
         
     | 
| 
      
 113 
     | 
    
         
            +
              <%= submit_tag I18n.t('spree.save_and_continue'),
         
     | 
| 
      
 114 
     | 
    
         
            +
                             class: 'continue button primary',
         
     | 
| 
      
 115 
     | 
    
         
            +
                             id: 'pay-button' %>
         
     | 
| 
      
 116 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 119 
     | 
    
         
            +
                    src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
         
     | 
| 
      
 120 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 121 
     | 
    
         
            +
                    src='https://openpay.s3.amazonaws.com/openpay.v1.min.js'></script>
         
     | 
| 
      
 122 
     | 
    
         
            +
            <script type='text/javascript'
         
     | 
| 
      
 123 
     | 
    
         
            +
                    src='https://openpay.s3.amazonaws.com/openpay-data.v1.min.js'></script>
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
            <script type='text/javascript'>
         
     | 
| 
      
 126 
     | 
    
         
            +
              $(document).ready(function() {
         
     | 
| 
      
 127 
     | 
    
         
            +
                Spree.disableSaveOnClick();
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                // Initialize OpenPay
         
     | 
| 
      
 130 
     | 
    
         
            +
                OpenPay.setId('<%= payment_method.preferred_merchant_id %>');
         
     | 
| 
      
 131 
     | 
    
         
            +
                OpenPay.setApiKey('<%= payment_method.preferred_public_key %>');
         
     | 
| 
      
 132 
     | 
    
         
            +
                OpenPay.setSandboxMode('<%= payment_method.preferred_test_mode %>');
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                var paymentForm = document.getElementById('checkout_form_payment');
         
     | 
| 
      
 135 
     | 
    
         
            +
                var submitButton = document.getElementById('pay-button');
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                submitButton.addEventListener('click', function(event) {
         
     | 
| 
      
 138 
     | 
    
         
            +
                  event.preventDefault();
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                  // Disable submit button
         
     | 
| 
      
 141 
     | 
    
         
            +
                  document.getElementById('pay-button').disabled = true;
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                  // Set values
         
     | 
| 
      
 144 
     | 
    
         
            +
                  var deviceDataId = OpenPay.deviceData.setup(
         
     | 
| 
      
 145 
     | 
    
         
            +
                    paymentForm,
         
     | 
| 
      
 146 
     | 
    
         
            +
                    'deviceIdField'
         
     | 
| 
      
 147 
     | 
    
         
            +
                  );
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  document.getElementById('device-session-id').value = deviceDataId;
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                  OpenPay.token.extractFormAndCreate(
         
     | 
| 
      
 152 
     | 
    
         
            +
                    paymentForm,
         
     | 
| 
      
 153 
     | 
    
         
            +
                    sucess_callbak,
         
     | 
| 
      
 154 
     | 
    
         
            +
                    error_callbak,
         
     | 
| 
      
 155 
     | 
    
         
            +
                    OpenPay.getId()
         
     | 
| 
      
 156 
     | 
    
         
            +
                  );
         
     | 
| 
      
 157 
     | 
    
         
            +
                });
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                var sucess_callbak = function(response) {
         
     | 
| 
      
 160 
     | 
    
         
            +
                  var data = response.data
         
     | 
| 
      
 161 
     | 
    
         
            +
                  var token_id = data.id;
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                  document.getElementById('token_id').value = token_id;
         
     | 
| 
      
 164 
     | 
    
         
            +
                  document.getElementById('cc-brand').value = data.card.brand;
         
     | 
| 
      
 165 
     | 
    
         
            +
                  document.getElementById('cc-points-card').value = data.card.points_card;
         
     | 
| 
      
 166 
     | 
    
         
            +
                  document.getElementById('cc-points-type').value = data.card.points_type;
         
     | 
| 
      
 167 
     | 
    
         
            +
                  document.getElementById('checkout_form_payment').submit();
         
     | 
| 
      
 168 
     | 
    
         
            +
                };
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                var error_callbak = function(response) {
         
     | 
| 
      
 171 
     | 
    
         
            +
                  var desc = '';
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                  if (response.data.description != undefined) {
         
     | 
| 
      
 174 
     | 
    
         
            +
                    desc = response.data.description
         
     | 
| 
      
 175 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 176 
     | 
    
         
            +
                    desc = response.message;
         
     | 
| 
      
 177 
     | 
    
         
            +
                  };
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
                  alert('ERROR [' + response.status + '] ' + desc);
         
     | 
| 
      
 180 
     | 
    
         
            +
                  document.getElementById('pay-button').disabled = false;
         
     | 
| 
      
 181 
     | 
    
         
            +
                };
         
     | 
| 
      
 182 
     | 
    
         
            +
              })
         
     | 
| 
      
 183 
     | 
    
         
            +
             </script>
         
     | 
    
        data/bin/console
    ADDED
    
    | 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require "bundler/setup"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "solidus_open_pay"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            # You can add fixtures and/or initialization code here to make experimenting
         
     | 
| 
      
 9 
     | 
    
         
            +
            # with your gem easier. You can also use a different console, if you like.
         
     | 
| 
      
 10 
     | 
    
         
            +
            $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         
     | 
| 
      
 13 
     | 
    
         
            +
            # require "pry"
         
     | 
| 
      
 14 
     | 
    
         
            +
            # Pry.start
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            require "irb"
         
     | 
| 
      
 17 
     | 
    
         
            +
            IRB.start(__FILE__)
         
     | 
    
        data/bin/rails
    ADDED
    
    
    
        data/bin/rails-engine
    ADDED
    
    | 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
            # This command will automatically be run when you run "rails" with Rails gems
         
     | 
| 
      
 3 
     | 
    
         
            +
            # installed from the root of your application.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ENGINE_ROOT = File.expand_path('..', __dir__)
         
     | 
| 
      
 6 
     | 
    
         
            +
            ENGINE_PATH = File.expand_path('../lib/solidus_open_pay/engine', __dir__)
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            # Set up gems listed in the Gemfile.
         
     | 
| 
      
 9 
     | 
    
         
            +
            ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            require 'rails/all'
         
     | 
| 
      
 13 
     | 
    
         
            +
            require 'rails/engine/commands'
         
     | 
    
        data/bin/rails-sandbox
    ADDED
    
    | 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            app_root = 'sandbox'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            unless File.exist? "#{app_root}/bin/rails"
         
     | 
| 
      
 6 
     | 
    
         
            +
              warn 'Creating the sandbox app...'
         
     | 
| 
      
 7 
     | 
    
         
            +
              Dir.chdir "#{__dir__}/.." do
         
     | 
| 
      
 8 
     | 
    
         
            +
                system "#{__dir__}/sandbox" or begin
         
     | 
| 
      
 9 
     | 
    
         
            +
                  warn 'Automatic creation of the sandbox app failed'
         
     | 
| 
      
 10 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            Dir.chdir app_root
         
     | 
| 
      
 16 
     | 
    
         
            +
            exec 'bin/rails', *ARGV
         
     |