solidus_bling 2.0.6 → 3.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +1 -3
  5. data/LICENSE +1 -1
  6. data/README.md +1 -1
  7. data/app/controllers/spree/admin/solidus_bling/accounts_controller.rb +77 -0
  8. data/app/jobs/solidus_bling/order_job.rb +5 -7
  9. data/app/models/solidus_bling/account.rb +7 -1
  10. data/app/models/solidus_bling/order.rb +122 -95
  11. data/app/models/solidus_bling/token.rb +44 -0
  12. data/app/subscribers/solidus_bling/subscriber.rb +2 -22
  13. data/app/views/spree/admin/{accounts → solidus_bling/accounts}/_form.html.erb +21 -8
  14. data/app/views/spree/admin/solidus_bling/accounts/edit.html.erb +1 -0
  15. data/app/views/spree/admin/solidus_bling/accounts/index.html.erb +13 -0
  16. data/app/views/spree/admin/{accounts → solidus_bling/accounts}/new.html.erb +1 -1
  17. data/bin/meu_sandbox +67 -0
  18. data/config/locales/pt-BR.yml +1 -1
  19. data/config/routes.rb +6 -2
  20. data/db/migrate/{20230918141419_create_solidus_bling_accounts.rb → 20231109210635_create_solidus_bling_accounts.rb} +4 -5
  21. data/db/migrate/{20230918142547_create_solidus_bling_events.rb → 20231110112819_create_solidus_bling_events.rb} +1 -2
  22. data/db/migrate/{20230918143057_create_solidus_bling_shipping_methods.rb → 20231110113221_create_solidus_bling_shipping_methods.rb} +1 -0
  23. data/lib/generators/solidus_bling/install/install_generator.rb +0 -10
  24. data/lib/solidus_bling/engine.rb +8 -11
  25. data/lib/solidus_bling/version.rb +1 -1
  26. data/lib/solidus_bling.rb +1 -1
  27. data/solidus_bling.gemspec +6 -7
  28. metadata +25 -55
  29. data/app/assets/javascripts/spree/backend/solidus_bling.js +0 -2
  30. data/app/assets/javascripts/spree/frontend/solidus_bling.js +0 -2
  31. data/app/assets/stylesheets/spree/backend/solidus_bling.css +0 -4
  32. data/app/assets/stylesheets/spree/frontend/solidus_bling.css +0 -4
  33. data/app/controllers/spree/admin/accounts_controller.rb +0 -67
  34. data/app/controllers/spree/admin/bling_products_controller.rb +0 -20
  35. data/app/decorators/models/solidus_bling/spree/payment_method_decorator.rb +0 -13
  36. data/app/decorators/models/solidus_bling/spree/shipping_method_decorator.rb +0 -13
  37. data/app/helpers/solidus_bling/accounts_helper.rb +0 -4
  38. data/app/helpers/solidus_bling/bling_products_helper.rb +0 -4
  39. data/app/jobs/solidus_bling/contact_job.rb +0 -22
  40. data/app/jobs/solidus_bling/product_job.rb +0 -13
  41. data/app/jobs/solidus_bling/update_product_job.rb +0 -9
  42. data/app/models/solidus_bling/api.rb +0 -57
  43. data/app/models/solidus_bling/contact.rb +0 -83
  44. data/app/models/solidus_bling/product.rb +0 -36
  45. data/app/views/spree/admin/accounts/edit.html.erb +0 -11
  46. data/app/views/spree/admin/accounts/index.html.erb +0 -13
  47. data/db/migrate/20230918141700_create_solidus_bling_products.rb +0 -12
  48. data/db/migrate/20231018141940_add_company_to_solidus_bling_shipping_methods.rb +0 -5
  49. data/spec/helpers/solidus_bling/accounts_helper_spec.rb +0 -17
  50. data/spec/helpers/solidus_bling/bling_products_helper_spec.rb +0 -17
  51. data/spec/jobs/solidus_bling/contact_job_spec.rb +0 -7
  52. data/spec/jobs/solidus_bling/product_job_spec.rb +0 -7
  53. data/spec/jobs/solidus_bling/update_product_job_spec.rb +0 -7
  54. data/spec/models/solidus_bling/product_spec.rb +0 -7
  55. data/spec/requests/solidus_bling/accounts_spec.rb +0 -7
  56. data/spec/requests/solidus_bling/bling_products_spec.rb +0 -7
  57. /data/app/views/spree/admin/{accounts → solidus_bling/accounts}/show.html.erb +0 -0
  58. /data/db/migrate/{20230918141505_add_bling_order_id_to_spree_orders.rb → 20231110112528_add_bling_order_id_to_spree_orders.rb} +0 -0
  59. /data/db/migrate/{20230918142742_create_solidus_bling_payment_methods.rb → 20231110112958_create_solidus_bling_payment_methods.rb} +0 -0
  60. /data/db/migrate/{20230918142953_create_solidus_bling_sellers.rb → 20231110113122_create_solidus_bling_sellers.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd3b2416612bb0c496adcbe4dadb851decd26a74c378ea362f5ab47a2cac9c50
4
- data.tar.gz: 8b918c41a1a377631d470407b6d711f7dd57d4183d558e24ab99627f433b3394
3
+ metadata.gz: 6db82bc3c77223d35418dc4778dea214887526407f73b566a1e3e36929d9349a
4
+ data.tar.gz: fb46fb95a4787468f045fb0b3e4b28c5e9d51fe20b6cad8d2292f9c222f11bac
5
5
  SHA512:
6
- metadata.gz: 82e33cf15f8c38519af2688ce3834aca4777c16995f83ddf394de8689d274459896357b910ccb23dc0e03aa5dbdf54a267ef5068fd799eb79ba24ea1061411d8
7
- data.tar.gz: 246a8b67a86852e725584de7a7d413f293ac3c31984fa889baba8d188132d17e1325b800cb0b76cc9be5ce8d7c3ccc40637a385140b387429f1084206b6c3d96
6
+ metadata.gz: 5191696fc43ae7a0e9174bb03eb47464c21eab8f0e181533e4d4c1433e55dde194637af73e8a8363336929cc8e8b7eab28a4de810d102232e5d090488c5eb20f
7
+ data.tar.gz: d278d7f74dcfe34ddf36833fed252e9149011b7ad43131a034a0ab41854711938917fb3d255760734ff243f21a7b7cc9d2807ecb6a3dce7ca549394d9f923fc5
data/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
data/.gitignore CHANGED
@@ -19,4 +19,3 @@ spec/examples.txt
19
19
  .rvmrc
20
20
  .ruby-version
21
21
  .ruby-gemset
22
- release.sh
data/CHANGELOG.md CHANGED
@@ -1,5 +1,3 @@
1
1
  # Changelog
2
2
 
3
-
4
-
5
- \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
3
+ See https://github.com/solidusio-contrib/solidus_bling/releases or OLD_CHANGELOG.md for older versions.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 ulysses-bull
1
+ Copyright (c) 2023 Hamilton Tumenas Borges
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
data/README.md CHANGED
@@ -70,4 +70,4 @@ Please refer to the [dedicated page](https://github.com/solidusio/solidus/wiki/H
70
70
 
71
71
  ## License
72
72
 
73
- Copyright (c) 2023 ulysses-bull, released under the New BSD License.
73
+ Copyright (c) 2023 Hamilton Tumenas Borges, released under the New BSD License.
@@ -0,0 +1,77 @@
1
+ module Spree
2
+ module Admin
3
+ module SolidusBling
4
+
5
+ class AccountsController < BaseController
6
+ before_action :set_account, only: [:show, :edit, :update, :destroy]
7
+
8
+ def index
9
+ @accounts = ::SolidusBling::Account.all
10
+ end
11
+
12
+ def show
13
+ end
14
+
15
+ def new
16
+ @bling_account = ::SolidusBling::Account.new
17
+ @payment_methods = ::Spree::PaymentMethod.all.pluck(:name, :id)
18
+ @shipping_methods = ::Spree::ShippingMethod.all.pluck(:name, :id)
19
+ @bling_account.payment_methods.build
20
+ @bling_account.shipping_methods.build
21
+ @bling_account.sellers.build
22
+ end
23
+
24
+ def create
25
+ bling_account = ::SolidusBling::Account.new account_params
26
+ if bling_account.save
27
+ flash[:success] = "Conta criada com sucesso"
28
+ redirect_to admin_solidus_bling_accounts_path
29
+ else
30
+ flash[:error] = bling_account.errors.full_messages.join("\n")
31
+ redirect_to new_admin_solidus_bling_account_path
32
+ end
33
+ end
34
+
35
+ def edit
36
+ @payment_methods = ::Spree::PaymentMethod.all.pluck(:name, :id)
37
+ @shipping_methods = ::Spree::ShippingMethod.all.pluck(:name, :id)
38
+ end
39
+
40
+ def update
41
+ @bling_account.update account_params
42
+ redirect_to edit_admin_solidus_bling_account_path(@bling_account.id)
43
+ end
44
+
45
+ def destroy
46
+ @bling_account.delete
47
+ redirect_to admin_solidus_bling_accounts_path
48
+ end
49
+
50
+ def authorize
51
+ bling_account = ::SolidusBling::Account.first
52
+ code = params[:code]
53
+ unless ::SolidusBling::Token.new.authorize(bling_account, code)
54
+ bling_account.errors.add(:base, "Erro ao autorizar aplicativo 🦆")
55
+ flash[:error] = bling_account.errors.full_messages.join("\n")
56
+ end
57
+ redirect_to edit_admin_solidus_bling_account_path(bling_account.id)
58
+ end
59
+
60
+ private
61
+
62
+ def set_account
63
+ @bling_account = ::SolidusBling::Account.find(params[:id])
64
+ end
65
+
66
+ def account_params
67
+ params.require(:account).permit(
68
+ :client_id, :client_secret, :refresh_token, :redirect_url, :state, :access_token, :api_key, :external_store_id, :incoming_category_id,
69
+ payment_methods_attributes: [:id, :spree_payment_method_id, :external_id],
70
+ shipping_methods_attributes: [:id, :spree_shipping_method_id, :alias, :company],
71
+ sellers_attributes: [:id, :name, :external_id]
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -2,21 +2,19 @@ module SolidusBling
2
2
  class OrderJob < ApplicationJob
3
3
  queue_as :default
4
4
 
5
- def perform event:, method_name:
6
- bling_event = SolidusBling::Event.new
5
+ def perform(event:)
7
6
  order = event[:order]
8
- bling_event.internal_id = order.id
9
- bling_event.method = method_name
7
+ bling_event = SolidusBling::Event.new(internal_id: order.id, body: order.to_json)
10
8
  begin
11
9
  SolidusBling::Order.new(order).send
12
- bling_event.status = 'success'
10
+ bling_event.status = "success"
13
11
  rescue => e
14
- bling_event.status = 'error'
12
+ bling_event.status = "error"
15
13
  bling_event.message = e.to_json
16
14
  ensure
17
- bling_event.body = order.to_json
18
15
  bling_event.save!
19
16
  end
20
17
  end
18
+
21
19
  end
22
20
  end
@@ -2,8 +2,14 @@ module SolidusBling
2
2
  class Account < ApplicationRecord
3
3
  has_many :payment_methods, dependent: :destroy
4
4
  has_many :shipping_methods, dependent: :destroy
5
- has_many :products, dependent: :destroy
6
5
  has_many :sellers, dependent: :destroy
7
6
  accepts_nested_attributes_for :payment_methods, :shipping_methods, :sellers
7
+
8
+ def check_token
9
+ return if client_id.blank? || client_secret.blank? || refresh_token.blank?
10
+ return if (token_expires_in - 1.day) > DateTime.now
11
+ Token.new.refresh self
12
+ end
13
+
8
14
  end
9
15
  end
@@ -1,136 +1,163 @@
1
1
  module SolidusBling
2
- class Order < SolidusBling::Api
2
+ class Order
3
3
 
4
- def initialize order
5
- super(SolidusBling::Account.first)
6
- @order = order
4
+ def initialize spree_order
5
+ @order = spree_order
7
6
  end
8
7
 
9
8
  def send
10
- if @order.present?
11
- contato = SolidusBling::Contact.new(@order, @account)
12
- hash_order = build_hash_order(@order, contato.info)
13
- begin
14
- attempts ||= 1
15
- req = Typhoeus.post("#{@account.api_base_url}/pedidos/vendas", headers: @headers, body: JSON.dump(hash_order))
16
- raise if req.code == 429
17
- rescue
18
- retry if (attempts += 1) < 5
19
- ensure
20
- json = JSON.parse(req.body)
21
- response_has_error?(json)
22
- if json.include? "data"
23
- @order.bling_order_id = json["data"]["id"]
24
- @order.save
25
- end
26
- end
27
- end
28
- end
9
+ @account = SolidusBling::Account.first
10
+ @account.check_token
11
+ BlingApi.access_token = @account.access_token
29
12
 
30
- private
31
-
32
- def build_hash_order order, contato
33
- {
34
- "numeroLoja": order.number,
35
- "data": order.completed_at.strftime("%Y-%m-%d"),
36
- "loja": {
37
- "id": @account.external_store_id
38
- },
39
- "contato": {
40
- "id": contato["id"]
41
- },
42
- "itens": build_array_items(order.line_items),
43
- "vendedor": {
44
- "id": @account.sellers.first.external_id
45
- },
46
- "transporte": build_hash_transporte(order),
47
- "parcelas": build_array_parcelas(order),
48
- "desconto": {
49
- "valor": order.promo_total&.to_f.abs || 0,
50
- "unidade": "REAL"
51
- },
52
- "totalProdutos": order.item_total.to_f,
53
- "total": order.total.to_f,
54
- "observacoes": " Nº Pedido Loja: #{order.number}",
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)}#{build_order_url(order)}",
56
- "categoria": {
57
- "id": @account.incoming_category_id
58
- }
59
- }
13
+ contato = costumer
14
+ items = products
15
+ parcelas = installments
16
+ observacoes_internas = internal_observations
17
+ transporte = shipment
18
+
19
+ bling_order = BlingApi::Order.new(
20
+ id_contato: contato.id,
21
+ items: items,
22
+ parcelas: parcelas,
23
+ numero_loja: @order.number,
24
+ data: @order.completed_at.strftime("%Y-%m-%d"),
25
+ total_produtos: @order.item_total.to_f,
26
+ total: @order.total.to_f,
27
+ id_loja: @account.external_store_id,
28
+ observacoes: "Número do pedido loja: #{@order.number}",
29
+ observacoes_internas: observacoes_internas,
30
+ valor_desconto: @order.adjustment_total,
31
+ id_categoria: @account.incoming_category_id,
32
+ transporte: transporte,
33
+ id_vendedor: @account.sellers.first.external_id
34
+ ).create
60
35
  end
61
36
 
62
- def build_order_url order
63
- "Link para o pedido: #{order.store.url}/orders/#{order.number}/token/#{order.guest_token}"
37
+ def costumer
38
+ contato = BlingApi::Customer.find_by_tax_id(@order.tax_id)
39
+ if contato
40
+ contato.update(
41
+ pessoa_juridica: @order.tax_id.length > 14 ? true : false,
42
+ numero_documento: @order.tax_id,
43
+ **build_customer
44
+ )
45
+ else
46
+ contato = BlingApi::Customer.new(
47
+ pessoa_juridica: @order.tax_id.length > 14 ? true : false,
48
+ numero_documento: @order.tax_id,
49
+ **build_customer
50
+ ).create
51
+ end
52
+ contato
64
53
  end
65
54
 
66
- def build_array_items items
67
- items.map do |item|
68
- bling_product = SolidusBling::Product.find_by(sku: item.sku)
55
+ def products
56
+ @order.line_items.map do |item|
57
+ product = BlingApi::Product.find_by_sku(item.sku)
69
58
  {
70
- "id": bling_product.external_id,
59
+ "id": product.id,
71
60
  "quantidade": item.quantity,
72
61
  "valor": item.price.to_f,
73
62
  "produto": {
74
- "id": bling_product.external_id
63
+ "id": product.id
75
64
  }
76
- }
77
- end
65
+ }
66
+ end.compact
78
67
  end
79
68
 
80
- def build_array_parcelas order
81
- @parcelas = 1
82
- if order.payments.last.source
83
- @parcelas = order.payments.last.source.try(:installments) || 1
84
- end
85
- valor_parcela = order.total.to_f / @parcelas
69
+ def installments
70
+ @parcelas = @order.payments.last.source.try(:installments) || 1
71
+ valor_parcela = @order.total.to_f / @parcelas
86
72
  1.upto(@parcelas).map do |parcela|
87
73
  {
88
- "dataVencimento": (order.completed_at + parcela.months).strftime("%Y-%m-%d"),
89
- "valor": valor_parcela,
90
- "formaPagamento": {
91
- "id": @account.payment_methods.find_by(spree_payment_method_id: order.payments.last.payment_method_id).external_id
74
+ dataVencimento: (@order.completed_at + parcela.months).strftime("%Y-%m-%d"),
75
+ valor: valor_parcela,
76
+ formaPagamento: {
77
+ id: @account.payment_methods.find_by(spree_payment_method_id: @order.payments.last.payment_method_id).external_id
92
78
  }
93
79
  }
94
80
  end
95
81
  end
96
82
 
97
- def build_hash_transporte order
98
- shipping_method = @account.shipping_methods.find_by(spree_shipping_method_id: order.shipments.last.shipping_method.id)
83
+ def internal_observations
84
+ "Pagamento: #{@parcelas}x R$ #{(@order.total.to_f / @parcelas).round(2)}" +
85
+ "\n" +
86
+ "Forma de envio: #{@order.shipments.last.selected_shipping_rate.name}" +
87
+ "\n" +
88
+ "#{build_cupons(@order.promotions)}" +
89
+ "\n" +
90
+ "#{build_order_url}"
91
+ end
92
+
93
+ def shipment
94
+ shipping_method = @account.shipping_methods.find_by(spree_shipping_method_id: @order.shipments.last.shipping_method.id)
99
95
  servico = shipping_method.nil? ? "" : shipping_method.alias
100
96
  transportadora = shipping_method.nil? ? "" : shipping_method.company
101
97
  {
102
- "fretePorConta": 1,
103
- "frete": order.shipment_total.to_f,
104
- "quantidadeVolumes": 1,
105
- "contato": {
106
- "nome": transportadora,
98
+ fretePorConta: 1,
99
+ frete: @order.shipment_total.to_f,
100
+ quantidadeVolumes: 1,
101
+ contato: {
102
+ nome: transportadora
107
103
  },
108
- "etiqueta": {
109
- "nome": order.ship_address.name,
110
- "endereco": order.ship_address.address1,
111
- "numero": order.ship_address.number,
112
- "complemento": order.ship_address.address2,
113
- "municipio": order.ship_address.city,
114
- "uf": order.ship_address.state.abbr,
115
- "bairro": order.ship_address.district,
116
- "cep": order.ship_address.zipcode,
117
- "nomePais": "Brasil"
104
+ etiqueta: {
105
+ nome: @order.ship_address.name,
106
+ endereco: @order.ship_address.address1,
107
+ numero: @order.ship_address.number,
108
+ complemento: @order.ship_address.address2,
109
+ municipio: @order.ship_address.city,
110
+ uf: @order.ship_address.state.abbr,
111
+ bairro: @order.ship_address.district,
112
+ cep: @order.ship_address.zipcode,
113
+ nomePais: "Brasil"
118
114
  },
119
- "volumes": [
115
+ volumes: [
120
116
  {
121
- "servico": servico,
122
- "codigoRastreamento": ""
117
+ servico: servico,
118
+ codigoRastreamento: ""
123
119
  }
124
120
  ]
125
121
  }
126
122
  end
127
123
 
124
+ def build_customer
125
+ {
126
+ nome: @order.bill_address.name,
127
+ telefone: @order.bill_address.phone,
128
+ email: @order.email,
129
+ endereco: {
130
+ "endereco" => @order.bill_address.address1,
131
+ "cep" => @order.bill_address.zipcode,
132
+ "bairro" => @order.bill_address.district,
133
+ "municipio" => @order.bill_address.city,
134
+ "uf" => @order.bill_address.state.abbr,
135
+ "numero" => @order.bill_address.number,
136
+ "complemento" => @order.bill_address.address2,
137
+ },
138
+ endereco_cobranca: {
139
+ "endereco" => @order.bill_address.address1,
140
+ "cep" => @order.bill_address.zipcode,
141
+ "bairro" => @order.bill_address.district,
142
+ "municipio" => @order.bill_address.city,
143
+ "uf" => @order.bill_address.state.abbr,
144
+ "numero" => @order.bill_address.number,
145
+ "complemento" => @order.bill_address.address2,
146
+ }
147
+ }
148
+ end
149
+
128
150
  def build_cupons cupons
129
- string_cupons = ''
151
+ string_cupons = ""
130
152
  if !cupons.empty?
131
- string_cupons = "Cupons utilizados: #{cupons.pluck(:name).join(", ")}"
153
+ string_cupons = "Cupons utilizados: #{cupons.pluck(:name).join(", ")}"
132
154
  end
133
155
  string_cupons
134
156
  end
157
+
158
+ def build_order_url
159
+ "Link para o pedido: #{@order.store.url}/orders/#{@order.number}/token/#{@order.guest_token}"
160
+ end
161
+
135
162
  end
136
- end
163
+ end
@@ -0,0 +1,44 @@
1
+ module SolidusBling
2
+ class Token < ::Ac::Base
3
+ BASE_URL = "https://www.bling.com.br/Api/v3"
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def authorize bling_account, code
10
+ basic_encoded = Base64.strict_encode64("#{bling_account.client_id}:#{bling_account.client_secret}")
11
+ headers = {
12
+ "Content-Type": "application/x-www-form-urlencoded",
13
+ Authorization: "Basic #{basic_encoded}"
14
+ }
15
+ body = {
16
+ code: code,
17
+ grant_type: "authorization_code"
18
+ }
19
+ response_json = post("/oauth/token", headers:, body:).json
20
+ bling_account.update(
21
+ access_token: response_json["access_token"],
22
+ token_expires_in: DateTime.now.utc + response_json["expires_in"].seconds,
23
+ refresh_token: response_json["refresh_token"]
24
+ )
25
+ rescue
26
+ false
27
+ end
28
+
29
+ def refresh bling_account
30
+ response_json = BlingApi::Client.new.refresh_token(
31
+ client_id: bling_account.client_id,
32
+ client_secret: bling_account.client_secret,
33
+ refresh_token: bling_account.refresh_token
34
+ )
35
+ bling_account.update(
36
+ access_token: response_json["access_token"],
37
+ token_expires_in: DateTime.now.utc + response_json["expires_in"].seconds,
38
+ refresh_token: response_json["refresh_token"]
39
+ )
40
+ rescue
41
+ false
42
+ end
43
+ end
44
+ end
@@ -3,30 +3,10 @@ module SolidusBling
3
3
  include Omnes::Subscriber
4
4
 
5
5
  handle :order_finalized,
6
- with: :send_order_to_bling,
7
- id: :send_order_to_bling
8
-
9
- handle :bling_products_updated,
10
- with: :products_updated,
11
- id: :products_updated
12
-
13
- handle :bling_contact_created,
14
- with: :contato_created,
15
- id: :contato_created
6
+ with: :send_order_to_bling
16
7
 
17
8
  def send_order_to_bling event, debug_info = {}
18
- method = __method__.to_s
19
- SolidusBling::OrderJob.perform_later(event: event.payload, method_name: method)
20
- end
21
-
22
- def contato_created event, debug_info = {}
23
- method = __method__.to_s
24
- SolidusBling::ContactJob.perform_later(event: event.payload, method_name: method)
25
- end
26
-
27
- def products_updated event, debug_info = {}
28
- method = __method__.to_s
29
- SolidusBling::ProductJob.perform_later(event: event.payload, method_name: method)
9
+ SolidusBling::OrderJob.perform_later(event: event.payload)
30
10
  end
31
11
  end
32
12
  end
@@ -1,10 +1,5 @@
1
1
  <%= form_with model: bling_account, url: form_url do |form| %>
2
2
  <h6>Dados da conta</h6>
3
- <div>
4
- <%= form.label :app_name, "Nome do Aplicativo: " %>
5
- <%= form.text_field :app_name %>
6
- </div>
7
-
8
3
  <div>
9
4
  <%= form.label :client_id, "Client ID: " %>
10
5
  <%= form.text_field :client_id %>
@@ -21,8 +16,18 @@
21
16
  </div>
22
17
 
23
18
  <div>
24
- <%= form.label :api_base_url, "API URL: " %>
25
- <%= form.text_field :api_base_url %>
19
+ <%= form.label :redirect_url, "Redirect URL: " %>
20
+ <%= form.text_field :redirect_url %>
21
+ </div>
22
+
23
+ <div>
24
+ <%= form.label :state, "State: " %>
25
+ <%= form.text_field :state %>
26
+ </div>
27
+
28
+ <div>
29
+ <%= form.label :access_token, "Access Token: " %>
30
+ <%= form.text_field :access_token %>
26
31
  </div>
27
32
 
28
33
  <div>
@@ -73,4 +78,12 @@
73
78
  </div>
74
79
 
75
80
  <%= form.submit "Salvar" %>
76
- <% end %>
81
+ <% end %>
82
+
83
+ <div>
84
+ <input value="https://www.bling.com.br/Api/v3/oauth/authorize?response_type=code&client_id=<%= bling_account.client_id %>&state=<%= bling_account.state %>&scopes=98308+98309+98310+98313+98314+507943+5990556+6631498+106168710+182224097+199272829+200802821+220621674+318257556+318257565+318257568+318257570+318257583+333936575+363921589+363921590+363921591+363921592+363953167+363953556+791588404+875116881+1869535257+5862218180+13645012997+13645013013">
85
+ <a target="_blank" class="" href="https://www.bling.com.br/Api/v3/oauth/authorize?response_type=code&client_id=<%= bling_account.client_id %>&state=<%= bling_account.state %>&scopes=98308+98309+98310+98313+98314+507943+5990556+6631498+106168710+182224097+199272829+200802821+220621674+318257556+318257565+318257568+318257570+318257583+333936575+363921589+363921590+363921591+363921592+363953167+363953556+791588404+875116881+1869535257+5862218180+13645012997+13645013013">
86
+ <svg style="width: 24px; height: 24px;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
87
+ <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"></path></svg>
88
+ </a>
89
+ </div>
@@ -0,0 +1 @@
1
+ <%= render "form", bling_account: @bling_account, form_url: admin_solidus_bling_account_path(@bling_account.id) %>
@@ -0,0 +1,13 @@
1
+ <%= link_to "Criar", new_admin_solidus_bling_account_path %>
2
+ <div>
3
+ <% @accounts.each do |account| %>
4
+ <div>
5
+ <div>
6
+ Nome do aplicativo:
7
+ <span>ID - <%= account.id %></span>
8
+ </div>
9
+ <%= link_to "Editar", edit_admin_solidus_bling_account_path(account.id) %>
10
+ <%= link_to "Excluir", admin_solidus_bling_account_path(account.id), method: :delete %>
11
+ </div>
12
+ <% end %>
13
+ </div>
@@ -1,2 +1,2 @@
1
1
 
2
- <%= render "form", bling_account: @bling_account, form_url: admin_accounts_path %>
2
+ <%= render "form", bling_account: @bling_account, form_url: admin_solidus_bling_accounts_path %>
data/bin/meu_sandbox ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bin/rails db:environment:set RAILS_ENV=development
4
+
5
+ set -e
6
+ test -z "${DEBUG+empty_string}" || set -x
7
+
8
+ if [ -z "$SOLIDUS_BRANCH" ]
9
+ then
10
+ echo "~~> Use 'export SOLIDUS_BRANCH=[main|v3.2|...]' to control the Solidus branch"
11
+ SOLIDUS_BRANCH="main"
12
+ fi
13
+ echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
14
+
15
+ extension_name="solidus_bling"
16
+
17
+ # Stay away from the bundler env of the containing extension.
18
+ function unbundled {
19
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
20
+ }
21
+
22
+ rm -rf ./sandbox
23
+ unbundled bundle exec rails new sandbox \
24
+ --database=postgresql \
25
+ --skip-bundle \
26
+ --skip-git \
27
+ --skip-keeps \
28
+ --skip-rc \
29
+ --skip-spring \
30
+ --skip-test \
31
+ --skip-javascript
32
+
33
+ if [ ! -d "sandbox" ]; then
34
+ echo 'sandbox rails application failed'
35
+ exit 1
36
+ fi
37
+
38
+ cd ./sandbox
39
+ cat <<RUBY >> Gemfile
40
+ gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
41
+ gem 'rails-i18n'
42
+ gem 'solidus_i18n'
43
+
44
+ gem '$extension_name', path: '..'
45
+
46
+ group :test, :development do
47
+ platforms :mri do
48
+ gem 'pry-byebug'
49
+ end
50
+ end
51
+ RUBY
52
+
53
+ unbundled bundle install --gemfile Gemfile
54
+
55
+ unbundled bundle exec rake db:drop db:create
56
+
57
+ unbundled bundle exec rails generate solidus:install \
58
+ --auto-accept \
59
+ --payment-method=none \
60
+ --frontend=starter \
61
+ $@
62
+
63
+ unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
64
+
65
+ echo
66
+ echo "🚀 Sandbox app successfully created for $extension_name!"
67
+ echo "🧪 This app is intended for test purposes."
@@ -2,4 +2,4 @@ pt-BR:
2
2
  spree:
3
3
  admin:
4
4
  tab:
5
- bling_account: "Conta Bling"
5
+ bling_account: "Bling"
data/config/routes.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Spree::Core::Engine.routes.draw do
4
+ # Add your extension routes here
4
5
  namespace :admin do
5
- resources :accounts
6
- resources :bling_products, only: [:update]
6
+ namespace :solidus_bling do
7
+ resources :accounts do
8
+ get "authorize", on: :collection
9
+ end
10
+ end
7
11
  end
8
12
  end