Module: SpreeStripe::BaseHelper

Defined in:
app/helpers/spree_stripe/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_store_publishable_api_keyString

The store's publishable Spree API key, used by the storefront JS as the X-Spree-API-Key header for v3 Store API calls. Creates one on first use when the store has no active publishable key yet.

Returns:

  • (String)


28
29
30
31
32
33
# File 'app/helpers/spree_stripe/base_helper.rb', line 28

def current_store_publishable_api_key
  @current_store_publishable_api_key ||= (
    current_store.api_keys.publishable.active.first ||
      current_store.api_keys.create!(key_type: 'publishable', name: 'Storefront')
  ).plaintext_token
end

#current_stripe_gatewayObject



3
4
5
# File 'app/helpers/spree_stripe/base_helper.rb', line 3

def current_stripe_gateway
  @current_stripe_gateway ||= current_store.stripe_gateway
end

#current_stripe_payment_sessionSpree::PaymentSessions::Stripe?

Server-side payment session for the current order, used for the legacy Rails storefront payment flow: reuses the order's pending Stripe session (keeping its amount in sync) or creates one. Memoized per request.

Returns:

  • (Spree::PaymentSessions::Stripe, nil)


11
12
13
14
15
# File 'app/helpers/spree_stripe/base_helper.rb', line 11

def current_stripe_payment_session
  return if current_stripe_gateway.nil?

  @current_stripe_payment_session ||= SpreeStripe::CreatePaymentSession.new.call(@order, current_stripe_gateway)
end

#stripe_cart_prefixed_id(order) ⇒ String

The cart-prefixed id the v3 Store API addresses carts by (e.g. cart_xxx). Must match Spree::Api::V3::CartSerializer's encoding exactly.

Returns:

  • (String)


20
21
22
# File 'app/helpers/spree_stripe/base_helper.rb', line 20

def stripe_cart_prefixed_id(order)
  "cart_#{Spree::PrefixedId::SQIDS.encode([order.id])}"
end