pay-asaas 0.1.0.pre.alpha → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b569b26d2eacd591aad245cd92687459f6c419d5182a5514caeee1558f1b32e
4
- data.tar.gz: 0c91f916c6b7d83e633c1a5aa1a9caaec037dbfa00b52097384b1733a1dd2cfa
3
+ metadata.gz: e8740ebeaaae97eef969cf19ad4330ee537c3830cb851b7797a77d34b2681523
4
+ data.tar.gz: a8f0ff7411dcb34025fe21c6d85737fb4eff504e095a5feb264056633fe7af5f
5
5
  SHA512:
6
- metadata.gz: 160e4949149cdd12370128a59bdca7e4f02e9188bb61bd593053238a69a43c3186e4353863d962a90f78b462d78bb0ae6e11a2974d1fafe4d296d8b940b357a6
7
- data.tar.gz: 33baf9d3695fdd9627fa890a0a2d7ddfc530cfd95798352debd4ab103f9a033207e2cc58569982d1f4571456da7a8b96e8ed9b4744363fc225f937f57f2fca68
6
+ metadata.gz: a9c796a31134dc0cd08a28adfa0a01c827e7156a0740f6b10035bc53375be0f78b6164bd4e5625d8bd16e0098fb9cdde6e0b47c7809c115e0203452815fae9ce
7
+ data.tar.gz: 6fd4b710b4cc89cbd7e078f294aeea43a8109ed4f8e2bf905a5ea82235b0831624317b95063343526b7f61aefaa86f403cb708a0bdc274f89db638b0c4c48a53
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Asaas payment processor for Pay gem (Payments engine for Ruby on Rails);
4
4
 
5
+ > [!WARNING]
5
6
  > This gem is a work in progress and is not ready for production use.
6
7
 
7
8
  > This gem is not affiliated with Asaas.
@@ -11,10 +12,9 @@ The goal for the first implementation is to support the following features:
11
12
  - [x] Customer creation
12
13
  - [x] Make a payment with PIX
13
14
  - [x] Support basic webhooks needed for the payment process
15
+ - [x] Pix QRCode sync
14
16
 
15
17
  Following features will be implemented in the future and I will be happy to receive contributions:
16
-
17
- - [ ] Pix QRCode sync
18
18
  - [ ] Credit Cards
19
19
  - [ ] Subscriptions
20
20
 
@@ -23,7 +23,7 @@ Following features will be implemented in the future and I will be happy to rece
23
23
  Install the gem and add to the application's Gemfile by executing:
24
24
 
25
25
  ```bash
26
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG;
26
+ bundle add pay-asaas;
27
27
  ```
28
28
 
29
29
  > Install pay gem if you haven't already: https://github.com/pay-rails/pay/blob/main/docs/1_installation.md
@@ -53,12 +53,12 @@ Pay will also check environment variables for API keys:
53
53
 
54
54
  ## Customer
55
55
 
56
- **IMPORTANT**: For this add the document column to users table.
57
-
58
- The customer works the same as the other processors, but with the document additional field.
56
+ **IMPORTANT**: In order to create a customer with pay-asaas, you need to provide a document (cpf or cnpj) to the user. This can be in the form of the following columns, in order of preference:
57
+ - `document`
58
+ - `cpf`
59
+ - `cnpj`
59
60
 
60
- The document is not required to create the customer but is required to process payments. The document can be cpf ou cnpj
61
- without mask.
61
+ In asaas, the document is not required to create the customer but is required to process payments, as such, we choose to make the field mandatory in this gem.
62
62
 
63
63
  ## Charge
64
64
 
@@ -66,6 +66,8 @@ This first version of the gem will only support PIX payments.
66
66
 
67
67
  ```ruby
68
68
  @user.payment_processor.charge(15_00)
69
+
70
+ @user.payment_processor.charge(15_00, { attrs: { order_id: @order.id } })
69
71
  ```
70
72
 
71
73
  ## Webhooks
@@ -95,6 +97,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
95
97
  to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
96
98
  the [code of conduct](https://github.com/[USERNAME]/pay-asaas/blob/master/CODE_OF_CONDUCT.md).
97
99
 
100
+ ### Running tests
101
+
102
+ In order to run the test, first add a .env with fake credentials at the root of the project, and create a database in the `spec/dummy` folder.
103
+
98
104
  ## License
99
105
 
100
106
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ require "pay/asaas/client"
2
+ require "pay/asaas/api"
3
+
4
+ class Pay::Asaas::Api::CreditCard < Pay::Asaas::ApiClient
5
+ def self.resource_key
6
+ "creditCard"
7
+ end
8
+
9
+ def self.tokenize(params:)
10
+ request(:post, "creditCards/tokenize", body: params.to_json)
11
+ end
12
+ end
@@ -5,4 +5,8 @@ class Pay::Asaas::Api::Payment < Pay::Asaas::ApiClient
5
5
  def self.resource_key
6
6
  "payments"
7
7
  end
8
+
9
+ def self.fetch_qr_code(processor_id)
10
+ request(:get, "#{resource_key}/#{processor_id}/pixQrCode")
11
+ end
8
12
  end
@@ -4,7 +4,8 @@ module Pay
4
4
  module Asaas
5
5
  class Charge < Pay::Charge
6
6
  store_accessor :data, :status
7
- store_accessor :data, :qr_code
7
+ store_accessor :data, :pix_code
8
+ after_create :sync_pix_qr_code
8
9
 
9
10
  def self.sync(charge_id, object: nil, try: 0, retries: 1)
10
11
  object ||= Pay::Asaas::Api::Payment.find(id: charge_id)
@@ -57,6 +58,16 @@ module Pay
57
58
  def refund!(amount_to_refund)
58
59
  raise NotImplementedError, "Refunding charges is not supported yet by the Asaas fake processor"
59
60
  end
61
+
62
+ def sync_pix_qr_code
63
+ return unless payment_method_type == "pix"
64
+
65
+ response = Pay::Asaas::Api::Payment.fetch_qr_code(processor_id)
66
+
67
+ update!(
68
+ pix_code: response["payload"],
69
+ )
70
+ end
60
71
  end
61
72
  end
62
73
  end
@@ -28,7 +28,6 @@ module Pay::Asaas
28
28
 
29
29
  def configure
30
30
  yield(configuration)
31
- configuration.validate!
32
31
  end
33
32
 
34
33
  def headers
@@ -44,6 +43,7 @@ module Pay::Asaas
44
43
  end
45
44
 
46
45
  def request(method, path, options = {})
46
+ configuration.validate!
47
47
  response = HTTParty.send(
48
48
  method,
49
49
  "#{configuration.base_url}/#{path}",
@@ -9,7 +9,21 @@ module Pay
9
9
  has_one :default_payment_method, -> { where(default: true) }, class_name: "Pay::Asaas::PaymentMethod"
10
10
 
11
11
  def api_record_attributes
12
- { email: email, name: customer_name, cpfCnpj: owner.document, externalReference: owner.id }
12
+ document = if owner.respond_to?(:document)
13
+ owner.document
14
+ elsif owner.respond_to?(:cpf)
15
+ owner.cpf
16
+ elsif owner.respond_to?(:cnpj)
17
+ owner.cnpj
18
+ else
19
+ raise StandardError, "The document attribute, and it's alternatives are not implemented for #{owner.class}"
20
+ end
21
+
22
+ raise StandardError, "The document attribute is required" if document.nil?
23
+
24
+ document = document.gsub(/[^\d]/, "")
25
+
26
+ { email: email, name: customer_name, cpfCnpj: document, externalReference: owner.id }
13
27
  end
14
28
 
15
29
  def api_record
@@ -47,6 +61,8 @@ module Pay
47
61
  payment_method_type: "pix",
48
62
  }
49
63
 
64
+ attrs = attrs.merge(options[:attrs]) if options[:attrs]
65
+
50
66
  charge = charges.find_or_initialize_by(processor_id: transaction["id"])
51
67
  charge.update(attrs)
52
68
  charge
@@ -1,5 +1,5 @@
1
1
  module Pay
2
2
  module Asaas
3
- VERSION = "0.1.0-alpha"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  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.pre.alpha
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PedroAugustoRamalhoDuarte
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-12-29 00:00:00.000000000 Z
10
+ date: 2025-04-03 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -51,34 +51,6 @@ dependencies:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '8'
54
- - !ruby/object:Gem::Dependency
55
- name: database_cleaner-active_record
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- - !ruby/object:Gem::Dependency
69
- name: rspec-rails
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: 6.0.0
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: 6.0.0
82
54
  email:
83
55
  - pedroaugustorduarte@gmail.com
84
56
  executables: []
@@ -97,6 +69,7 @@ files:
97
69
  - config/routes.rb
98
70
  - lib/pay/asaas.rb
99
71
  - lib/pay/asaas/api.rb
72
+ - lib/pay/asaas/api/credit_card.rb
100
73
  - lib/pay/asaas/api/customer.rb
101
74
  - lib/pay/asaas/api/payment.rb
102
75
  - lib/pay/asaas/charge.rb