Last active
November 13, 2016 22:58
-
-
Save gipsh/1858f022664b7fafea8e4ea3f82139bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you want to integrate your dashboard with mercadopago. | |
Do you need to add `mercadopago` gem to your Gemfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mercadopago' | |
SCHEDULER.every '5m' do | |
client_id = settings.mercadopago['client_id'] | |
client_secret = settings.mercadopago['client_secret'] | |
client_uid = settings.mercadopago['client_uid'] | |
client = MercadoPago::Client.new(client_id, client_secret) | |
response = MercadoPago::Request.wrap_get("/users/#{client_uid}/mercadopago_account/balance?access_token=#{client.access_token}", { accept: 'application/json' }) | |
total_amount = response['total_amount'] | |
send_event('balance', { current: total_amount, last: total_amount }) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the total orders from this week and also from the week before | |
require 'mercadopago' | |
SCHEDULER.every '5m', :first_in => 0 do |job| | |
client_id = settings.mercadopago['client_id'] | |
client_secret = settings.mercadopago['client_secret'] | |
client_uid = settings.mercadopago['client_uid'] | |
client = MercadoPago::Client.new(client_id, client_secret) | |
filters = {limit: "100", status: "approved", operation_type: "regular_payment", range: "date_created", | |
begin_date: "NOW-7DAY", end_date: "NOW" } | |
search = client.search(filters) | |
orders_this_week = search['results'].count | |
filters = {limit: "100", status: "approved", operation_type: "regular_payment", range: "date_created", | |
begin_date: "NOW-14DAY", end_date: "NOW-7DAY" } | |
search = client.search(filters) | |
orders_last_week = search['results'].count | |
send_event('valuation', { current: orders_this_week, last: orders_last_week }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment