Project

polar_sh

0.01
No release in over a year
Interact with the Polar API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 0.6
~> 5
 Project Readme

Polar.sh Ruby API client

Still in development. API docs

Installation

bundle add polar_sh

Usage

Polar.configure do |config|
  config.access_token = "polar_..."
  config.sandbox = true
  config.webhook_secret = "xyz..."
end

class CheckoutsController < ApplicationController
  def create
    checkout = Polar::Checkout::Custom.create(
      customer_email: current_user.email,
      metadata: {user_id: current_user.id},
      product_id: "xyzxyz-...",
      success_url: root_path
    )

    redirect_to(checkout.url, allow_other_host: true)
  end
end

class WebhooksController < ApplicationController
  skip_before_action :verify_authenticity_token

  def handle_polar
    event = Polar::Webhook.verify(request)

    Rails.logger.info("Received Polar webhook: #{event.type}")

    case event.type
    when "order.created"
      process_order(event.object)
    end

    head(:ok)
  end

  private

  def process_order(order)
    return unless order.status == "paid"
    return unless (user = User.find(order.metadata[:user_id]))

    # ...
  end
end

API versioning

Requests are pinned to the 2026-04 Polar API version by default, sent as a Polar-Version header. Pin to a different version with:

Polar.configure do |config|
  config.api_version = "2026-10"
end

Setting api_version to nil omits the header. Polar then falls back to whichever version is current, which changes at each quarterly release, so pinning is recommended.

Development

bundle
rake spec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mikker/polar_sh.

License

The gem is available as open source under the terms of the MIT License.