pay-asaas 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8740ebeaaae97eef969cf19ad4330ee537c3830cb851b7797a77d34b2681523
4
- data.tar.gz: a8f0ff7411dcb34025fe21c6d85737fb4eff504e095a5feb264056633fe7af5f
3
+ metadata.gz: e6fce30ee5fbaee0c63c697c766902af8971425a70c32b03270e227b1eac7085
4
+ data.tar.gz: 278b2b442a0ffc52074ccb4a14acc84640b18a3a56cf6409f54731c021415bac
5
5
  SHA512:
6
- metadata.gz: a9c796a31134dc0cd08a28adfa0a01c827e7156a0740f6b10035bc53375be0f78b6164bd4e5625d8bd16e0098fb9cdde6e0b47c7809c115e0203452815fae9ce
7
- data.tar.gz: 6fd4b710b4cc89cbd7e078f294aeea43a8109ed4f8e2bf905a5ea82235b0831624317b95063343526b7f61aefaa86f403cb708a0bdc274f89db638b0c4c48a53
6
+ metadata.gz: '018adb7590219b99cf4ce86070c66b46c63b511b790c1db44a09b68360c61058f7b0880f5dbb0f7a6cdf6acf60ecab6bfc3c092e9a77b8d0b79526ecdc7335bd'
7
+ data.tar.gz: 457704afa98597c321b37a1bc447fc5087157e8df34ae84bbc3433f1629eea1d58adaa7fa5aa5e136ed8e0ecb5681857a1d7798c9f9f9f3727cf98a605a5219e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2025-06-13
4
+
5
+ - Fixes payment sync in webhooks
6
+ - Does not create charge the not exists inside the webhook processor
7
+
3
8
  ## [0.1.0] - 2024-12-26
4
9
 
5
10
  - Initial release
data/README.md CHANGED
@@ -37,7 +37,7 @@ bundle add pay-asaas;
37
37
  ```yml
38
38
  asaas:
39
39
  api_key: xxxx
40
- api_url: https://sandbox.asaas.com/api/v3 # or https://www.asaas.com/api/v3
40
+ api_url: https://api-sandbox.asaas.com/v3 # or https://api.asaas.com/v3
41
41
  webhook_access_key: xxxx
42
42
  ```
43
43
 
@@ -72,16 +72,35 @@ This first version of the gem will only support PIX payments.
72
72
 
73
73
  ## Webhooks
74
74
 
75
- The gem will provide a controller to handle the webhooks.
75
+ The gem provides a built-in controller to handle webhooks from Asaas. These webhooks are essential for keeping your payment records in sync with Asaas's systems.
76
76
 
77
- To configure webhooks on your payment processor, use the following URLs while replacing example.org with your own
78
- domain:
77
+ ### Configuration
79
78
 
80
- - Asaas: https://example.org/pay/webhooks/asaas
79
+ To configure webhooks in your Asaas dashboard, use the following URL (replace `example.org` with your domain):
80
+
81
+ - **Asaas Webhook URL**: `https://example.org/pay/webhooks/asaas`
82
+
83
+ ### Supported Events
84
+
85
+ The main goal of the webhooks right now is to sync payment statuses.
81
86
 
82
87
  > For now we listen to the events that are important for pix transactions. For more configuration options
83
88
  > see: https://github.com/pay-rails/pay/blob/main/docs/7_webhooks.md
84
89
 
90
+ ### Verify Webhooks
91
+
92
+ All incoming webhooks from Asaas will be verified using the `webhook_access_key` provided in the gem configuration.
93
+
94
+ ## Debugging
95
+
96
+ To debug HTTP requests made by our gem, which uses the httparty library, you can enable logging of all outgoing HTTP calls. Just add the following line to one of your initializers:
97
+
98
+ ```ruby
99
+ HTTParty::Basement.debug_output($stdout)
100
+ ```
101
+
102
+ This will print the full request and response details to the console, making it easier to troubleshoot issues during development.
103
+
85
104
  ## Development
86
105
 
87
106
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
@@ -10,27 +10,30 @@ module Pay
10
10
  def self.sync(charge_id, object: nil, try: 0, retries: 1)
11
11
  object ||= Pay::Asaas::Api::Payment.find(id: charge_id)
12
12
 
13
- pay_customer = Pay::Customer.find_by(processor: :asaas, processor_id: object.customer)
13
+ customer_processor_id = get_attribute(object, :customer)
14
+ charge_processor_id = get_attribute(object, :id)
15
+ pay_customer = Pay::Customer.find_by(processor: :asaas, processor_id: customer_processor_id)
16
+
17
+ # rubocop:disable Layout/LineLength
14
18
  if pay_customer.blank?
15
19
  Rails.logger.debug do
16
- "Pay::Customer #{object.customer} is not in the database while syncing Asaas Charge #{object.id}"
20
+ "Pay::Customer #{customer_processor_id} is not in the database while syncing Asaas Charge #{charge_processor_id}"
17
21
  end
18
22
  return
19
23
  end
24
+ # rubocop:enable Layout/LineLength
20
25
 
21
26
  attrs = {
22
27
  amount: get_attribute(object, :value).to_f * 100,
23
28
  status: get_attribute(object, :status),
24
29
  }
25
30
 
26
- # Update or create the charge
27
- if (pay_charge = pay_customer.charges.find_by(processor_id: object.id))
31
+ # Update the charge
32
+ if (pay_charge = pay_customer.charges.find_by(processor_id: charge_processor_id))
28
33
  pay_charge.with_lock do
29
34
  pay_charge.update!(attrs)
30
35
  end
31
36
  pay_charge
32
- else
33
- pay_customer.charges.create!(attrs.merge(processor_id: object.id))
34
37
  end
35
38
  rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
36
39
  try += 1
@@ -56,7 +59,7 @@ module Pay
56
59
  end
57
60
 
58
61
  def refund!(amount_to_refund)
59
- raise NotImplementedError, "Refunding charges is not supported yet by the Asaas fake processor"
62
+ raise NotImplementedError, "Refunding charges is not supported yet by the Asaas processor"
60
63
  end
61
64
 
62
65
  def sync_pix_qr_code
@@ -1,5 +1,5 @@
1
1
  module Pay
2
2
  module Asaas
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -4,8 +4,6 @@ module Pay
4
4
  class PaymentSync
5
5
  def call(event)
6
6
  Pay::Asaas::Charge.sync(event["payment"]["id"], object: event["payment"])
7
-
8
- # TODO: Add notifications
9
7
  end
10
8
  end
11
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pay-asaas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PedroAugustoRamalhoDuarte
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-03 00:00:00.000000000 Z
10
+ date: 2025-06-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport