Skip to content

Instantly share code, notes, and snippets.

View juque's full-sized avatar

Juan Pablo Aqueveque juque

View GitHub Profile
...
payload = {
name: "Descuento para #{product.title}",
discount_type: 'fixed',
tiers: [
{from: 5, to: 9, value: 1900},
{from: 9, to: nil, value: 2500}
]
}
...
shop = root.shops.first
# Buscamos el producto por su slug
product = shop.product(id: 'shinola')
# Se configura
payload = {
name: "Descuento para #{product.title}",
discount_type: 'percentage',
tiers: [
@juque
juque / example_promotion.json
Created September 24, 2021 02:39
Bootic promotion API result
{
"_actions": {
"search": {
"fields": [
{
"name": "page",
"options": null,
"prompt": "page number",
"value": null
},
Rails.application.routes.draw do
match '/auth/:provider/callback', to: 'session#create', via: [:get, :post]
get '/auth/logout', to: 'session#destroy', as: :logout
get '/dashboard', to: 'dashboard#index'
get 'session/create'
get 'dashboard/index'
get 'welcome/index'
root to: 'welcome#index'
<h1>Dashboard#index</h1>
<p><a title="Salir" href="/auth/logout">Logout</a></p>
<h2>Pedidos recientes</h2>
<ul class="orders_list">
<% @orders.each do |order| %>
<li class="order status_<%= order.status %>">
<h3><%= order.code %></h3>
<span class="total"><%= order.net_total %></span>
<h1>Welcome#index</h1>
<p><a href="/auth/bootic">Login</a></p>
class DashboardController < ApplicationController
before_action :login_required
def index
@orders = if current_shop.has?(:orders)
current_shop.orders(sort: 'updated_on.desc')
else
[]
end
end
class SessionController < ApplicationController
def create
session[:access_token] = request.env['omniauth.auth']['credentials']['token']
session[:user_name] = request.env['omniauth.auth']['info']['name']
flash[:notice] = "Welcome!"
redirect_to dashboard_index_url
end
def destroy
session.delete :access_token
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def logged_in?
session[:access_token].present?
end
def bootic_client
@bootic_client ||= BooticClient.client(:authorized, access_token: session[:access_token]) do |new_token|
Rails.logger.info "Renewed access token"
Rails.application.config.middleware.use OmniAuth::Builder do
provider :bootic, ENV['BOOTIC_CLIENT_ID'], ENV['BOOTIC_CLIENT_SECRET'], scope: 'admin'
end