solidus_inter 0.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e914a20c06aee6978f5e168cdcec9fab0e45e8d82c7c25c35c6826f40fe0bbd
4
- data.tar.gz: f4b4c1c9e6e3aaa1809659e44f5a8d9b16958a01983ab0b67efe97bec414c086
3
+ metadata.gz: 65574da9c18ba2b6a8614c875587a9b088c033b0aabfb5ff66781db662dfd5d5
4
+ data.tar.gz: f6781e3a2b08c876cca2b213f9d3911ec64573222356e2b9ba9ab59c36fa6f27
5
5
  SHA512:
6
- metadata.gz: f2717dc3520c55adb260ea9f54350914cea1fc9076f32389b9aed762113b05ba63d3e5d51c37d01141e3f9a82abcb4d519c855b33d9623e501351733d648f461
7
- data.tar.gz: 37640b8a2e34e04a45116f5eb43304f904fe505861cfad0bcff825d23d284589af4afed1cbd0e2dd1e23a23a10ae01f12de0430f05670f485c6484b01e0567c6
6
+ metadata.gz: d8335b7d7dee01e2616b261f919c1fdb621ff9c025adc39fb6e7f22d1b71e7272060a44689fc9a0b3bacc7ba6797c65c41da562a703655c89edd0753f46b1a17
7
+ data.tar.gz: 896f661ccde79b9153572302a552328ef32fdceee38a6b902bedb822fc3b8da58534fb1ea3c1388460a37ac98c7d606a69481af3bb15d64c5e4d8d799795550d
@@ -0,0 +1,5 @@
1
+ module SolidusInter
2
+ class Account < ApplicationRecord
3
+ belongs_to :spree_payment_method, class_name: "Spree::PaymentMethod"
4
+ end
5
+ end
@@ -61,8 +61,7 @@ module SolidusInter
61
61
  end
62
62
 
63
63
  def purchase(money, source, options = {})
64
- client = set_api_client
65
- inter_payment = client.get_payment(source.txid)
64
+ inter_payment = find_payment(source.txid)
66
65
  if inter_payment.paid?
67
66
  source.update(status: "approved")
68
67
  successful_response("Pagamento realizado", inter_payment.txid)
@@ -71,17 +70,31 @@ module SolidusInter
71
70
  end
72
71
  end
73
72
 
73
+ def should_skip_processing?(source)
74
+ inter_payment = find_payment(source.txid)
75
+ if inter_payment.paid?
76
+ false
77
+ else
78
+ true
79
+ end
80
+ end
81
+
74
82
  private
75
83
 
76
84
  def set_api_client
77
- ::InterApi::Client.new(
85
+ account = SolidusInter::Account.find_by(chave_pix: preferences[:chave_pix])
86
+ client = ::InterApi::Client.new(
78
87
  client_id: preferences[:client_id],
79
88
  client_secret: preferences[:client_secret],
80
89
  chave_pix: preferences[:chave_pix],
81
90
  conta_corrente: preferences[:conta_corrente],
82
91
  crt: temp_file(preferences[:crt]).path,
83
- key: temp_file(preferences[:key]).path
92
+ key: temp_file(preferences[:key]).path,
93
+ token: account&.token,
94
+ token_expires_at: account&.expires_at
84
95
  )
96
+ SolidusInter::Account.upsert({token: client.token, expires_at: client.token_expires_at, chave_pix: client.chave_pix, spree_payment_method_id: id}, unique_by: :chave_pix)
97
+ client
85
98
  end
86
99
 
87
100
  def temp_file content
@@ -0,0 +1,12 @@
1
+ class CreateSolidusInterAccounts < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_inter_accounts do |t|
4
+ t.string :chave_pix, index: { unique: true }
5
+ t.string :token
6
+ t.datetime :expires_at
7
+ t.integer :spree_payment_method_id
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusInter
4
- VERSION = "0.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_inter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-31 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -104,6 +104,7 @@ files:
104
104
  - LICENSE
105
105
  - README.md
106
106
  - Rakefile
107
+ - app/models/solidus_inter/account.rb
107
108
  - app/models/solidus_inter/inter_pix.rb
108
109
  - app/models/solidus_inter/pix_payment_source.rb
109
110
  - app/views/spree/admin/payments/source_forms/_inter_pix.html.erb
@@ -119,6 +120,7 @@ files:
119
120
  - config/locales/en.yml
120
121
  - config/routes.rb
121
122
  - db/migrate/20240527193953_create_solidus_inter_pix_payment_sources.rb
123
+ - db/migrate/20240603132203_create_solidus_inter_accounts.rb
122
124
  - lib/generators/solidus_inter/install/install_generator.rb
123
125
  - lib/generators/solidus_inter/install/templates/initializer.rb
124
126
  - lib/solidus_inter.rb