payment_gateway-mundipagg 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +88 -0
- data/MIT-LICENSE +7 -0
- data/README.md +67 -0
- data/Rakefile +5 -0
- data/lib/payment_gateway/mundipagg/base.rb +35 -0
- data/lib/payment_gateway/mundipagg/card.rb +142 -0
- data/lib/payment_gateway/mundipagg/customer.rb +67 -0
- data/lib/payment_gateway/mundipagg/order.rb +23 -0
- data/lib/payment_gateway/mundipagg/plan.rb +56 -0
- data/lib/payment_gateway/mundipagg/subscription.rb +56 -0
- data/lib/payment_gateway/mundipagg.rb +27 -0
- data/lib/payment_gateway-mundipagg.rb +9 -0
- data/payment_gateway-mundipagg.gemspec +23 -0
- data/spec/payment_gateway/mundipagg/card_spec.rb +27 -0
- data/spec/payment_gateway/mundipagg/customer_spec.rb +32 -0
- data/spec/payment_gateway/mundipagg/order_spec.rb +46 -0
- data/spec/payment_gateway/mundipagg/plan_spec.rb +9 -0
- data/spec/payment_gateway/mundipagg/subscription_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/helper_methods.rb +33 -0
- data/spec/support/request_mocks/mundipagg/card.rb +31 -0
- data/spec/support/request_mocks/mundipagg/customer.rb +45 -0
- data/spec/support/request_mocks/mundipagg/order.rb +54 -0
- data/spec/support/response_mocks/mundipagg/card.rb +59 -0
- data/spec/support/response_mocks/mundipagg/customer.rb +52 -0
- data/spec/support/response_mocks/mundipagg/order.rb +222 -0
- data/spec/support/shared_examples.rb +20 -0
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 282e280e42ca33cd04dc16ecd54c92bd88aa3d1d
|
4
|
+
data.tar.gz: e43e5e8a08db7256275d2c5290927599f063d61b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bebf6534ccc25b43d5cb40d88bc70e2d3d1f1124d26cb9598818a445070ee90899e5ce5ae72d02839cd22f7a15633a8772a28ba3405f86bb58ebee17eb7e947
|
7
|
+
data.tar.gz: fde3534aaf6a0da779fb9af099fc7d6176f638d2411aadc33aba10dddc7be5e488e8c30ba517999081388a226e53ec48534bedd8c867d96a629898a9fba705a3
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.tool-versions
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
payment_gateway-mundipagg (0.0.3)
|
5
|
+
activesupport (>= 3.0)
|
6
|
+
credit_card_validations (~> 3.4)
|
7
|
+
http (~> 3.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (5.1.4)
|
13
|
+
activesupport (= 5.1.4)
|
14
|
+
activesupport (5.1.4)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (~> 0.7)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
addressable (2.5.2)
|
20
|
+
public_suffix (>= 2.0.2, < 4.0)
|
21
|
+
byebug (9.1.0)
|
22
|
+
coderay (1.1.2)
|
23
|
+
concurrent-ruby (1.0.5)
|
24
|
+
crack (0.4.3)
|
25
|
+
safe_yaml (~> 1.0.0)
|
26
|
+
credit_card_validations (3.4.0)
|
27
|
+
activemodel (>= 3, <= 6)
|
28
|
+
activesupport (>= 3, <= 6)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
domain_name (0.5.20170404)
|
31
|
+
unf (>= 0.0.5, < 1.0.0)
|
32
|
+
hashdiff (0.3.7)
|
33
|
+
http (3.0.0)
|
34
|
+
addressable (~> 2.3)
|
35
|
+
http-cookie (~> 1.0)
|
36
|
+
http-form_data (>= 2.0.0.pre.pre2, < 3)
|
37
|
+
http_parser.rb (~> 0.6.0)
|
38
|
+
http-cookie (1.0.3)
|
39
|
+
domain_name (~> 0.5)
|
40
|
+
http-form_data (2.0.0)
|
41
|
+
http_parser.rb (0.6.0)
|
42
|
+
i18n (0.9.3)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
method_source (0.9.0)
|
45
|
+
minitest (5.11.1)
|
46
|
+
pry (0.11.3)
|
47
|
+
coderay (~> 1.1.0)
|
48
|
+
method_source (~> 0.9.0)
|
49
|
+
pry-byebug (3.5.1)
|
50
|
+
byebug (~> 9.1)
|
51
|
+
pry (~> 0.10)
|
52
|
+
public_suffix (3.0.1)
|
53
|
+
rspec (3.7.0)
|
54
|
+
rspec-core (~> 3.7.0)
|
55
|
+
rspec-expectations (~> 3.7.0)
|
56
|
+
rspec-mocks (~> 3.7.0)
|
57
|
+
rspec-core (3.7.0)
|
58
|
+
rspec-support (~> 3.7.0)
|
59
|
+
rspec-expectations (3.7.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.7.0)
|
62
|
+
rspec-mocks (3.7.0)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.7.0)
|
65
|
+
rspec-support (3.7.0)
|
66
|
+
safe_yaml (1.0.4)
|
67
|
+
thread_safe (0.3.6)
|
68
|
+
tzinfo (1.2.4)
|
69
|
+
thread_safe (~> 0.1)
|
70
|
+
unf (0.1.4)
|
71
|
+
unf_ext
|
72
|
+
unf_ext (0.0.7.4)
|
73
|
+
webmock (3.1.1)
|
74
|
+
addressable (>= 2.3.6)
|
75
|
+
crack (>= 0.3.2)
|
76
|
+
hashdiff
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
payment_gateway-mundipagg!
|
83
|
+
pry-byebug (~> 3.5)
|
84
|
+
rspec (~> 3.6)
|
85
|
+
webmock (~> 3.1)
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
1.16.1
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Felipe G. Hespanhol
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Payment Gateway - Mundipagg
|
2
|
+
|
3
|
+
This library provides an easy integration with Mundipagg services in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### 1 - Include `gem "payment_gateway-mundipagg"` in your Gemfile.
|
8
|
+
|
9
|
+
### 2 - Set your access key given by Mundipagg
|
10
|
+
|
11
|
+
If your use Rails, create a file in initializer containing following code:
|
12
|
+
|
13
|
+
```
|
14
|
+
PaymentGateway::Mundipagg.configure do |config|
|
15
|
+
config.access_key = "your-access-key-here"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
Or else configure it manually.
|
19
|
+
|
20
|
+
### 3 - Call the referred service module you want to use. E.g.:
|
21
|
+
|
22
|
+
```
|
23
|
+
require 'payment_gateway/mundipagg/plan'
|
24
|
+
|
25
|
+
mundipagg_plan = PaymentGateway::Mundipagg::Plan.new
|
26
|
+
mundipagg_plan.list # Lists all registered plans
|
27
|
+
```
|
28
|
+
|
29
|
+
## Available services at the moment
|
30
|
+
|
31
|
+
All methods receives a hash as described in Mundipagg docs (https://docs.mundipagg.com/reference) and returns parsed gateway responses also as described in the docs in ruby Hash format.
|
32
|
+
|
33
|
+
### Plan
|
34
|
+
|
35
|
+
Methods:
|
36
|
+
|
37
|
+
- list
|
38
|
+
- create
|
39
|
+
- destroy
|
40
|
+
|
41
|
+
### Card
|
42
|
+
|
43
|
+
- list
|
44
|
+
- create
|
45
|
+
- destroy
|
46
|
+
|
47
|
+
### Customer
|
48
|
+
|
49
|
+
- show
|
50
|
+
- list
|
51
|
+
- create
|
52
|
+
|
53
|
+
### Subscription
|
54
|
+
|
55
|
+
- list
|
56
|
+
- create
|
57
|
+
- create_from_plan
|
58
|
+
- cancel
|
59
|
+
|
60
|
+
### Order
|
61
|
+
|
62
|
+
- list
|
63
|
+
- create
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
MIT License. Copyright 2017 Felipe G. Hespanhol
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module PaymentGateway
|
4
|
+
module Mundipagg
|
5
|
+
|
6
|
+
class Base
|
7
|
+
class GatewayError < StandardError; end
|
8
|
+
class MissingAccessKeyError < StandardError; end
|
9
|
+
|
10
|
+
API_URL = 'https://api.mundipagg.com/core/v1'
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
access_key = PaymentGateway::Mundipagg.configuration.access_key
|
14
|
+
raise MissingAccessKeyError if access_key.nil? || access_key.eql?('')
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def request(method, url, options={ headers: {}, body: {}, params: {} })
|
20
|
+
headers = { 'Content-Type' => 'application/json' }
|
21
|
+
headers.merge!(options[:headers]) unless options[:headers].nil?
|
22
|
+
response = HTTP.basic_auth(user: PaymentGateway::Mundipagg.configuration.access_key, pass: '').
|
23
|
+
headers('Content-Type' => 'application/json').
|
24
|
+
send(method, url, json: options[:body], params: options[:params])
|
25
|
+
if response.status.eql?(200)
|
26
|
+
response.parse.with_indifferent_access
|
27
|
+
else
|
28
|
+
error_message = "#{response.status} - #{response.parse['errors'] || response.parse['message']}"
|
29
|
+
raise GatewayError, error_message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'credit_card_validations'
|
2
|
+
|
3
|
+
module PaymentGateway
|
4
|
+
module Mundipagg
|
5
|
+
class Card < Base
|
6
|
+
class MissingCardDataAttributeError < StandardError; end
|
7
|
+
class InvalidCardNumberError < StandardError; end
|
8
|
+
|
9
|
+
attr_accessor :customer_id
|
10
|
+
|
11
|
+
def initialize(customer_id)
|
12
|
+
super()
|
13
|
+
raise "User customer_id cannot be blank" if customer_id.blank?
|
14
|
+
@customer_id = customer_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def list
|
18
|
+
request(:get, mount_url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def show(card_id)
|
22
|
+
request(:get, mount_url("/#{card_id}"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def any?
|
26
|
+
list&.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
### Card data ###
|
30
|
+
#
|
31
|
+
# {
|
32
|
+
# "number": "5425019448107793",
|
33
|
+
# "holder_name": "Tony Stark",
|
34
|
+
# "holder_document": "93095135270",
|
35
|
+
# "exp_month": 1,
|
36
|
+
# "exp_year": 18,
|
37
|
+
# "cvv": "351",
|
38
|
+
# "billing_address": {
|
39
|
+
# street: "Malibu Point",
|
40
|
+
# "number": "10880",
|
41
|
+
# "ZIP code": "90265",
|
42
|
+
# "neighborhood": "Central Malibu",
|
43
|
+
# "city": Malibu,
|
44
|
+
# "state": "HERE",
|
45
|
+
# "country": "US"
|
46
|
+
# }
|
47
|
+
# }
|
48
|
+
def create(card_data)
|
49
|
+
validate_card_data(card_data)
|
50
|
+
request(:post, mount_url, body: card_request_body(card_data))
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy(credit_card_id)
|
54
|
+
if credit_card_id.blank?
|
55
|
+
raise "Credit card id cannot be blank"
|
56
|
+
end
|
57
|
+
response = request(:delete, mount_url("/#{credit_card_id}"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_card_data(card_data)
|
61
|
+
validate_card_data_attributes_presence(card_data)
|
62
|
+
validate_card_number((card_data[:number] || card_data['number']))
|
63
|
+
validate_card_exp_date(card_data)
|
64
|
+
validate_card_cvv((card_data[:cvv] || card_data['cvv']))
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_card_number(card_number)
|
68
|
+
unless CreditCardValidations::Detector.new(card_number).valid?
|
69
|
+
raise InvalidCardNumberError
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate_card_exp_date(card_data)
|
74
|
+
exp_month = card_data[:exp_month] || card_data['exp_month']
|
75
|
+
exp_year = card_data[:exp_year] || card_data['exp_year']
|
76
|
+
unless exp_month.is_a?(Integer) && exp_month.in?(1..12)
|
77
|
+
raise "Invalid card exp_month, use integer from 1 to 12"
|
78
|
+
end
|
79
|
+
unless exp_year.is_a?(Integer) && exp_year.in?(0..50)
|
80
|
+
raise "Invalid card exp_year, user integer from 0 to 50"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_card_cvv(cvv)
|
85
|
+
raise "Invalid cvv" unless /^[0-9]{3,4}$/.match(cvv.to_s)
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def mount_url(relative_path="")
|
91
|
+
"#{API_URL}/customers/#{@customer_id}/cards" + relative_path
|
92
|
+
end
|
93
|
+
|
94
|
+
def card_request_body(card_data)
|
95
|
+
card_data = card_data.with_indifferent_access
|
96
|
+
{
|
97
|
+
number: card_data[:number],
|
98
|
+
holder_name: card_data[:holder_name],
|
99
|
+
holder_document: card_data[:holder_document],
|
100
|
+
exp_month: card_data[:exp_month],
|
101
|
+
exp_year: card_data[:exp_year],
|
102
|
+
cvv: card_data[:cvv],
|
103
|
+
options: { verify_card: true }
|
104
|
+
}.tap { |body|
|
105
|
+
if card_data[:billing_address].present?
|
106
|
+
body[:billing_address] = parsed_billing_address(card_data)
|
107
|
+
end
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def parsed_billing_address(card_data)
|
112
|
+
card_data = card_data.with_indifferent_access
|
113
|
+
billing_address = card_data[:billing_address]
|
114
|
+
{
|
115
|
+
street: billing_address[:street],
|
116
|
+
number: billing_address[:number],
|
117
|
+
zip_code: billing_address[:zip_code],
|
118
|
+
neighborhood: billing_address[:neighborhood],
|
119
|
+
city: billing_address[:city],
|
120
|
+
state: billing_address[:state],
|
121
|
+
country: billing_address[:country]
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
def validate_card_data_attributes_presence(card_data)
|
126
|
+
card_data = card_data.with_indifferent_access
|
127
|
+
[
|
128
|
+
:number,
|
129
|
+
:holder_name,
|
130
|
+
:holder_document,
|
131
|
+
:exp_month,
|
132
|
+
:exp_year,
|
133
|
+
:cvv
|
134
|
+
].each do |key|
|
135
|
+
if card_data[key].blank?
|
136
|
+
raise MissingCardDataAttributeError, "Missing #{key} in card_data object"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module PaymentGateway
|
2
|
+
module Mundipagg
|
3
|
+
class Customer < Base
|
4
|
+
|
5
|
+
def show(customer_id)
|
6
|
+
url = "#{API_URL}/customers/#{customer_id}"
|
7
|
+
request(:get, url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(options)
|
11
|
+
list_url = "#{API_URL}/customers"
|
12
|
+
request(:get, list_url, params: options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
list_url = "#{API_URL}/customers"
|
17
|
+
response = request(:get, list_url)
|
18
|
+
response.parse['data']
|
19
|
+
end
|
20
|
+
|
21
|
+
def any?
|
22
|
+
list&.any?
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(customer_data)
|
26
|
+
creation_url = "#{API_URL}/customers"
|
27
|
+
request(:post, creation_url, body: create_customer_body(customer_data))
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_customer_body(customer_data)
|
33
|
+
customer_data = customer_data.with_indifferent_access
|
34
|
+
{
|
35
|
+
name: customer_data[:name],
|
36
|
+
email: customer_data[:email],
|
37
|
+
type: customer_data[:type] || 'individual',
|
38
|
+
document: customer_data[:document],
|
39
|
+
gender: customer_data[:gender],
|
40
|
+
phones: {
|
41
|
+
home_phone: {
|
42
|
+
country_code: customer_data.dig(:phones, :home_phone, :country_code),
|
43
|
+
area_code: customer_data.dig(:phones, :home_phone, :area_code),
|
44
|
+
number: customer_data.dig(:phones, :home_phone, :number)
|
45
|
+
},
|
46
|
+
mobile_phone: {
|
47
|
+
country_code: customer_data.dig(:phones, :mobile_phone, :country_code),
|
48
|
+
area_code: customer_data.dig(:phones, :mobile_phone, :area_code),
|
49
|
+
number: customer_data.dig(:phones, :mobile_phone, :number)
|
50
|
+
}
|
51
|
+
},
|
52
|
+
address: {
|
53
|
+
street: customer_data.dig(:address, :street),
|
54
|
+
number: customer_data.dig(:address, :number),
|
55
|
+
complement: customer_data.dig(:address, :complement),
|
56
|
+
zip_code: customer_data.dig(:address, :zip_code),
|
57
|
+
neighborhood: customer_data.dig(:address, :neighborhood),
|
58
|
+
city: customer_data.dig(:address, :city),
|
59
|
+
state: customer_data.dig(:address, :state),
|
60
|
+
country: customer_data.dig(:address, :country)
|
61
|
+
},
|
62
|
+
metadata: customer_data[:metadata] || {}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PaymentGateway
|
2
|
+
module Mundipagg
|
3
|
+
|
4
|
+
class Order < Base
|
5
|
+
|
6
|
+
def list
|
7
|
+
request(:get, mount_url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(order_data)
|
11
|
+
request(:post, mount_url, body: order_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def mount_url(relative_path="")
|
17
|
+
"#{API_URL}/orders" + relative_path
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PaymentGateway
|
2
|
+
module Mundipagg
|
3
|
+
|
4
|
+
class Plan < Base
|
5
|
+
|
6
|
+
def list
|
7
|
+
list_url = "#{API_URL}/plans"
|
8
|
+
response = request(:get, list_url)
|
9
|
+
response
|
10
|
+
end
|
11
|
+
|
12
|
+
def any?
|
13
|
+
list&.any?
|
14
|
+
end
|
15
|
+
|
16
|
+
# {
|
17
|
+
# "name" => "Básico",
|
18
|
+
# "currency" => "BRL",
|
19
|
+
# "interval" => "month",
|
20
|
+
# "interval_count" => 1,
|
21
|
+
# "billing_type" => "prepaid",
|
22
|
+
# "items" => [
|
23
|
+
# {
|
24
|
+
# "name" => "Assinatura",
|
25
|
+
# "quantity" => 1,
|
26
|
+
# "pricing_scheme" => {
|
27
|
+
# # R$ 20,00
|
28
|
+
# "price" => 2000
|
29
|
+
# }
|
30
|
+
# }
|
31
|
+
# ],
|
32
|
+
# "metadata" => {
|
33
|
+
# "id" => "plano-basico"
|
34
|
+
# }
|
35
|
+
# }
|
36
|
+
def create(plan_data)
|
37
|
+
validate_plan_data(plan_data)
|
38
|
+
creation_url = "#{API_URL}/plans"
|
39
|
+
request(:post, creation_url, body: plan_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy(plan_id)
|
43
|
+
destruction_url = "#{API_URL}/plans/#{plan_id}"
|
44
|
+
request(:delete, destruction_url)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def validate_plan_data(plan_data)
|
50
|
+
raise "Plan data is missing name" if plan_data[:name].blank?
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PaymentGateway
|
2
|
+
module Mundipagg
|
3
|
+
|
4
|
+
class Subscription < Base
|
5
|
+
|
6
|
+
def list(query_parameters={})
|
7
|
+
request(:get, mount_url, params: query_parameters)
|
8
|
+
end
|
9
|
+
|
10
|
+
def list_customer(customer_id, query_parameters={})
|
11
|
+
raise "Customer id cannot be blank" if customer_id.blank?
|
12
|
+
url = mount_url("?customer_id=#{customer_id}")
|
13
|
+
request(:get, url, params: query_parameters)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(subscription_data)
|
17
|
+
validate_credit_card_data(subscription_data)
|
18
|
+
request(:post, mount_url, body: subscription_data)
|
19
|
+
end
|
20
|
+
|
21
|
+
# plan_id and payment_method are required
|
22
|
+
def create_from_plan(subscription_data)
|
23
|
+
validate_plan_data(subscription_data)
|
24
|
+
validate_credit_card_data(subscription_data)
|
25
|
+
request(:post, mount_url, body: subscription_data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cancel(subscription_id)
|
29
|
+
url = mount_url("/#{subscription_id}")
|
30
|
+
request(:delete, url)
|
31
|
+
end
|
32
|
+
alias_method :destroy, :cancel
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def mount_url(relative_path="")
|
37
|
+
"#{API_URL}/subscriptions" + relative_path
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_plan_data(subscription_data)
|
41
|
+
subscription_data = subscription_data.with_indifferent_access
|
42
|
+
raise "Missing plan_id in subscription data" if subscription_data[:plan_id].blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_credit_card_data(subscription_data)
|
46
|
+
subscription_data = subscription_data.with_indifferent_access
|
47
|
+
if subscription_data[:payment_method].eql?('credit_card') &&
|
48
|
+
(subscription_data[:card].blank? && subscription_data[:card_id].blank?)
|
49
|
+
raise "Missing card data or card_id"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PaymentGateway
|
2
|
+
module Mundipagg
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.reset
|
16
|
+
@configuration = Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
class Configuration
|
20
|
+
attr_accessor :access_key
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@access_key = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
require 'payment_gateway/mundipagg'
|
4
|
+
require 'payment_gateway/mundipagg/base'
|
5
|
+
require 'payment_gateway/mundipagg/plan'
|
6
|
+
require 'payment_gateway/mundipagg/card'
|
7
|
+
require 'payment_gateway/mundipagg/customer'
|
8
|
+
require 'payment_gateway/mundipagg/subscription'
|
9
|
+
require 'payment_gateway/mundipagg/order'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "payment_gateway-mundipagg"
|
3
|
+
s.version = "0.0.3"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.licenses = ["MIT"]
|
6
|
+
s.summary = "Easy integration with Mundipagg payment gateway services"
|
7
|
+
s.email = "felipeghespanhol@gmail.com"
|
8
|
+
s.homepage = "https://github.com/felipehespanhol/payment_gateway-mundipagg"
|
9
|
+
s.description = "Easy integration with Mundipagg payment gateway services"
|
10
|
+
s.authors = ['Felipe G. Hespanhol']
|
11
|
+
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.required_ruby_version = '>= 2.3.4'
|
15
|
+
|
16
|
+
s.add_runtime_dependency("http", "~> 3.0")
|
17
|
+
s.add_runtime_dependency("activesupport", ">=3.0")
|
18
|
+
s.add_runtime_dependency("credit_card_validations", "~>3.4")
|
19
|
+
|
20
|
+
s.add_development_dependency("rspec", "~>3.6")
|
21
|
+
s.add_development_dependency("webmock", "~>3.1")
|
22
|
+
s.add_development_dependency("pry-byebug", "~>3.5")
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe PaymentGateway::Mundipagg::Card do
|
4
|
+
describe '.initialize' do
|
5
|
+
include_examples 'access key needed', PaymentGateway::Mundipagg::Card, 1
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
config_access_key
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#create' do
|
13
|
+
let(:customer_id) { "cus_yoqONwOJI1IBNbjl" }
|
14
|
+
let(:url) { "https://api.mundipagg.com/core/v1/customers/#{customer_id}/cards" }
|
15
|
+
let(:valid_params) { RequestMocks::Mundipagg::Card.create }
|
16
|
+
|
17
|
+
before do
|
18
|
+
stub_mundipagg_request(:card, :create, :post, url, valid_params)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "requests mundipagg api with POST https://api.mundipagg.com/core/v1/customers/cus_yoqONwOJI1IBNbjl/cards " do
|
22
|
+
PaymentGateway::Mundipagg::Card.new(customer_id).create(valid_params)
|
23
|
+
expect(WebMock).to have_requested(:post, url).with(body: valid_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|