punto_pagos_rails 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 +4 -4
- data/lib/punto_pagos_rails/resource_extension.rb +5 -18
- data/lib/punto_pagos_rails/transaction_service.rb +8 -6
- data/lib/punto_pagos_rails/version.rb +1 -1
- data/spec/dummy/app/models/ticket.rb +9 -0
- data/spec/dummy/spec/lib/punto_pagos_rails/transaction_service_spec.rb +11 -2
- data/spec/rails_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0802b882684f0f88e366a6286bf88001576d7040
|
4
|
+
data.tar.gz: 0abf35bab91213a7d0e99ecd01a97c825b33cca7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c5528f759e9dd8be5c6604d2c1036ae84840f69401f7ce8e18b108b3345371806555d9538d982359cbd6e61ab60aadeb03ae6462b640c31d532a03e75d0de6
|
7
|
+
data.tar.gz: 15942f1a64c89f99f86dc81dc0df429bf1fcbe78d3bcf4398e0565c0d9cb35fdd283e0356df07d461215b8050d73aead3ac846b520e8d75a62e5d6e808a5d6dd
|
@@ -5,6 +5,10 @@ module PuntoPagosRails
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
+
include ActiveSupport::Callbacks
|
9
|
+
define_callbacks :payment_error
|
10
|
+
define_callbacks :payment_success
|
11
|
+
|
8
12
|
has_many :transactions, class_name: 'PuntoPagosRails::Transaction', foreign_key: :resource_id
|
9
13
|
|
10
14
|
def paid?
|
@@ -15,24 +19,7 @@ module PuntoPagosRails
|
|
15
19
|
end
|
16
20
|
|
17
21
|
module ClassMethods
|
18
|
-
|
19
|
-
def on_payment_error(&block)
|
20
|
-
@payment_error_cb = block
|
21
|
-
end
|
22
|
-
|
23
|
-
def on_payment_success(&block)
|
24
|
-
@payment_success_cb = block
|
25
|
-
end
|
26
|
-
|
27
|
-
def notify(resource, type)
|
28
|
-
if type == :error && @payment_error_cb
|
29
|
-
resource.instance_exec(&@payment_error_cb)
|
30
|
-
end
|
31
|
-
if type == :success && @payment_success_cb
|
32
|
-
resource.instance_exec(&@payment_success_cb)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
22
|
+
# TODO
|
36
23
|
end
|
37
24
|
end
|
38
25
|
end
|
@@ -27,10 +27,8 @@ module PuntoPagosRails
|
|
27
27
|
err = params[:error]
|
28
28
|
|
29
29
|
if notification.valid?(headers, params)
|
30
|
-
PuntoPagosRails.resource_class.notify(@resource, :success)
|
31
30
|
respond_success(tken)
|
32
31
|
else
|
33
|
-
PuntoPagosRails.resource_class.notify(@resource, :error)
|
34
32
|
respond_error(tken, err)
|
35
33
|
end
|
36
34
|
end
|
@@ -51,16 +49,20 @@ module PuntoPagosRails
|
|
51
49
|
def self.respond_success(token)
|
52
50
|
transaction = processing_transaction(token)
|
53
51
|
return if transaction.nil?
|
54
|
-
transaction.
|
55
|
-
|
52
|
+
transaction.resource.run_callbacks :payment_success do
|
53
|
+
transaction.complete
|
54
|
+
transaction.save
|
55
|
+
end
|
56
56
|
{ respuesta: SUCCESS_CODE, token: token }
|
57
57
|
end
|
58
58
|
|
59
59
|
def self.respond_error(token, error)
|
60
60
|
transaction = processing_transaction(token)
|
61
61
|
return if transaction.nil?
|
62
|
-
transaction.
|
63
|
-
|
62
|
+
transaction.resource.run_callbacks :payment_error do
|
63
|
+
transaction.reject_with(error)
|
64
|
+
transaction.save
|
65
|
+
end
|
64
66
|
{ respuesta: ERROR_CODE, error: error, token: token }
|
65
67
|
end
|
66
68
|
|
@@ -1,4 +1,13 @@
|
|
1
1
|
class Ticket < ActiveRecord::Base
|
2
2
|
include PuntoPagosRails::ResourceExtension
|
3
3
|
|
4
|
+
attr_reader :message
|
5
|
+
|
6
|
+
set_callback :payment_success, :after do
|
7
|
+
@message = "successful payment! #{self.id}"
|
8
|
+
end
|
9
|
+
|
10
|
+
set_callback :payment_error, :after do
|
11
|
+
@message = "error paying ticket #{self.id}"
|
12
|
+
end
|
4
13
|
end
|
@@ -11,7 +11,7 @@ RSpec.describe TransactionService do
|
|
11
11
|
let(:token) { 'XXXXX' }
|
12
12
|
let(:payment_process_url) { double }
|
13
13
|
let(:notification) { double }
|
14
|
-
let(:transaction) { Transaction.create }
|
14
|
+
let(:transaction) { PuntoPagosRails::Transaction.create(resource: ticket) }
|
15
15
|
|
16
16
|
before do
|
17
17
|
allow(PuntoPagos::Request).to receive(:new).and_return(request)
|
@@ -98,6 +98,11 @@ RSpec.describe TransactionService do
|
|
98
98
|
|
99
99
|
context "when the notification is valid" do
|
100
100
|
|
101
|
+
it "runs callback after successful payment" do
|
102
|
+
TransactionService.notificate({}, {})
|
103
|
+
expect(ticket.message).to eq("successful payment! #{ticket.id}")
|
104
|
+
end
|
105
|
+
|
101
106
|
it "the notification is completed" do
|
102
107
|
TransactionService.notificate({}, {})
|
103
108
|
expect(transaction.reload.state).to eq('completed')
|
@@ -107,12 +112,16 @@ RSpec.describe TransactionService do
|
|
107
112
|
context "when the notification is invalid" do
|
108
113
|
before do
|
109
114
|
allow(notification).to receive(:valid?).with({}, {}).and_return(false)
|
115
|
+
TransactionService.notificate({}, {})
|
110
116
|
end
|
111
117
|
|
112
118
|
it "the notification is rejected" do
|
113
|
-
TransactionService.notificate({}, {})
|
114
119
|
expect(transaction.reload.state).to eq('rejected')
|
115
120
|
end
|
121
|
+
|
122
|
+
it "calls error callbacks" do
|
123
|
+
expect(ticket.message).to eq("error paying ticket #{ticket.id}")
|
124
|
+
end
|
116
125
|
end
|
117
126
|
|
118
127
|
context "when the notification is completed" do
|
data/spec/rails_helper.rb
CHANGED
@@ -17,6 +17,8 @@ RSpec.configure do |config|
|
|
17
17
|
config.order = :random
|
18
18
|
config.render_views
|
19
19
|
config.include FactoryGirl::Syntax::Methods
|
20
|
+
config.filter_run :focus
|
21
|
+
config.run_all_when_everything_filtered = true
|
20
22
|
|
21
23
|
FactoryGirl::SyntaxRunner.send(:include, RSpec::Mocks::ExampleMethods)
|
22
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punto_pagos_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Segovia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|