upay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +3 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +6 -0
- data/Guardfile +70 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +11 -0
- data/examples/capture_and_authorize.rb +90 -0
- data/examples/get_a_customer.rb +14 -0
- data/lib/upay/address/address.rb +53 -0
- data/lib/upay/address/billing_address.rb +13 -0
- data/lib/upay/address/shipping_address.rb +13 -0
- data/lib/upay/configure.rb +28 -0
- data/lib/upay/credit_card.rb +131 -0
- data/lib/upay/customer.rb +161 -0
- data/lib/upay/order.rb +56 -0
- data/lib/upay/payment.rb +15 -0
- data/lib/upay/people/buyer.rb +33 -0
- data/lib/upay/people/payer.rb +30 -0
- data/lib/upay/people/person.rb +37 -0
- data/lib/upay/plan.rb +145 -0
- data/lib/upay/report.rb +22 -0
- data/lib/upay/requestor.rb +90 -0
- data/lib/upay/signature.rb +26 -0
- data/lib/upay/subscription.rb +94 -0
- data/lib/upay/token.rb +98 -0
- data/lib/upay/transaction.rb +137 -0
- data/lib/upay/version.rb +3 -0
- data/lib/upay.rb +86 -0
- data/spec/factories/address.rb +36 -0
- data/spec/factories/credit_card.rb +22 -0
- data/spec/factories/customer.rb +12 -0
- data/spec/factories/order.rb +13 -0
- data/spec/factories/people.rb +29 -0
- data/spec/factories/plan.rb +26 -0
- data/spec/factories/token.rb +18 -0
- data/spec/factories/transaction.rb +16 -0
- data/spec/lib/upay/address/address_spec.rb +34 -0
- data/spec/lib/upay/address/billing_address_spec.rb +34 -0
- data/spec/lib/upay/address/shipping_address_spec.rb +34 -0
- data/spec/lib/upay/credit_card_spec.rb +39 -0
- data/spec/lib/upay/customer_spec.rb +18 -0
- data/spec/lib/upay/order_spec.rb +29 -0
- data/spec/lib/upay/people/buyer_spec.rb +19 -0
- data/spec/lib/upay/people/payer_spec.rb +19 -0
- data/spec/lib/upay/people/person_spec.rb +19 -0
- data/spec/lib/upay/plan_spec.rb +54 -0
- data/spec/lib/upay/token_spec.rb +33 -0
- data/spec/lib/upay/transaction_spec.rb +39 -0
- data/spec/lib/upay_spec.rb +5 -0
- data/spec/spec_helper.rb +123 -0
- data/spec/support/factory_girl.rb +5 -0
- data/upay.gemspec +47 -0
- metadata +361 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
module Upay
|
2
|
+
class Customer
|
3
|
+
|
4
|
+
def initialize(args = {})
|
5
|
+
reload(args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def reload(args = {})
|
9
|
+
args.each do |k,v|
|
10
|
+
instance_variable_set("@#{k}", v)
|
11
|
+
if k == "creditCards"
|
12
|
+
ccs = []
|
13
|
+
v.each do |c|
|
14
|
+
puts c
|
15
|
+
ccs << CreditCard.new(c)
|
16
|
+
end
|
17
|
+
instance_variable_set("@#{k}", ccs)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def fullName; @fullName end
|
23
|
+
def fullName=(fullName)
|
24
|
+
@fullName = fullName
|
25
|
+
end
|
26
|
+
|
27
|
+
def email; @email end
|
28
|
+
def email=(email)
|
29
|
+
@email = email
|
30
|
+
end
|
31
|
+
|
32
|
+
def id; @id end
|
33
|
+
def id=(id)
|
34
|
+
@id = id
|
35
|
+
end
|
36
|
+
|
37
|
+
def customerId; @customerId end
|
38
|
+
def customerId=(customerId)
|
39
|
+
@customerId = customerId
|
40
|
+
end
|
41
|
+
|
42
|
+
def subscription; @subscription end
|
43
|
+
def subscription=(subscription)
|
44
|
+
@subscription = subscription
|
45
|
+
end
|
46
|
+
|
47
|
+
def creditCards; @creditCards end
|
48
|
+
def creditCards=(creditCards = {}) @creditCards = creditCards end
|
49
|
+
|
50
|
+
def valid?
|
51
|
+
validator = CustomerValidator.new
|
52
|
+
validator.valid?(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
#Verb: POST
|
56
|
+
#Description:
|
57
|
+
#Returns: JSON
|
58
|
+
def create
|
59
|
+
url = "rest/v4.3/customers"
|
60
|
+
hash_for_create = self.to_hash
|
61
|
+
response = Requestor.new.post(url, {:fullName => self.fullName, :email => self.email})
|
62
|
+
self.customerId = response["id"]
|
63
|
+
self.id = response["id"]
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
#Verb: UPDATE
|
68
|
+
#Description:
|
69
|
+
#Returns: JSON
|
70
|
+
def update
|
71
|
+
url = "rest/v4.3/customers/#{self.customerId}"
|
72
|
+
Requestor.new.put(url, {:fullName => self.fullName, :email => self.email})
|
73
|
+
end
|
74
|
+
|
75
|
+
#Verb: GET
|
76
|
+
#Description:
|
77
|
+
#Returns: JSON
|
78
|
+
def show
|
79
|
+
begin
|
80
|
+
unless self.customerId.nil?
|
81
|
+
url = "rest/v4.3/customers/#{self.customerId}"
|
82
|
+
response = Requestor.new.get(url, {})
|
83
|
+
self.reload(response)
|
84
|
+
else
|
85
|
+
raise "customerId cannot be blank"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
#Verb: GET
|
92
|
+
#Description:
|
93
|
+
#Returns: JSON
|
94
|
+
def all
|
95
|
+
url = "rest/v4.3/customers/"
|
96
|
+
customers = []
|
97
|
+
list_of_customers = Requestor.new.get(url, {})
|
98
|
+
if list_of_customers["customerList"] && list_of_customers["customerList"].count > 0
|
99
|
+
customers = list_of_customers["customerList"].map{|x| Customer.new(x) }
|
100
|
+
end
|
101
|
+
customers
|
102
|
+
end
|
103
|
+
|
104
|
+
#Verb: DELETE
|
105
|
+
#Description:
|
106
|
+
#Returns: JSON
|
107
|
+
def delete
|
108
|
+
url = "rest/v4.3/customers/#{self.customerId}"
|
109
|
+
Requestor.new.delete(url, {})
|
110
|
+
end
|
111
|
+
|
112
|
+
#Subscriptions Thingys
|
113
|
+
|
114
|
+
def subscription
|
115
|
+
response = self.show
|
116
|
+
if response["subscriptions"]
|
117
|
+
self.subscription = Subscription.new({:id => response["subscriptions"].last["id"]})
|
118
|
+
else
|
119
|
+
{}
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def has_subscription?(planCode)
|
125
|
+
response = self.show
|
126
|
+
it_has = false
|
127
|
+
unless response["subscriptions"].blank?
|
128
|
+
response["subscriptions"].each do |subscription|
|
129
|
+
if subscription["plan"]["planCode"] == planCode
|
130
|
+
it_has = true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
it_has
|
135
|
+
end
|
136
|
+
|
137
|
+
def has_subscriptions?
|
138
|
+
response = self.show
|
139
|
+
unless response["subscriptions"].blank?
|
140
|
+
response["subscriptions"].count > 0
|
141
|
+
else
|
142
|
+
false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def to_hash
|
147
|
+
{
|
148
|
+
:customerId => self.customerId || nil,
|
149
|
+
:fullName => self.fullName,
|
150
|
+
:email => self.email
|
151
|
+
}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
class CustomerValidator
|
156
|
+
include Veto.validator
|
157
|
+
|
158
|
+
validates :fullName, :presence => true
|
159
|
+
validates :email, :presence => true
|
160
|
+
end
|
161
|
+
end
|
data/lib/upay/order.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Upay
|
2
|
+
class Order
|
3
|
+
def initialize(args = {})
|
4
|
+
args.each do |k,v|
|
5
|
+
instance_variable_set("@#{k}", v)
|
6
|
+
end
|
7
|
+
instance_variable_set("@accountId", Upay.account_id)
|
8
|
+
instance_variable_set("@language", Upay.lang)
|
9
|
+
instance_variable_set("@notifyUrl", Upay.notifyUrl)
|
10
|
+
end
|
11
|
+
|
12
|
+
def accountId; @accountId end
|
13
|
+
def language; @language end
|
14
|
+
def notifyUrl; @notifyUrl end
|
15
|
+
|
16
|
+
def additionalValues; @additionalValues end
|
17
|
+
def additionalValues=(additionalValues = {}); @additionalValues end
|
18
|
+
|
19
|
+
|
20
|
+
def referenceCode; @referenceCode end
|
21
|
+
def referenceCode=(referenceCode = nil) @referenceCode = referenceCode; end
|
22
|
+
|
23
|
+
def description; @description end
|
24
|
+
def description=(description = nil) @description = description; end
|
25
|
+
|
26
|
+
def signature; @signature end
|
27
|
+
def signature=(signature = nil) @signature = signature; end
|
28
|
+
|
29
|
+
def buyer; @buyer end
|
30
|
+
def buyer=(buyer = {}) @buyer = buyer; end
|
31
|
+
|
32
|
+
def shippingAddress; @shippingAddress end
|
33
|
+
def shippingAddress=(shippingAddress = {}) @shippingAddress = shippingAddress; end
|
34
|
+
|
35
|
+
def valid?
|
36
|
+
validator = OrderValidator.new
|
37
|
+
validator.valid?(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_hash
|
41
|
+
order_hash = self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var)}
|
42
|
+
order_hash[:buyer] = self.buyer.to_hash if self.buyer
|
43
|
+
order_hash[:shippingAddress] = self.shippingAddress.to_hash if self.shippingAddress
|
44
|
+
order_hash
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class OrderValidator
|
49
|
+
include Veto.validator
|
50
|
+
|
51
|
+
validates :referenceCode, presence: true
|
52
|
+
validates :description, presence: true
|
53
|
+
validates :signature, presence: true
|
54
|
+
validates :buyer, presence: true
|
55
|
+
end
|
56
|
+
end
|
data/lib/upay/payment.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Upay
|
2
|
+
class Payment
|
3
|
+
def ping_payments
|
4
|
+
Requestor.new.request(PAYMENTS_API_URL, "PING")
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_payment_methods
|
8
|
+
Requestor.new.request(PAYMENTS_API_URL, "GET_PAYMENT_METHODS")
|
9
|
+
end
|
10
|
+
|
11
|
+
def submit_transaction(payload)
|
12
|
+
Requestor.new.request(PAYMENTS_API_URL, "SUBMIT_TRANSACTION", payload)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Upay
|
2
|
+
module People
|
3
|
+
class Buyer < Person
|
4
|
+
|
5
|
+
def id; @id end
|
6
|
+
def id=(id = nil) @id = id; end
|
7
|
+
|
8
|
+
def merchantBuyerId; @merchantBuyerId || @id end
|
9
|
+
def merchantBuyerId=(merchantBuyerId = nil) @merchantBuyerId = merchantBuyerId; end
|
10
|
+
|
11
|
+
def dniNumber; @dniNumber end
|
12
|
+
def dniNumber=(dniNumber = nil) @dniNumber = dniNumber; end
|
13
|
+
|
14
|
+
def shippingAddress; @shippingAddress end
|
15
|
+
def shippingAddress=(shippingAddress = nil) @shippingAddress = shippingAddress; end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
validator = BuyerValidator.new
|
19
|
+
validator.valid?(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
person_hash = self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var)}
|
24
|
+
person_hash[:shippingAddress] = self.shippingAddress.to_hash if self.shippingAddress
|
25
|
+
person_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class BuyerValidator < PersonValidator
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Upay
|
2
|
+
module People
|
3
|
+
class Payer < Person
|
4
|
+
|
5
|
+
def id; @id end
|
6
|
+
def id=(id = nil) @id = id; end
|
7
|
+
|
8
|
+
def merchantPayerId; @merchantPayerId || @id end
|
9
|
+
def merchantPayerId=(merchantPayerId = nil) @merchantPayerId = merchantPayerId; end
|
10
|
+
|
11
|
+
def billingAddress; @billingAddress end
|
12
|
+
def billingAddress=(billingAddress = nil) @billingAddress = billingAddress; end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
validator = PayerValidator.new
|
16
|
+
validator.valid?(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
person_hash = self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var)}
|
21
|
+
person_hash[:billingAddress] = self.billingAddress.to_hash if self.billingAddress
|
22
|
+
person_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class PayerValidator < PersonValidator
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Upay
|
2
|
+
module People
|
3
|
+
class Person
|
4
|
+
def initialize(args = {})
|
5
|
+
args.each do |k,v|
|
6
|
+
instance_variable_set("@#{k}", v)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def fullName; @fullName end
|
11
|
+
def fullName=(fullName) @fullName = fullName end
|
12
|
+
|
13
|
+
def emailAddress; @emailAddress end
|
14
|
+
def emailAddress=(emailAddress) @emailAddress = emailAddress end
|
15
|
+
|
16
|
+
def contactPhone; @contactPhone end
|
17
|
+
def contactPhone=(contactPhone) @contactPhone = contactPhone; end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
validator = PersonValidator.new
|
21
|
+
validator.valid?(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
25
|
+
person_hash = self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var)}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class PersonValidator
|
30
|
+
include Veto.validator
|
31
|
+
|
32
|
+
validates :fullName, presence: true
|
33
|
+
validates :emailAddress, presence: true
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/upay/plan.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
module Upay
|
2
|
+
class Plan
|
3
|
+
def initialize(args = {})
|
4
|
+
args.each do |k,v|
|
5
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def accountId; @accountId end
|
10
|
+
def accountId=(accountId)
|
11
|
+
@accountId = accountId
|
12
|
+
end
|
13
|
+
|
14
|
+
def planCode; @planCode end
|
15
|
+
def planCode=(planCode)
|
16
|
+
@planCode = planCode
|
17
|
+
end
|
18
|
+
|
19
|
+
def description; @description end
|
20
|
+
def description=(description)
|
21
|
+
@description = description
|
22
|
+
end
|
23
|
+
|
24
|
+
def interval; @interval end
|
25
|
+
def interval=(interval)
|
26
|
+
@interval = interval
|
27
|
+
end
|
28
|
+
|
29
|
+
def value; @value end
|
30
|
+
def value=(value)
|
31
|
+
@value = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def currency; @currency end
|
35
|
+
def currency=(currency)
|
36
|
+
@currency = currency
|
37
|
+
end
|
38
|
+
|
39
|
+
def intervalCount; @intervalCount end
|
40
|
+
def intervalCount=(intervalCount)
|
41
|
+
@intervalCount = intervalCount
|
42
|
+
end
|
43
|
+
|
44
|
+
def maxPaymentsAllowed; @maxPaymentsAllowed end
|
45
|
+
def maxPaymentsAllowed=(maxPaymentsAllowed)
|
46
|
+
@maxPaymentsAllowed = maxPaymentsAllowed
|
47
|
+
end
|
48
|
+
|
49
|
+
def paymentAttempsDelay; @paymentAttempsDelay end
|
50
|
+
def paymentAttempsDelay=(paymentAttempsDelay)
|
51
|
+
@paymentAttempsDelay = paymentAttempsDelay
|
52
|
+
end
|
53
|
+
|
54
|
+
def additionalValues; @additionalValues end
|
55
|
+
def additionalValues=(additionalValues)
|
56
|
+
@additionalValues = additionalValues
|
57
|
+
end
|
58
|
+
|
59
|
+
def trialDays; @trialDays end
|
60
|
+
def trialDays=(trialDays)
|
61
|
+
@trialDays = trialDays
|
62
|
+
end
|
63
|
+
|
64
|
+
def valid?
|
65
|
+
validator = PlanValidator.new
|
66
|
+
validator.valid?(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
#Verb: POST
|
70
|
+
#Description:
|
71
|
+
#Returns: JSON
|
72
|
+
def create
|
73
|
+
url = "rest/v4.3/plans"
|
74
|
+
Requestor.new.post(url, self.to_hash)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
#Verb: UPDATE
|
79
|
+
#Description:
|
80
|
+
#Returns: JSON
|
81
|
+
def update
|
82
|
+
url = "rest/v4.3/plans/#{self.planCode}"
|
83
|
+
Requestor.new.put(url, self.to_hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
#Verb: POST
|
87
|
+
#Description:
|
88
|
+
#Returns: JSON
|
89
|
+
def show
|
90
|
+
url = "rest/v4.3/plans/#{self.planCode}"
|
91
|
+
Requestor.new.get(url, self.to_hash)
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_by_name(name)
|
95
|
+
url = "rest/v4.3/plans/"
|
96
|
+
request = Requestor.new.get(url, {})
|
97
|
+
obtained_plan = {}
|
98
|
+
request["subscriptionPlanList"].each do |plan|
|
99
|
+
obtained_plan = plan if plan["planCode"] == name
|
100
|
+
end
|
101
|
+
obtained_plan
|
102
|
+
end
|
103
|
+
|
104
|
+
#Verb: DELETE
|
105
|
+
#Description:
|
106
|
+
#Returns: JSON
|
107
|
+
def delete
|
108
|
+
url = "rest/v4.3/plans/#{self.planCode}"
|
109
|
+
Requestor.new.delete(url, self.to_hash)
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_hash
|
113
|
+
{
|
114
|
+
:accountId => self.accountId || nil,
|
115
|
+
:planCode => self.planCode,
|
116
|
+
:description => self.description,
|
117
|
+
:interval => self.interval,
|
118
|
+
:intervalCount => self.intervalCount,
|
119
|
+
:maxPaymentsAllowed => self.maxPaymentsAllowed || nil,
|
120
|
+
:paymentAttemptsDelay => "1",
|
121
|
+
:additionalValues => [
|
122
|
+
{
|
123
|
+
:name => "PLAN_VALUE",
|
124
|
+
:value => self.value,
|
125
|
+
:currency => "COP"
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class PlanValidator
|
133
|
+
include Veto.validator
|
134
|
+
|
135
|
+
validates :accountId, presence: true
|
136
|
+
validates :planCode, presence: true
|
137
|
+
validates :description, presence: true
|
138
|
+
validates :interval, presence: true
|
139
|
+
validates :value, presence: true
|
140
|
+
validates :currency, presence: true
|
141
|
+
validates :intervalCount, presence: true
|
142
|
+
validates :additionalValues, presence: true
|
143
|
+
validates :trialDays, presence: true
|
144
|
+
end
|
145
|
+
end
|
data/lib/upay/report.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Upay
|
2
|
+
class Report
|
3
|
+
def ping
|
4
|
+
Requestor.new.request(REPORTS_API_URL, "PING")
|
5
|
+
end
|
6
|
+
|
7
|
+
def order_detail(order_id)
|
8
|
+
payload = { "details" => { "orderId" => order_id } }
|
9
|
+
Requestor.new.request(REPORTS_API_URL, "ORDER_DETAIL", payload)
|
10
|
+
end
|
11
|
+
|
12
|
+
def order_detail_by_reference_code(reference_code)
|
13
|
+
payload = { "details" => { "referenceCode" => reference_code } }
|
14
|
+
Requestor.new.request(REPORTS_API_URL, "ORDER_DETAIL_BY_REFERENCE_CODE", payload)
|
15
|
+
end
|
16
|
+
|
17
|
+
def transaction_response_detail(transaction_id)
|
18
|
+
payload = { "details" => { "transactionId" => transaction_id } }
|
19
|
+
Requestor.new.request(REPORTS_API_URL, "TRANSACTION_RESPONSE_DETAIL", payload)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Upay
|
2
|
+
class Requestor
|
3
|
+
|
4
|
+
def rest
|
5
|
+
api_uri = (Upay.test) ? 'https://stg.api.payulatam.com/payments-api/' : "https://api.payulatam.com/payments-api/"
|
6
|
+
@rest = Faraday.new(:url => api_uri, :ssl => {:verify => false}, headers: { accept: 'application/json', :"Content-Type" => 'application/json; charset=utf-8' }) do |faraday|
|
7
|
+
faraday.response :logger if Upay.logger == true
|
8
|
+
faraday.response :json, :content_type => /\b(json|json-home)$/
|
9
|
+
faraday.adapter Faraday.default_adapter
|
10
|
+
end
|
11
|
+
@rest.basic_auth Upay.api_login, Upay.api_key
|
12
|
+
@rest
|
13
|
+
end
|
14
|
+
|
15
|
+
def request(url, command, data={})
|
16
|
+
api_uri = URI.parse("https://#{'stg.' if Upay.test}api.payulatam.com")
|
17
|
+
|
18
|
+
http = Net::HTTP.new(api_uri.host, api_uri.port)
|
19
|
+
http.use_ssl = true
|
20
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
+
|
22
|
+
data["merchant"] = {
|
23
|
+
"apiKey" => Upay.api_key,
|
24
|
+
"apiLogin" => Upay.api_login
|
25
|
+
}
|
26
|
+
|
27
|
+
data["command"] = command
|
28
|
+
data["test"] = Upay.test || false
|
29
|
+
data["language"] = "es" || Upay.lang
|
30
|
+
|
31
|
+
headers = {
|
32
|
+
"Accept" => "application/json",
|
33
|
+
"Content-Type" => "application/json; charset=utf-8"
|
34
|
+
}
|
35
|
+
|
36
|
+
result = http.send_request("POST", url, data.to_json, headers)
|
37
|
+
|
38
|
+
begin
|
39
|
+
response = JSON.parse(result.body)
|
40
|
+
rescue Exception => e
|
41
|
+
response = result.body
|
42
|
+
end
|
43
|
+
|
44
|
+
return {
|
45
|
+
"status" => result.code,
|
46
|
+
"response" => response
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def get url, data = {}
|
51
|
+
request = self.rest.get do |req|
|
52
|
+
req.url "#{url}"
|
53
|
+
req.headers['Accept'] = 'application/json'
|
54
|
+
req.headers['Content-Type'] = 'application/json; charset=utf-8'
|
55
|
+
req.body = data.to_json
|
56
|
+
end
|
57
|
+
return request.body
|
58
|
+
end
|
59
|
+
|
60
|
+
def post url, data = {}
|
61
|
+
request = self.rest.post do |req|
|
62
|
+
req.url "#{url}"
|
63
|
+
req.headers['Accept'] = 'application/json'
|
64
|
+
req.headers['Content-Type'] = 'application/json; charset=utf-8'
|
65
|
+
req.body = data.to_json
|
66
|
+
end
|
67
|
+
return request.body
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete url, data = {}
|
71
|
+
request = self.rest.delete do |req|
|
72
|
+
req.url "#{url}"
|
73
|
+
req.headers['Accept'] = 'application/json'
|
74
|
+
req.headers['Content-Type'] = 'application/json; charset=utf-8'
|
75
|
+
req.body = data.to_json
|
76
|
+
end
|
77
|
+
return request.body
|
78
|
+
end
|
79
|
+
|
80
|
+
def put url, data = {}
|
81
|
+
request = self.rest.put do |req|
|
82
|
+
req.url "#{url}"
|
83
|
+
req.headers['Accept'] = 'application/json'
|
84
|
+
req.headers['Content-Type'] = 'application/json; charset=utf-8'
|
85
|
+
req.body = data.to_json
|
86
|
+
end
|
87
|
+
return request.body
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Upay
|
2
|
+
class Signature
|
3
|
+
def initialize(args = {})
|
4
|
+
args.each do |k,v|
|
5
|
+
instance_variable_set("@#{k}", v)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def transaction_reference; @transaction_reference end
|
10
|
+
def transaction_reference=(transaction_reference = nil) @transaction_reference = transaction_reference; end
|
11
|
+
|
12
|
+
def transaction_value; @transaction_value end
|
13
|
+
def transaction_value=(transaction_value = nil) @transaction_value = transaction_value; end
|
14
|
+
|
15
|
+
def currency; @currency end
|
16
|
+
def currency=(currency = nil) @currency = currency; end
|
17
|
+
|
18
|
+
def signature
|
19
|
+
@signature ||= "#{Upay.api_key}~#{Upay.merchant_id}~#{self.transaction_reference}~#{self.transaction_value}~#{self.currency}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def signature_digest
|
23
|
+
Digest::MD5.hexdigest(self.signature)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|