moiper 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.
- data/README.md +56 -5
- data/lib/moiper/payment.rb +3 -3
- data/lib/moiper/version.rb +1 -1
- data/spec/moiper/payment_spec.rb +15 -0
- metadata +7 -7
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Moiper
|
2
2
|
|
3
|
-
Moip payment service integration library.
|
3
|
+
[Moip payment service](http://moip.com.br/) integration library.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -35,7 +35,7 @@ Moiper.configure do |config|
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
Then, you can request a new payment authorization:
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
payment = Moiper::Payment.new(
|
@@ -48,12 +48,18 @@ payment = Moiper::Payment.new(
|
|
48
48
|
|
49
49
|
response = payment.checkout
|
50
50
|
|
51
|
-
|
51
|
+
if response.success?
|
52
|
+
redirect_to response.checkout_url
|
53
|
+
else
|
54
|
+
render :text => response.errors.to_sentence
|
55
|
+
end
|
52
56
|
```
|
53
57
|
|
58
|
+
You need to redirect your user to the url returned by `response.checkout_url`. After the user accepts or rejects your payment request, he will be redirected to the `return_url` you specified on the payment. In case of possible errors during the payment request phase, you can access then through the `response.errors` method.
|
59
|
+
|
54
60
|
### Notifications
|
55
61
|
|
56
|
-
Moip will notify your application
|
62
|
+
Moip will notify your application about order updates through [NASP](http://labs.moip.com.br/referencia/nasp/). Moiper provides a Rails controller helper to you can easily intercept these notifications with the `moip_notification` method.
|
57
63
|
|
58
64
|
```ruby
|
59
65
|
class OrdersController < ApplicationController
|
@@ -61,15 +67,60 @@ class OrdersController < ApplicationController
|
|
61
67
|
|
62
68
|
def confirm
|
63
69
|
moip_notification do |notification|
|
64
|
-
# Here you can update your database with updated information
|
70
|
+
# Here you can update your database with updated information.
|
71
|
+
# Ex:
|
65
72
|
@order = Order.find_by_unique_identifier(notification.id)
|
66
73
|
@order.update_attribute :status, notification.payment_status
|
67
74
|
@order.save
|
75
|
+
|
76
|
+
# Moip will recognize the request as successfully if the statuses
|
77
|
+
# are 200, 201, 202, 203, 204, 205, 206 or 207.
|
78
|
+
head 200
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
71
82
|
```
|
72
83
|
|
84
|
+
#### Payment Status
|
85
|
+
|
86
|
+
Following are the possible payment statuses returned by the `Moip::Notification#payment_status`.
|
87
|
+
|
88
|
+
* `authorized`
|
89
|
+
* `started`
|
90
|
+
* `payment_form_printed`
|
91
|
+
* `finished`
|
92
|
+
* `canceled`
|
93
|
+
* `under_analysis`
|
94
|
+
* `returned`
|
95
|
+
* `reimbursed`
|
96
|
+
|
97
|
+
#### Payment Methods
|
98
|
+
|
99
|
+
Following are the possible financial institutions returned by the `Moip::Notification#payment_method`.
|
100
|
+
|
101
|
+
* `payment_form`
|
102
|
+
* `credit_card`
|
103
|
+
* `debit`
|
104
|
+
* `debit_card`
|
105
|
+
* `financing`
|
106
|
+
* `moip_account`
|
107
|
+
|
108
|
+
#### Financial Institution
|
109
|
+
|
110
|
+
Following are the possible financial institutions returned by the `Moip::Notification#financial_institution`.
|
111
|
+
|
112
|
+
* MoIP
|
113
|
+
* Visa
|
114
|
+
* AmericanExpress
|
115
|
+
* Mastercard
|
116
|
+
* Diners
|
117
|
+
* BancoDoBrasil
|
118
|
+
* Bradesco
|
119
|
+
* Itau
|
120
|
+
* Hipercard
|
121
|
+
* Paggo
|
122
|
+
* Banrisul
|
123
|
+
|
73
124
|
## Disclaimer
|
74
125
|
|
75
126
|
This gem is being developed in a workshop-like manner, during the trainee training program at Tagview, so the students can understand concepts such as open source development, TDD, API integration and documentation.
|
data/lib/moiper/payment.rb
CHANGED
@@ -35,14 +35,14 @@ module Moiper
|
|
35
35
|
xml.EnviarInstrucao {
|
36
36
|
xml.InstrucaoUnica {
|
37
37
|
xml.Razao description
|
38
|
-
xml.IdProprio id
|
38
|
+
xml.IdProprio id if id
|
39
39
|
|
40
40
|
xml.Valores {
|
41
41
|
xml.Valor price, :moeda => "BRL"
|
42
42
|
}
|
43
43
|
|
44
|
-
xml.URLNotificacao notification_url
|
45
|
-
xml.URLRetorno return_url
|
44
|
+
xml.URLNotificacao notification_url if notification_url
|
45
|
+
xml.URLRetorno return_url if return_url
|
46
46
|
}
|
47
47
|
}
|
48
48
|
end
|
data/lib/moiper/version.rb
CHANGED
data/spec/moiper/payment_spec.rb
CHANGED
@@ -104,5 +104,20 @@ describe Moiper::Payment do
|
|
104
104
|
|
105
105
|
it { doc.at_css("InstrucaoUnica > URLRetorno").text.should eq "http://example.org/thank_you" }
|
106
106
|
it { doc.at_css("InstrucaoUnica > URLNotificacao").text.should eq "http://example.org/moip/notification" }
|
107
|
+
|
108
|
+
context "when no id is informed" do
|
109
|
+
before { payment.id = nil }
|
110
|
+
it { doc.at_css("InstrucaoUnica > IdProprio").should be_nil }
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when no notification_url is informed" do
|
114
|
+
before { payment.notification_url = nil }
|
115
|
+
it { doc.at_css("InstrucaoUnica > URLNotificacao").should be_nil }
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when no return_url is informed" do
|
119
|
+
before { payment.return_url = nil }
|
120
|
+
it { doc.at_css("InstrucaoUnica > URLRetorno").should be_nil }
|
121
|
+
end
|
107
122
|
end
|
108
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moiper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-01-23 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152746220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152746220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152745700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152745700
|
36
36
|
description: Moip payment service integration library.
|
37
37
|
email:
|
38
38
|
- rnavarro1@gmail.com
|
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
segments:
|
78
78
|
- 0
|
79
|
-
hash:
|
79
|
+
hash: 1028028193519655170
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash:
|
88
|
+
hash: 1028028193519655170
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
91
|
rubygems_version: 1.8.11
|