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

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.