solidus_bling 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/spree/admin/accounts_controller.rb +54 -0
- data/app/helpers/solidus_bling/accounts_helper.rb +4 -0
- data/app/jobs/solidus_bling/application_job.rb +9 -0
- data/app/jobs/solidus_bling/contact_job.rb +22 -0
- data/app/jobs/solidus_bling/order_job.rb +22 -0
- data/app/jobs/solidus_bling/product_job.rb +13 -0
- data/app/models/solidus_bling/account.rb +9 -0
- data/app/models/{bling → solidus_bling}/api.rb +5 -5
- data/app/models/{bling/contato.rb → solidus_bling/contact.rb} +12 -12
- data/app/models/solidus_bling/event.rb +4 -0
- data/app/models/{bling/pedido.rb → solidus_bling/order.rb} +13 -18
- data/app/models/solidus_bling/payment_method.rb +5 -0
- data/app/models/{bling/produto.rb → solidus_bling/product.rb} +11 -8
- data/app/models/solidus_bling/seller.rb +5 -0
- data/app/models/solidus_bling/shipping_method.rb +5 -0
- data/app/subscribers/{bling → solidus_bling}/subscriber.rb +6 -6
- data/app/views/spree/admin/accounts/_form.html.erb +68 -0
- data/app/views/spree/admin/accounts/edit.html.erb +2 -0
- data/app/views/spree/admin/accounts/index.html.erb +13 -0
- data/app/views/spree/admin/accounts/new.html.erb +2 -0
- data/app/views/spree/admin/accounts/show.html.erb +8 -0
- data/config/routes.rb +3 -1
- data/db/migrate/{20230906141624_create_erp_accounts.rb → 20230918141419_create_solidus_bling_accounts.rb} +4 -2
- data/db/migrate/20230918141505_add_bling_order_id_to_spree_orders.rb +5 -0
- data/db/migrate/{20230906142108_create_erp_products.rb → 20230918141700_create_solidus_bling_products.rb} +3 -3
- data/db/migrate/{20230906142806_create_erp_events.rb → 20230918142547_create_solidus_bling_events.rb} +2 -2
- data/db/migrate/20230918142742_create_solidus_bling_payment_methods.rb +13 -0
- data/db/migrate/20230918142953_create_solidus_bling_sellers.rb +11 -0
- data/db/migrate/20230918143057_create_solidus_bling_shipping_methods.rb +13 -0
- data/lib/generators/solidus_bling/install/templates/initializer.rb +0 -5
- data/lib/solidus_bling/configuration.rb +3 -1
- data/lib/solidus_bling/engine.rb +17 -4
- data/lib/solidus_bling/version.rb +1 -1
- data/solidus_bling.gemspec +6 -0
- data/spec/helpers/solidus_bling/accounts_helper_spec.rb +17 -0
- data/spec/jobs/solidus_bling/contact_job_spec.rb +7 -0
- data/spec/jobs/solidus_bling/order_job_spec.rb +7 -0
- data/spec/jobs/solidus_bling/product_job_spec.rb +7 -0
- data/spec/models/solidus_bling/account_spec.rb +7 -0
- data/spec/models/solidus_bling/event_spec.rb +7 -0
- data/spec/models/solidus_bling/payment_method_spec.rb +7 -0
- data/spec/models/solidus_bling/product_spec.rb +7 -0
- data/spec/models/solidus_bling/seller_spec.rb +7 -0
- data/spec/models/solidus_bling/shipping_method_spec.rb +7 -0
- data/spec/requests/solidus_bling/accounts_spec.rb +7 -0
- metadata +55 -32
- data/app/jobs/application_job.rb +0 -7
- data/app/jobs/erp_contact_job.rb +0 -20
- data/app/jobs/erp_order_job.rb +0 -20
- data/app/jobs/erp_product_job.rb +0 -11
- data/app/models/erp_account.rb +0 -3
- data/app/models/erp_event.rb +0 -2
- data/app/models/erp_product.rb +0 -3
- data/config/initializers/solidus_bling.rb +0 -11
- data/db/migrate/20230906141728_add_erp_id_to_spree_orders.rb +0 -5
- data/spec/jobs/erp_contact_job_spec.rb +0 -5
- data/spec/jobs/erp_order_job_spec.rb +0 -5
- data/spec/jobs/erp_product_job_spec.rb +0 -5
- data/spec/models/erp_account_spec.rb +0 -5
- data/spec/models/erp_event_spec.rb +0 -5
- data/spec/models/erp_product_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81e47bc81b103b82f681395e85e63674a0950316711770d0bbe6ca6f854eef01
|
4
|
+
data.tar.gz: 3983f4e929e14af2409202589016c7bb330376a2e38e0d1a33e02fcfa5620583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885bd2077efb3f7dc2d0b0cad3ba18e92f136c82608da254e35de9b6867ce235a587d11dfdee02d88ff086fff0e96ab19f5acf58c587ce6579b432fde861eb0b
|
7
|
+
data.tar.gz: 754480ad38bc954d93577623a3aaee813dead59ee10aede1afed9a5aa48c425b675f62d03a04eb934459eb5e62cb238cb78cd71ea548c88b9c2854318f023a96
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class AccountsController < ResourceController
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
@bling_account = SolidusBling::Account.find(params[:id])
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
@bling_account = SolidusBling::Account.new
|
13
|
+
@payment_methods = Spree::PaymentMethod.all.pluck(:name, :id)
|
14
|
+
@shipping_methods = Spree::ShippingMethod.all.pluck(:name, :id)
|
15
|
+
@bling_account.payment_methods.build
|
16
|
+
@bling_account.shipping_methods.build
|
17
|
+
@bling_account.sellers.build
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
bling_account = SolidusBling::Account.create account_params.merge(name: "Bling")
|
22
|
+
redirect_to admin_accounts_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
@bling_account = SolidusBling::Account.find(params[:id])
|
27
|
+
@payment_methods = Spree::PaymentMethod.all.pluck(:name, :id)
|
28
|
+
@shipping_methods = Spree::ShippingMethod.all.pluck(:name, :id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
bling_account = SolidusBling::Account.find(params[:id])
|
33
|
+
bling_account.update account_params
|
34
|
+
redirect_to edit_admin_account_path(bling_account.id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete
|
38
|
+
bling_account = SolidusBling::Account.find(params[:id])
|
39
|
+
bling_account.delete
|
40
|
+
redirect_to admin_accounts_path
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def model_class
|
46
|
+
SolidusBling::Account
|
47
|
+
end
|
48
|
+
|
49
|
+
def account_params
|
50
|
+
params.require(:account).permit(:app_name, :client_id, :client_secret, :refresh_token, :api_base_url, :external_store_id, :incoming_category_id, payment_methods_attributes: [:id, :spree_payment_method_id, :external_id], shipping_methods_attributes: [:id, :spree_shipping_method_id, :alias], sellers_attributes: [:id, :name, :external_id])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SolidusBling
|
2
|
+
class ApplicationJob < ActiveJob::Base
|
3
|
+
# Automatically retry jobs that encountered a deadlock
|
4
|
+
# retry_on ActiveRecord::Deadlocked
|
5
|
+
|
6
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
7
|
+
# discard_on ActiveJob::DeserializationError
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SolidusBling
|
2
|
+
class ContactJob < ApplicationJob
|
3
|
+
queue_as :default
|
4
|
+
|
5
|
+
def perform event:, method_name:
|
6
|
+
bling_event = SolidusBling::Event.new
|
7
|
+
contact = event[:args][:contato]
|
8
|
+
order = event[:args][:order]
|
9
|
+
bling_event.internal_id = order.id
|
10
|
+
bling_event.name = "event.omnes_event_name"
|
11
|
+
bling_event.method = method_name
|
12
|
+
if contact.include? "error"
|
13
|
+
bling_event.status = 'error'
|
14
|
+
bling_event.message = contact["error"]["description"]
|
15
|
+
else
|
16
|
+
bling_event.status = 'success'
|
17
|
+
end
|
18
|
+
bling_event.body = order.to_json
|
19
|
+
bling_event.save!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SolidusBling
|
2
|
+
class OrderJob < ApplicationJob
|
3
|
+
queue_as :default
|
4
|
+
|
5
|
+
def perform event:, method_name:
|
6
|
+
bling_event = SolidusBling::Event.new
|
7
|
+
order = event[:order]
|
8
|
+
bling_event.internal_id = order.id
|
9
|
+
bling_event.method = method_name
|
10
|
+
begin
|
11
|
+
SolidusBling::Order.new(order).send
|
12
|
+
bling_event.status = 'success'
|
13
|
+
rescue => e
|
14
|
+
bling_event.status = 'error'
|
15
|
+
bling_event.message = e.to_json
|
16
|
+
ensure
|
17
|
+
bling_event.body = order.to_json
|
18
|
+
bling_event.save!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SolidusBling
|
2
|
+
class ProductJob < ApplicationJob
|
3
|
+
queue_as :default
|
4
|
+
|
5
|
+
def perform event:, method_name:
|
6
|
+
bling_event = SolidusBling::Event.new
|
7
|
+
products = event[:products]
|
8
|
+
bling_event.method = method_name
|
9
|
+
bling_event.body = products.to_json
|
10
|
+
bling_event.save!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module SolidusBling
|
2
2
|
class Api
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
@account =
|
4
|
+
attr_reader :account, :headers
|
5
|
+
def initialize account
|
6
|
+
@account = account
|
7
7
|
verify_token
|
8
8
|
@headers = {
|
9
9
|
"Content-Type": "application/json",
|
@@ -48,7 +48,7 @@ module Bling
|
|
48
48
|
private
|
49
49
|
|
50
50
|
def find_account app_name
|
51
|
-
account =
|
51
|
+
account = SolidusBling::Account.find_by(app_name: app_name)
|
52
52
|
raise 'Conta de aplicativo inexistente' if account.nil?
|
53
53
|
account
|
54
54
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
module
|
2
|
-
class
|
1
|
+
module SolidusBling
|
2
|
+
class Contact < SolidusBling::Api
|
3
3
|
|
4
4
|
attr_reader :info
|
5
5
|
|
6
|
-
def initialize order
|
7
|
-
super()
|
6
|
+
def initialize order, account
|
7
|
+
super(account)
|
8
8
|
@info = find_or_create(order)
|
9
9
|
end
|
10
10
|
|
11
11
|
def find_or_create order
|
12
|
-
raise "Order com CPF/CNPJ vazio" if order.
|
13
|
-
contato = find_by_cpf(order.
|
12
|
+
raise "Order com CPF/CNPJ vazio" if order.tax_id.nil?
|
13
|
+
contato = find_by_cpf(order.tax_id)
|
14
14
|
if contato.nil?
|
15
15
|
contato_external_id = create(order)
|
16
16
|
contato = {"id" => contato_external_id}
|
@@ -18,8 +18,8 @@ module Bling
|
|
18
18
|
contato
|
19
19
|
end
|
20
20
|
|
21
|
-
def find_by_cpf
|
22
|
-
req = Typhoeus.get("#{@account.api_base_url}/contatos?numeroDocumento=#{
|
21
|
+
def find_by_cpf tax_id
|
22
|
+
req = Typhoeus.get("#{@account.api_base_url}/contatos?numeroDocumento=#{tax_id.gsub(/\D/, "")}", headers: @headers)
|
23
23
|
json = JSON.parse(req.body)
|
24
24
|
response_has_error?(json)
|
25
25
|
user = {}
|
@@ -39,7 +39,7 @@ module Bling
|
|
39
39
|
ensure
|
40
40
|
json = JSON.parse(req.body)
|
41
41
|
response_has_error?(json)
|
42
|
-
Spree::Bus.publish :
|
42
|
+
Spree::Bus.publish :bling_contact_created, args: {order: order, contato: json}
|
43
43
|
return json.dig("data", "id")
|
44
44
|
end
|
45
45
|
end
|
@@ -47,15 +47,15 @@ module Bling
|
|
47
47
|
private
|
48
48
|
|
49
49
|
def tipo_pessoa doc
|
50
|
-
doc.length > 11 ? "J" : "F"
|
50
|
+
doc.gsub(/\D/, "").length > 11 ? "J" : "F"
|
51
51
|
end
|
52
52
|
|
53
53
|
def build_hash_contato order
|
54
54
|
{
|
55
55
|
"nome": order.ship_address.name,
|
56
56
|
"telefone": order.ship_address.phone,
|
57
|
-
"tipo": tipo_pessoa(order.
|
58
|
-
"numeroDocumento": order.
|
57
|
+
"tipo": tipo_pessoa(order.tax_id),
|
58
|
+
"numeroDocumento": order.tax_id,
|
59
59
|
"email": order.email,
|
60
60
|
"endereco": {
|
61
61
|
"geral": {
|
@@ -1,19 +1,14 @@
|
|
1
|
-
module
|
2
|
-
class
|
3
|
-
|
4
|
-
ID_LOJA_BLING = SolidusBling.config.store_id.to_i || 204601505
|
5
|
-
ID_VENDEDOR_BLING = SolidusBling.config.seller_id.to_i || 15596272829
|
6
|
-
ID_FORMA_PGTO_BLING = SolidusBling.config.payment_type_id.to_i || 4484076
|
7
|
-
ID_CAT_RECEITA_BLING = SolidusBling.config.category_id.to_i || 14653794318
|
1
|
+
module SolidusBling
|
2
|
+
class Order < SolidusBling::Api
|
8
3
|
|
9
4
|
def initialize order
|
10
|
-
super()
|
5
|
+
super(SolidusBling::Account.first)
|
11
6
|
@order = order
|
12
7
|
end
|
13
8
|
|
14
9
|
def send
|
15
10
|
if @order.present?
|
16
|
-
contato =
|
11
|
+
contato = SolidusBling::Contact.new(@order, @account)
|
17
12
|
hash_order = build_hash_order(@order, contato.info)
|
18
13
|
begin
|
19
14
|
attempts ||= 1
|
@@ -25,7 +20,7 @@ module Bling
|
|
25
20
|
json = JSON.parse(req.body)
|
26
21
|
response_has_error?(json)
|
27
22
|
if json.include? "data"
|
28
|
-
@order.
|
23
|
+
@order.bling_order_id = json["data"]["id"]
|
29
24
|
@order.save
|
30
25
|
end
|
31
26
|
end
|
@@ -39,14 +34,14 @@ module Bling
|
|
39
34
|
"numeroLoja": order.number,
|
40
35
|
"data": order.completed_at.strftime("%Y-%m-%d"),
|
41
36
|
"loja": {
|
42
|
-
"id":
|
37
|
+
"id": @account.external_store_id
|
43
38
|
},
|
44
39
|
"contato": {
|
45
40
|
"id": contato["id"]
|
46
41
|
},
|
47
42
|
"itens": build_array_items(order.line_items),
|
48
43
|
"vendedor": {
|
49
|
-
"id":
|
44
|
+
"id": @account.sellers.first.external_id
|
50
45
|
},
|
51
46
|
"transporte": build_hash_transporte(order),
|
52
47
|
"parcelas": build_array_parcelas(order),
|
@@ -59,20 +54,20 @@ module Bling
|
|
59
54
|
"observacoes": " Nº Pedido Loja: #{order.number}",
|
60
55
|
"observacoesInternas": "Pagamento: #{@parcelas}x R$ #{(order.total.to_f / @parcelas).round(2)}\nForma de envio: #{order.shipments.last.selected_shipping_rate.name}\n#{build_cupons(order.promotions)}",
|
61
56
|
"categoria": {
|
62
|
-
"id":
|
57
|
+
"id": @account.incoming_category_id
|
63
58
|
}
|
64
59
|
}
|
65
60
|
end
|
66
61
|
|
67
62
|
def build_array_items items
|
68
|
-
items.map do |item|
|
69
|
-
|
63
|
+
items.map do |item|
|
64
|
+
bling_product = SolidusBling::Product.find_by(sku: item.sku)
|
70
65
|
{
|
71
|
-
"id":
|
66
|
+
"id": bling_product.external_id,
|
72
67
|
"quantidade": item.quantity,
|
73
68
|
"valor": item.price.to_f,
|
74
69
|
"produto": {
|
75
|
-
"id":
|
70
|
+
"id": bling_product.external_id
|
76
71
|
}
|
77
72
|
}
|
78
73
|
end
|
@@ -89,7 +84,7 @@ module Bling
|
|
89
84
|
"dataVencimento": (order.completed_at + parcela.months).strftime("%Y-%m-%d"),
|
90
85
|
"valor": valor_parcela,
|
91
86
|
"formaPagamento": {
|
92
|
-
"id":
|
87
|
+
"id": @account.payment_methods.find_by(spree_payment_method_id: order.payments.last.payment_method_id).external_id
|
93
88
|
}
|
94
89
|
}
|
95
90
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
module
|
2
|
-
class
|
1
|
+
module SolidusBling
|
2
|
+
class Product < ApplicationRecord
|
3
|
+
belongs_to :account
|
3
4
|
|
4
|
-
def update
|
5
|
+
def self.update bling_account
|
6
|
+
bling_api = SolidusBling::Api.new(bling_account)
|
5
7
|
skus = Spree::Variant.pluck(:sku)
|
6
8
|
hash_products = {}
|
7
9
|
products = skus.map do |sku|
|
8
10
|
begin
|
9
11
|
attempts ||= 1
|
10
|
-
req = Typhoeus.get("#{
|
12
|
+
req = Typhoeus.get("#{bling_api.account.api_base_url}/produtos?codigo=#{sku}", headers: bling_api.headers)
|
11
13
|
res_json = JSON.parse(req.body)
|
12
14
|
p "#{sku} => #{res_json}"
|
13
15
|
next if res_json["data"] == []
|
14
16
|
product = res_json["data"].first
|
15
17
|
hash_products[sku] = product["id"]
|
16
18
|
{
|
17
|
-
|
19
|
+
account_id: bling_api.account.id,
|
18
20
|
sku: sku,
|
19
21
|
external_id: product["id"].to_s,
|
20
22
|
name: product["nome"]
|
@@ -26,8 +28,9 @@ module Bling
|
|
26
28
|
retry if (attempts += 1) < 5
|
27
29
|
end
|
28
30
|
end.compact.uniq
|
29
|
-
|
30
|
-
Spree::Bus.publish :
|
31
|
+
SolidusBling::Product.upsert_all(products, unique_by: :sku)
|
32
|
+
Spree::Bus.publish :bling_products_updated, products: hash_products
|
31
33
|
end
|
34
|
+
|
32
35
|
end
|
33
|
-
end
|
36
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module SolidusBling
|
2
2
|
class Subscriber
|
3
3
|
include Omnes::Subscriber
|
4
4
|
|
@@ -6,27 +6,27 @@ module Bling
|
|
6
6
|
with: :send_order_to_bling,
|
7
7
|
id: :send_order_to_bling
|
8
8
|
|
9
|
-
handle :
|
9
|
+
handle :bling_products_updated,
|
10
10
|
with: :products_updated,
|
11
11
|
id: :products_updated
|
12
12
|
|
13
|
-
handle :
|
13
|
+
handle :bling_contact_created,
|
14
14
|
with: :contato_created,
|
15
15
|
id: :contato_created
|
16
16
|
|
17
17
|
def send_order_to_bling event, debug_info = {}
|
18
18
|
method = __method__.to_s
|
19
|
-
|
19
|
+
SolidusBling::OrderJob.perform_later(event: event.payload, method_name: method)
|
20
20
|
end
|
21
21
|
|
22
22
|
def contato_created event, debug_info = {}
|
23
23
|
method = __method__.to_s
|
24
|
-
|
24
|
+
SolidusBling::ContactJob.perform_later(event: event.payload, method_name: method)
|
25
25
|
end
|
26
26
|
|
27
27
|
def products_updated event, debug_info = {}
|
28
28
|
method = __method__.to_s
|
29
|
-
|
29
|
+
SolidusBling::ProductJob.perform_later(event: event.payload, method_name: method)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<%= form_with model: bling_account, url: form_url do |form| %>
|
2
|
+
<div>
|
3
|
+
<%= form.label :app_name, "Nome do Aplicativo: " %>
|
4
|
+
<%= form.text_field :app_name %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div>
|
8
|
+
<%= form.label :client_id, "Client ID: " %>
|
9
|
+
<%= form.text_field :client_id %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div>
|
13
|
+
<%= form.label :client_secret, "Client Secret: " %>
|
14
|
+
<%= form.text_field :client_secret %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div>
|
18
|
+
<%= form.label :refresh_token, "Refresh Token: " %>
|
19
|
+
<%= form.text_field :refresh_token %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div>
|
23
|
+
<%= form.label :api_base_url, "API URL: " %>
|
24
|
+
<%= form.text_field :api_base_url %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div>
|
28
|
+
<%= form.label :external_store_id, "ID da Loja no Bling: " %>
|
29
|
+
<%= form.text_field :external_store_id %>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div>
|
33
|
+
<%= form.label :incoming_category_id, "ID da Categoria de Receita: " %>
|
34
|
+
<%= form.text_field :incoming_category_id %>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div>
|
38
|
+
<% bling_account.payment_methods.each do |payment_method| %>
|
39
|
+
<%= form.fields_for :payment_methods do |payment_form| %>
|
40
|
+
<%= payment_form.select :spree_payment_method_id, @payment_methods %>
|
41
|
+
<%= payment_form.text_field :external_id %>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div>
|
47
|
+
<% bling_account.shipping_methods.each do |shipping_method| %>
|
48
|
+
<%= form.fields_for :shipping_methods do |shipping_form| %>
|
49
|
+
<%= shipping_form.select :spree_shipping_method_id, @shipping_methods %>
|
50
|
+
<%= shipping_form.text_field :alias %>
|
51
|
+
<% end %>
|
52
|
+
<% end %>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<div>
|
56
|
+
<% bling_account.sellers.each do |seller| %>
|
57
|
+
<%= form.fields_for :sellers do |seller_form| %>
|
58
|
+
<%= seller_form.label :name, "Nome do Vendedor: " %>
|
59
|
+
<%= seller_form.text_field :name %>
|
60
|
+
|
61
|
+
<%= seller_form.label :external_id, "ID do Vendedor: " %>
|
62
|
+
<%= seller_form.text_field :external_id %>
|
63
|
+
<% end %>
|
64
|
+
<% end %>
|
65
|
+
</div>
|
66
|
+
|
67
|
+
<%= form.submit "Salvar" %>
|
68
|
+
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= link_to "Criar", new_admin_account_path %>
|
2
|
+
<div>
|
3
|
+
<% @accounts.each do |account| %>
|
4
|
+
<div>
|
5
|
+
<div>
|
6
|
+
Nome do aplicativo:
|
7
|
+
<span><%= account.app_name %></span>
|
8
|
+
</div>
|
9
|
+
<%= link_to "Editar", edit_admin_account_path(account.id) %>
|
10
|
+
<%= link_to "Excluir", admin_account_path(account.id), method: :delete %>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class CreateSolidusBlingAccounts < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :solidus_bling_accounts do |t|
|
4
4
|
t.string :name
|
5
5
|
t.string :app_name
|
6
6
|
t.string :api_base_url
|
@@ -9,6 +9,8 @@ class CreateErpAccounts < ActiveRecord::Migration[7.0]
|
|
9
9
|
t.string :client_secret
|
10
10
|
t.string :refresh_token
|
11
11
|
t.string :access_token
|
12
|
+
t.string :external_store_id
|
13
|
+
t.string :incoming_category_id
|
12
14
|
t.datetime :token_expires_in
|
13
15
|
|
14
16
|
t.timestamps
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class
|
1
|
+
class CreateSolidusBlingProducts < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :solidus_bling_products do |t|
|
4
4
|
t.string :external_id, null: false, index: { unique: true }
|
5
5
|
t.string :name, null: false
|
6
6
|
t.string :sku, null: false, index: { unique: true }
|
7
|
-
t.
|
7
|
+
t.integer :account_id, null: false, index: true
|
8
8
|
|
9
9
|
t.timestamps
|
10
10
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class CreateSolidusBlingEvents < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :solidus_bling_events do |t|
|
4
4
|
t.string :internal_id
|
5
5
|
t.string :status
|
6
6
|
t.string :message
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSolidusBlingPaymentMethods < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :solidus_bling_payment_methods do |t|
|
4
|
+
t.string :external_id
|
5
|
+
t.integer :account_id, null: false, index: true
|
6
|
+
t.integer :spree_payment_method_id, null: false, index: true
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
|
10
|
+
t.foreign_key :spree_payment_methods, column: :spree_payment_method_id
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSolidusBlingShippingMethods < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :solidus_bling_shipping_methods do |t|
|
4
|
+
t.string :alias
|
5
|
+
t.integer :account_id, null: false, index: true, index: { name: "solidus_bling_shipping_account_index" }
|
6
|
+
t.integer :spree_shipping_method_id, null: false, index: true, index: { name: "solidus_bling_spree_shipping_index" }
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
|
10
|
+
t.foreign_key :spree_shipping_methods, column: :spree_shipping_method_id
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -3,9 +3,4 @@
|
|
3
3
|
SolidusBling.configure do |config|
|
4
4
|
# TODO: Remember to change this with the actual preferences you have implemented!
|
5
5
|
# config.sample_preference = 'sample_value'
|
6
|
-
config.app_name = ''
|
7
|
-
config.store_id = ''
|
8
|
-
config.seller_id = ''
|
9
|
-
config.payment_type_id = ''
|
10
|
-
config.category_id = ''
|
11
6
|
end
|
data/lib/solidus_bling/engine.rb
CHANGED
@@ -7,19 +7,32 @@ module SolidusBling
|
|
7
7
|
class Engine < Rails::Engine
|
8
8
|
include SolidusSupport::EngineExtensions
|
9
9
|
|
10
|
-
isolate_namespace
|
10
|
+
isolate_namespace SolidusBling
|
11
11
|
|
12
12
|
engine_name 'solidus_bling'
|
13
13
|
|
14
|
+
initializer 'solidus_bling.configure_backend' do
|
15
|
+
next unless ::Spree::Backend::Config.respond_to?(:menu_items)
|
16
|
+
|
17
|
+
::Spree::Backend::Config.configure do |config|
|
18
|
+
config.menu_items << config.class::MenuItem.new(
|
19
|
+
[:bling_account],
|
20
|
+
'exclamation',
|
21
|
+
url: :admin_accounts_path,
|
22
|
+
condition: -> { can?(:manage, Spree::Store) }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
14
27
|
# use rspec for tests
|
15
28
|
config.generators do |g|
|
16
29
|
g.test_framework :rspec
|
17
30
|
end
|
18
31
|
|
19
32
|
config.to_prepare do
|
20
|
-
Spree::Bus.register(:
|
21
|
-
Spree::Bus.register(:
|
22
|
-
|
33
|
+
Spree::Bus.register(:bling_products_updated)
|
34
|
+
Spree::Bus.register(:bling_contact_created)
|
35
|
+
SolidusBling::Subscriber.new.subscribe_to(Spree::Bus)
|
23
36
|
end
|
24
37
|
|
25
38
|
end
|
data/solidus_bling.gemspec
CHANGED
@@ -34,4 +34,10 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency 'solidus_brazilian_adaptations'
|
35
35
|
|
36
36
|
spec.add_development_dependency 'solidus_dev_support', '~> 2.7'
|
37
|
+
|
38
|
+
spec.post_install_message = <<-MESSAGE
|
39
|
+
To complete the installation, please run:
|
40
|
+
bin/rails g solidus_brazilian_adaptations:install
|
41
|
+
MESSAGE
|
42
|
+
|
37
43
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the AccountsHelper. For example:
|
5
|
+
#
|
6
|
+
# describe AccountsHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
module SolidusBling
|
14
|
+
RSpec.describe AccountsHelper, type: :helper do
|
15
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_bling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ulysses-bull
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -108,18 +108,27 @@ files:
|
|
108
108
|
- app/assets/javascripts/spree/frontend/solidus_bling.js
|
109
109
|
- app/assets/stylesheets/spree/backend/solidus_bling.css
|
110
110
|
- app/assets/stylesheets/spree/frontend/solidus_bling.css
|
111
|
-
- app/
|
112
|
-
- app/
|
113
|
-
- app/jobs/
|
114
|
-
- app/jobs/
|
115
|
-
- app/
|
116
|
-
- app/
|
117
|
-
- app/models/
|
118
|
-
- app/models/
|
119
|
-
- app/models/
|
120
|
-
- app/models/
|
121
|
-
- app/models/
|
122
|
-
- app/
|
111
|
+
- app/controllers/spree/admin/accounts_controller.rb
|
112
|
+
- app/helpers/solidus_bling/accounts_helper.rb
|
113
|
+
- app/jobs/solidus_bling/application_job.rb
|
114
|
+
- app/jobs/solidus_bling/contact_job.rb
|
115
|
+
- app/jobs/solidus_bling/order_job.rb
|
116
|
+
- app/jobs/solidus_bling/product_job.rb
|
117
|
+
- app/models/solidus_bling/account.rb
|
118
|
+
- app/models/solidus_bling/api.rb
|
119
|
+
- app/models/solidus_bling/contact.rb
|
120
|
+
- app/models/solidus_bling/event.rb
|
121
|
+
- app/models/solidus_bling/order.rb
|
122
|
+
- app/models/solidus_bling/payment_method.rb
|
123
|
+
- app/models/solidus_bling/product.rb
|
124
|
+
- app/models/solidus_bling/seller.rb
|
125
|
+
- app/models/solidus_bling/shipping_method.rb
|
126
|
+
- app/subscribers/solidus_bling/subscriber.rb
|
127
|
+
- app/views/spree/admin/accounts/_form.html.erb
|
128
|
+
- app/views/spree/admin/accounts/edit.html.erb
|
129
|
+
- app/views/spree/admin/accounts/index.html.erb
|
130
|
+
- app/views/spree/admin/accounts/new.html.erb
|
131
|
+
- app/views/spree/admin/accounts/show.html.erb
|
123
132
|
- bin/console
|
124
133
|
- bin/rails
|
125
134
|
- bin/rails-engine
|
@@ -127,13 +136,15 @@ files:
|
|
127
136
|
- bin/rake
|
128
137
|
- bin/sandbox
|
129
138
|
- bin/setup
|
130
|
-
- config/initializers/solidus_bling.rb
|
131
139
|
- config/locales/en.yml
|
132
140
|
- config/routes.rb
|
133
|
-
- db/migrate/
|
134
|
-
- db/migrate/
|
135
|
-
- db/migrate/
|
136
|
-
- db/migrate/
|
141
|
+
- db/migrate/20230918141419_create_solidus_bling_accounts.rb
|
142
|
+
- db/migrate/20230918141505_add_bling_order_id_to_spree_orders.rb
|
143
|
+
- db/migrate/20230918141700_create_solidus_bling_products.rb
|
144
|
+
- db/migrate/20230918142547_create_solidus_bling_events.rb
|
145
|
+
- db/migrate/20230918142742_create_solidus_bling_payment_methods.rb
|
146
|
+
- db/migrate/20230918142953_create_solidus_bling_sellers.rb
|
147
|
+
- db/migrate/20230918143057_create_solidus_bling_shipping_methods.rb
|
137
148
|
- lib/generators/solidus_bling/install/install_generator.rb
|
138
149
|
- lib/generators/solidus_bling/install/templates/initializer.rb
|
139
150
|
- lib/solidus_bling.rb
|
@@ -142,12 +153,17 @@ files:
|
|
142
153
|
- lib/solidus_bling/testing_support/factories.rb
|
143
154
|
- lib/solidus_bling/version.rb
|
144
155
|
- solidus_bling.gemspec
|
145
|
-
- spec/
|
146
|
-
- spec/jobs/
|
147
|
-
- spec/jobs/
|
148
|
-
- spec/
|
149
|
-
- spec/models/
|
150
|
-
- spec/models/
|
156
|
+
- spec/helpers/solidus_bling/accounts_helper_spec.rb
|
157
|
+
- spec/jobs/solidus_bling/contact_job_spec.rb
|
158
|
+
- spec/jobs/solidus_bling/order_job_spec.rb
|
159
|
+
- spec/jobs/solidus_bling/product_job_spec.rb
|
160
|
+
- spec/models/solidus_bling/account_spec.rb
|
161
|
+
- spec/models/solidus_bling/event_spec.rb
|
162
|
+
- spec/models/solidus_bling/payment_method_spec.rb
|
163
|
+
- spec/models/solidus_bling/product_spec.rb
|
164
|
+
- spec/models/solidus_bling/seller_spec.rb
|
165
|
+
- spec/models/solidus_bling/shipping_method_spec.rb
|
166
|
+
- spec/requests/solidus_bling/accounts_spec.rb
|
151
167
|
- spec/spec_helper.rb
|
152
168
|
homepage: https://github.com/ulysses-bull/solidus_bling#readme
|
153
169
|
licenses:
|
@@ -156,7 +172,9 @@ metadata:
|
|
156
172
|
homepage_uri: https://github.com/ulysses-bull/solidus_bling#readme
|
157
173
|
source_code_uri: https://github.com/ulysses-bull/solidus_bling
|
158
174
|
changelog_uri: https://github.com/ulysses-bull/solidus_bling/blob/master/CHANGELOG.md
|
159
|
-
post_install_message:
|
175
|
+
post_install_message: |2
|
176
|
+
To complete the installation, please run:
|
177
|
+
bin/rails g solidus_brazilian_adaptations:install
|
160
178
|
rdoc_options: []
|
161
179
|
require_paths:
|
162
180
|
- lib
|
@@ -179,10 +197,15 @@ signing_key:
|
|
179
197
|
specification_version: 4
|
180
198
|
summary: Solidus extension to integrate with the Bling
|
181
199
|
test_files:
|
182
|
-
- spec/
|
183
|
-
- spec/jobs/
|
184
|
-
- spec/jobs/
|
185
|
-
- spec/
|
186
|
-
- spec/models/
|
187
|
-
- spec/models/
|
200
|
+
- spec/helpers/solidus_bling/accounts_helper_spec.rb
|
201
|
+
- spec/jobs/solidus_bling/contact_job_spec.rb
|
202
|
+
- spec/jobs/solidus_bling/order_job_spec.rb
|
203
|
+
- spec/jobs/solidus_bling/product_job_spec.rb
|
204
|
+
- spec/models/solidus_bling/account_spec.rb
|
205
|
+
- spec/models/solidus_bling/event_spec.rb
|
206
|
+
- spec/models/solidus_bling/payment_method_spec.rb
|
207
|
+
- spec/models/solidus_bling/product_spec.rb
|
208
|
+
- spec/models/solidus_bling/seller_spec.rb
|
209
|
+
- spec/models/solidus_bling/shipping_method_spec.rb
|
210
|
+
- spec/requests/solidus_bling/accounts_spec.rb
|
188
211
|
- spec/spec_helper.rb
|
data/app/jobs/application_job.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
class ApplicationJob < ActiveJob::Base
|
2
|
-
# Automatically retry jobs that encountered a deadlock
|
3
|
-
# retry_on ActiveRecord::Deadlocked
|
4
|
-
|
5
|
-
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
-
# discard_on ActiveJob::DeserializationError
|
7
|
-
end
|
data/app/jobs/erp_contact_job.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class ErpContactJob < ApplicationJob
|
2
|
-
queue_as :default
|
3
|
-
|
4
|
-
def perform event:, method_name:
|
5
|
-
erp_event = ErpEvent.new
|
6
|
-
contact = event[:args][:contato]
|
7
|
-
order = event[:args][:order]
|
8
|
-
erp_event.internal_id = order.id
|
9
|
-
erp_event.name = "event.omnes_event_name"
|
10
|
-
erp_event.method = method_name
|
11
|
-
if contact.include? "error"
|
12
|
-
erp_event.status = 'error'
|
13
|
-
erp_event.message = contact["error"]["description"]
|
14
|
-
else
|
15
|
-
erp_event.status = 'success'
|
16
|
-
end
|
17
|
-
erp_event.body = order.to_json
|
18
|
-
erp_event.save!
|
19
|
-
end
|
20
|
-
end
|
data/app/jobs/erp_order_job.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class ErpOrderJob < ApplicationJob
|
2
|
-
queue_as :default
|
3
|
-
|
4
|
-
def perform event:, method_name:
|
5
|
-
erp_event = ErpEvent.new
|
6
|
-
order = event[:order]
|
7
|
-
erp_event.internal_id = order.id
|
8
|
-
erp_event.method = method_name
|
9
|
-
begin
|
10
|
-
Bling::Pedido.new(order).send
|
11
|
-
erp_event.status = 'success'
|
12
|
-
rescue => e
|
13
|
-
erp_event.status = 'error'
|
14
|
-
erp_event.message = e.to_json
|
15
|
-
ensure
|
16
|
-
erp_event.body = order.to_json
|
17
|
-
erp_event.save!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/app/jobs/erp_product_job.rb
DELETED
data/app/models/erp_account.rb
DELETED
data/app/models/erp_event.rb
DELETED
data/app/models/erp_product.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
SolidusBling.configure do |config|
|
4
|
-
# TODO: Remember to change this with the actual preferences you have implemented!
|
5
|
-
# config.sample_preference = 'sample_value'
|
6
|
-
config.app_name = ''
|
7
|
-
config.store_id = ''
|
8
|
-
config.seller_id = ''
|
9
|
-
config.payment_type_id = ''
|
10
|
-
config.category_id = ''
|
11
|
-
end
|