braspag-api 1.0.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 +7 -0
- data/lib/braspag/api.rb +88 -0
- data/lib/braspag/api/address.rb +53 -0
- data/lib/braspag/api/credit_card.rb +60 -0
- data/lib/braspag/api/customer.rb +58 -0
- data/lib/braspag/api/payment.rb +127 -0
- data/lib/braspag/api/recurrent_payment.rb +46 -0
- data/lib/braspag/api/request/braspag_error.rb +7 -0
- data/lib/braspag/api/request/braspag_request.rb +42 -0
- data/lib/braspag/api/request/create_sale_request.rb +20 -0
- data/lib/braspag/api/request/query_sale_request.rb +20 -0
- data/lib/braspag/api/request/update_sale_request.rb +36 -0
- data/lib/braspag/api/sale.rb +37 -0
- data/lib/braspag/api/version.rb +6 -0
- data/lib/braspag/environment.rb +31 -0
- data/lib/braspag/merchant.rb +17 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b03f3a2de0a1b2d02c51ef95c6d5a5f6e65586c
|
4
|
+
data.tar.gz: 030c537f49715d1570200ff388f49b011a5189a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0df227b756d464774a85bd59051bf3dd36b2440f8647bf8046399ad01ce4074c42eb74891e393d21e3a0d0c5f9326850ee4407522615bde2674de13dae8b15f7
|
7
|
+
data.tar.gz: 8b0528ea93b944467c47ea096d608419e9eb9cd59e90adb5fa75216aa5fa59b8e4aa4fdb43f28c651329fbfedc99ff5aceb5dd4e87e0d6527f6ffb07f80a2ed9
|
data/lib/braspag/api.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require "braspag/environment"
|
2
|
+
require "braspag/merchant"
|
3
|
+
|
4
|
+
require "braspag/api/address"
|
5
|
+
require "braspag/api/credit_card"
|
6
|
+
require "braspag/api/customer"
|
7
|
+
require "braspag/api/payment"
|
8
|
+
require "braspag/api/recurrent_payment"
|
9
|
+
require "braspag/api/sale"
|
10
|
+
|
11
|
+
require "braspag/api/request/create_sale_request"
|
12
|
+
require "braspag/api/request/query_sale_request"
|
13
|
+
require "braspag/api/request/update_sale_request"
|
14
|
+
|
15
|
+
module Braspag
|
16
|
+
# The Braspag API SDK front-end
|
17
|
+
class API
|
18
|
+
attr_accessor :merchant, :environment
|
19
|
+
private :merchant, :environment
|
20
|
+
|
21
|
+
# Create an instance of API by choosing the environment where the
|
22
|
+
# requests will be send
|
23
|
+
#
|
24
|
+
# @param merchant [Merchant] The merchant credentials
|
25
|
+
# @param environment [Environment] The environment
|
26
|
+
def initialize(
|
27
|
+
merchant,
|
28
|
+
environment = nil)
|
29
|
+
|
30
|
+
if (environment == nil)
|
31
|
+
environment = Environment.production()
|
32
|
+
end
|
33
|
+
|
34
|
+
@merchant = merchant
|
35
|
+
@environment = environment
|
36
|
+
end
|
37
|
+
|
38
|
+
# Send the Sale to be created and return the Sale with tid and the status
|
39
|
+
# returned by Braspag.
|
40
|
+
#
|
41
|
+
# @param sale [Sale] The preconfigured Sale
|
42
|
+
# @return [Sale] The Sale with authorization, tid, etc. returned by Braspag.
|
43
|
+
def create_sale(sale)
|
44
|
+
request = Braspag::Request::CreateSaleRequest.new(merchant, environment)
|
45
|
+
|
46
|
+
request.execute(sale)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Query a Sale on Braspag by paymentId
|
50
|
+
#
|
51
|
+
# @param paymentId [String] The paymentId to be queried
|
52
|
+
# @return [Sale] The Sale with authorization, tid, etc. returned by Braspag.
|
53
|
+
def get_sale(payment_id)
|
54
|
+
request = Braspag::Request::QuerySaleRequest.new(merchant, environment)
|
55
|
+
|
56
|
+
request.execute(payment_id)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Cancel a Payment on Braspag by paymentId and speficying the amount
|
60
|
+
#
|
61
|
+
# @param paymentId [String] The paymentId to be queried
|
62
|
+
# @param amount [Integer] Order value in cents
|
63
|
+
# @return [Payment] The cancelled payment
|
64
|
+
def cancel_payment(payment_id, amount=nil)
|
65
|
+
request = Braspag::Request::UpdateSaleRequest.new("void", merchant, environment)
|
66
|
+
|
67
|
+
request.amount = amount
|
68
|
+
|
69
|
+
request.execute(payment_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Capture a Sale on Braspag by paymentId and specifying the amount and the
|
73
|
+
# serviceTaxAmount
|
74
|
+
#
|
75
|
+
# @param paymentId [String] The paymentId to be captured
|
76
|
+
# @param amount [Integer] Amount of the authorization to be captured
|
77
|
+
# @param serviceTaxAmount [Integer] Amount of the authorization should be destined for the service charge
|
78
|
+
# @return [Payment] The captured payment
|
79
|
+
def capture_sale(payment_id, amount=nil, service_tax_amount=nil)
|
80
|
+
request = Braspag::Request::UpdateSaleRequest.new("capture", merchant, environment)
|
81
|
+
|
82
|
+
request.amount = amount
|
83
|
+
request.service_tax_amount = service_tax_amount
|
84
|
+
|
85
|
+
request.execute(payment_id)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Braspag
|
2
|
+
# Customer's address.
|
3
|
+
#
|
4
|
+
# @attr [String] street the customer's address
|
5
|
+
# @attr [String] number the customer's address number
|
6
|
+
# @attr [String] complement any complement of customer's address
|
7
|
+
# @attr [String] zip_code the zip code of customer's address
|
8
|
+
# @attr [String] city the city of customer's address
|
9
|
+
# @attr [String] state the state of customer's address
|
10
|
+
# @attr [String] country the country of customer's address
|
11
|
+
class Address
|
12
|
+
attr_accessor :street,
|
13
|
+
:number,
|
14
|
+
:complement,
|
15
|
+
:zip_code,
|
16
|
+
:city,
|
17
|
+
:state,
|
18
|
+
:country
|
19
|
+
|
20
|
+
def to_json(*options)
|
21
|
+
hash = as_json(*options)
|
22
|
+
hash.reject! {|k,v| v.nil?}
|
23
|
+
hash.to_json(*options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_json(data)
|
27
|
+
if (data != nil)
|
28
|
+
address = Address.new
|
29
|
+
|
30
|
+
address.street = data["Street"] || nil
|
31
|
+
address.number = data["Number"] || nil
|
32
|
+
address.complement = data["Complement"] || nil
|
33
|
+
address.zip_code = data["ZipCode"] || nil
|
34
|
+
address.city = data["City"] || nil
|
35
|
+
address.state = data["State"] || nil
|
36
|
+
address.country = data["Country"] || nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def as_json(options={})
|
42
|
+
{
|
43
|
+
Street: @street,
|
44
|
+
Number: @number,
|
45
|
+
Complement: @complement,
|
46
|
+
ZipCode: @zip_code,
|
47
|
+
City: @city,
|
48
|
+
State: @state,
|
49
|
+
Country: @country
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Braspag
|
2
|
+
# Credit card data
|
3
|
+
#
|
4
|
+
# @attr [String] card_number Credit card number
|
5
|
+
# @attr [String] holder Holder name
|
6
|
+
# @attr [String] expiration_date Credit card expiration date
|
7
|
+
# @attr [String] security_code Credit card security code
|
8
|
+
# @attr [Boolean] save_card Whether or not to save the card
|
9
|
+
# @attr [String] brand Credit card brand
|
10
|
+
# @attr [String] card_token Card token
|
11
|
+
class CreditCard
|
12
|
+
attr_accessor :card_number,
|
13
|
+
:holder,
|
14
|
+
:expiration_date,
|
15
|
+
:security_code,
|
16
|
+
:save_card,
|
17
|
+
:brand,
|
18
|
+
:card_token
|
19
|
+
|
20
|
+
def initialize(args = {})
|
21
|
+
@security_code = args[:security_code]
|
22
|
+
@brand = args[:brand]
|
23
|
+
@token = args[:token]
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(*options)
|
27
|
+
hash = as_json(*options)
|
28
|
+
hash.reject! {|k,v| v.nil?}
|
29
|
+
hash.to_json(*options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.from_json(data)
|
33
|
+
if (data != nil)
|
34
|
+
credit_card = CreditCard.new()
|
35
|
+
credit_card.card_number = data["CardNumber"] || nil
|
36
|
+
credit_card.holder = data["Holder"] || nil
|
37
|
+
credit_card.expiration_date = data["ExpirationDate"] || nil
|
38
|
+
credit_card.security_code = data["SecurityCode"] || nil
|
39
|
+
credit_card.save_card = data["SaveCard"] || nil
|
40
|
+
credit_card.brand = data["Brand"] || nil
|
41
|
+
credit_card.card_token = data["CardToken"] || nil
|
42
|
+
|
43
|
+
return credit_card
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def as_json(options={})
|
49
|
+
{
|
50
|
+
CardNumber: @card_number,
|
51
|
+
Holder: @holder,
|
52
|
+
ExpirationDate: @expiration_date,
|
53
|
+
SecurityCode: @security_code,
|
54
|
+
SaveCard: @save_card,
|
55
|
+
Brand: @brand,
|
56
|
+
CardToken: @card_token
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Braspag
|
2
|
+
# Customer data
|
3
|
+
#
|
4
|
+
# @attr [String] name Customer name
|
5
|
+
# @attr [String] email Customer email
|
6
|
+
# @attr [String] birthDate Customer's birth date
|
7
|
+
# @attr [String] identity Customer id
|
8
|
+
# @attr [String] identityType The type of customer id
|
9
|
+
# @attr [Address] address Customer's address
|
10
|
+
# @attr [Address] deliveryAddress The delivery address
|
11
|
+
class Customer
|
12
|
+
attr_accessor :name,
|
13
|
+
:email,
|
14
|
+
:birth_date,
|
15
|
+
:identity,
|
16
|
+
:identity_type,
|
17
|
+
:address,
|
18
|
+
:delivery_adress
|
19
|
+
|
20
|
+
def initialize(name)
|
21
|
+
@name = name
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*options)
|
25
|
+
hash = as_json(*options)
|
26
|
+
hash.reject! {|k,v| v.nil?}
|
27
|
+
hash.to_json(*options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.from_json(data)
|
31
|
+
if (data != nil)
|
32
|
+
customer = Customer.new(data["Name"] || nil)
|
33
|
+
|
34
|
+
customer.email = data["Email"] || nil
|
35
|
+
customer.birth_date = data["BirthDate"] || nil
|
36
|
+
customer.identity = data["Identity"] || nil
|
37
|
+
customer.identity_type = data["IdentityType"] || nil
|
38
|
+
customer.address = Address.from_json(data["Address"] || nil)
|
39
|
+
customer.delivery_adress = Address.from_json(data["DeliveryAddress"] || nil)
|
40
|
+
|
41
|
+
return customer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def as_json(options={})
|
47
|
+
{
|
48
|
+
Name: @name,
|
49
|
+
Email: @email,
|
50
|
+
BirthDate: @birth_date,
|
51
|
+
Identity: @identity,
|
52
|
+
IdentityType: @identity_type,
|
53
|
+
Address: @address,
|
54
|
+
DeliveryAddress: @delivery_address
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Payment
|
3
|
+
PAYMENTTYPE_CREDITCARD = "CreditCard"
|
4
|
+
PAYMENTTYPE_DEBITCARD = "DebitCard"
|
5
|
+
PAYMENTTYPE_ELECTRONIC_TRANSFER = "ElectronicTransfer"
|
6
|
+
PAYMENTTYPE_BOLETO = "Boleto"
|
7
|
+
|
8
|
+
PROVIDER_BRADESCO = "Bradesco"
|
9
|
+
PROVIDER_BANCO_DO_BRASIL = "BancoDoBrasil"
|
10
|
+
PROVIDER_SIMULADO = "Simulado"
|
11
|
+
|
12
|
+
attr_accessor :service_tax_amount,
|
13
|
+
:installments,
|
14
|
+
:interest,
|
15
|
+
:capture,
|
16
|
+
:authenticate,
|
17
|
+
:recurrent,
|
18
|
+
:recurrent_payment,
|
19
|
+
:credit_card,
|
20
|
+
:proof_of_sale,
|
21
|
+
:authorization_code,
|
22
|
+
:soft_descriptor,
|
23
|
+
:return_url,
|
24
|
+
:provider,
|
25
|
+
:payment_id,
|
26
|
+
:type,
|
27
|
+
:amount,
|
28
|
+
:received_date,
|
29
|
+
:captured_amount,
|
30
|
+
:captured_date,
|
31
|
+
:currency,
|
32
|
+
:country,
|
33
|
+
:reason_code,
|
34
|
+
:reason_message,
|
35
|
+
:provider_return_code,
|
36
|
+
:provider_return_message,
|
37
|
+
:status,
|
38
|
+
:links,
|
39
|
+
:extra_data_collection,
|
40
|
+
:expiration_date,
|
41
|
+
:url,
|
42
|
+
:number,
|
43
|
+
:bar_code_number,
|
44
|
+
:digitable_line,
|
45
|
+
:address
|
46
|
+
|
47
|
+
def initialize(amount, installments: 1)
|
48
|
+
@amount = amount
|
49
|
+
@installments = installments
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_json(*options)
|
53
|
+
hash = as_json(*options)
|
54
|
+
hash.reject! {|k,v| v.nil?}
|
55
|
+
hash.to_json(*options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.from_json(data)
|
59
|
+
if (data != nil)
|
60
|
+
payment = Payment.new(data["Amount"] || nil)
|
61
|
+
|
62
|
+
payment.service_tax_amount = data["ServiceTaxAmount"] || nil
|
63
|
+
payment.installments = data["Installments"] || nil
|
64
|
+
payment.interest = data["Interest"] || nil
|
65
|
+
payment.capture = data["Capture"] || nil
|
66
|
+
payment.authenticate = data["Authenticate"] || nil
|
67
|
+
payment.recurrent = data["Recurrent"] || nil
|
68
|
+
payment.recurrent_payment = Braspag::RecurrentPayment.from_json(data["RecurrentPayment"] || nil)
|
69
|
+
payment.credit_card = Braspag::CreditCard.from_json(data["CreditCard"] || nil)
|
70
|
+
payment.proof_of_sale = data["ProofOfSale"] || nil
|
71
|
+
payment.authorization_code = data["AuthorizationCode"] || nil
|
72
|
+
payment.soft_descriptor = data["SoftDescriptor"] || nil
|
73
|
+
payment.return_url = data["ReturnUrl"] || nil
|
74
|
+
payment.provider = data["Provider"] || nil
|
75
|
+
payment.payment_id = data["PaymentId"] || nil
|
76
|
+
payment.type = data["Type"] || nil
|
77
|
+
payment.received_date = data["ReceivedDate"] || nil
|
78
|
+
payment.captured_amount = data["CapturedAmount"] || nil
|
79
|
+
payment.captured_date = data["CapturedDate"] || nil
|
80
|
+
payment.currency = data["Currency"] || nil
|
81
|
+
payment.country = data["Country"] || nil
|
82
|
+
payment.reason_code = data["ReasonCode"] || nil
|
83
|
+
payment.reason_message = data["ReasonMessage"] || nil
|
84
|
+
payment.provider_return_code = data["ProviderReturnCode"] || nil
|
85
|
+
payment.provider_return_message = data["ProviderReturnMessage"] || nil
|
86
|
+
payment.status = data["Status"] || nil
|
87
|
+
|
88
|
+
payment.links = data["Links"] || nil
|
89
|
+
payment.extra_data_collection = data["ExtraDataCollection"] || nil
|
90
|
+
|
91
|
+
payment.expiration_date = data["ExpirationDate"] || nil
|
92
|
+
payment.url = data["Url"] || nil
|
93
|
+
payment.number = data["Number"] || nil
|
94
|
+
payment.bar_code_number = data["BarCodeNumber"] || nil
|
95
|
+
payment.digitable_line = data["DigitableLine"] || nil
|
96
|
+
payment.address = data["Address"] || nil
|
97
|
+
|
98
|
+
return payment
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
def as_json(options={})
|
104
|
+
{
|
105
|
+
ServiceTaxAmount: @service_tax_amount,
|
106
|
+
Installments: @installments,
|
107
|
+
Interest: @interest,
|
108
|
+
Capture: @capture,
|
109
|
+
Authenticate: @authenticate,
|
110
|
+
Recurrent: @recurrent,
|
111
|
+
RecurrentPayment: @recurrent_payment,
|
112
|
+
CreditCard: @credit_card,
|
113
|
+
SoftDescriptor: @soft_descriptor,
|
114
|
+
ReturnUrl: @return_url,
|
115
|
+
Provider: @provider,
|
116
|
+
Type: @type,
|
117
|
+
Amount: @amount,
|
118
|
+
Currency: @currency,
|
119
|
+
Country: @country,
|
120
|
+
Number: @number,
|
121
|
+
BarCodeNumber: @bar_code_number,
|
122
|
+
DigitableLine: @digitable_line,
|
123
|
+
Address: @address
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Braspag
|
2
|
+
class RecurrentPayment
|
3
|
+
INTERVAL_MONTHLY = "Monthly"
|
4
|
+
INTERVAL_BIMONTHLY = "Bimonthly"
|
5
|
+
INTERVAL_QUARTERLY = "Quarterly"
|
6
|
+
INTERVAL_SEMIANNUAL = "SemiAnnual"
|
7
|
+
INTERVAL_ANNUAL = "Annual"
|
8
|
+
|
9
|
+
attr_accessor :authorize_now,
|
10
|
+
:start_date,
|
11
|
+
:end_date,
|
12
|
+
:interval
|
13
|
+
|
14
|
+
def initialize(authorize_now=true)
|
15
|
+
@authorize_now = authorize_now
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json(*options)
|
19
|
+
hash = as_json(*options)
|
20
|
+
hash.reject! {|k,v| v.nil?}
|
21
|
+
hash.to_json(*options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_json(data)
|
25
|
+
if (data != nil)
|
26
|
+
recurrent_payment = RecurrentPayment.new(data["AuthorizeNow"] || false)
|
27
|
+
|
28
|
+
recurrent_payment.start_date =data["StartDate"] || nil
|
29
|
+
recurrent_payment.end_date =data["EndDate"] || nil
|
30
|
+
recurrent_payment.interval =data["Interval"] || nil
|
31
|
+
|
32
|
+
return recurrent_payment
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def as_json(options={})
|
38
|
+
{
|
39
|
+
AuthorizeNow: @authorize_now,
|
40
|
+
StartDate: @start_date,
|
41
|
+
EndDate: @end_date,
|
42
|
+
Interval: @interval
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "uuidtools"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
require "braspag/api/request/braspag_error"
|
6
|
+
|
7
|
+
module Braspag::Request
|
8
|
+
class BraspagRequest
|
9
|
+
attr_accessor :merchant
|
10
|
+
private :merchant
|
11
|
+
|
12
|
+
def initialize(merchant)
|
13
|
+
@merchant = merchant
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def send_request(method, uri, data=nil)
|
18
|
+
body = nil
|
19
|
+
headers = {"RequestId" => UUIDTools::UUID.random_create.to_s,
|
20
|
+
"MerchantId" => merchant.merchant_id,
|
21
|
+
"MerchantKey" => merchant.merchant_key}
|
22
|
+
|
23
|
+
if (data == nil)
|
24
|
+
headers["Content-Length"] = "0"
|
25
|
+
else
|
26
|
+
headers["Content-Type"] = "application/json"
|
27
|
+
body = data.to_json
|
28
|
+
end
|
29
|
+
|
30
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
client.use_ssl = true
|
32
|
+
|
33
|
+
response = client.send_request(method, uri.path, body, headers)
|
34
|
+
|
35
|
+
data = JSON.parse(response.body)
|
36
|
+
|
37
|
+
raise BraspagError, "Error [" + data[0]["Code"].to_s + "] " + data[0]["Message"] if response.code.to_i >= 400
|
38
|
+
|
39
|
+
return data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "braspag/api/request/braspag_request"
|
2
|
+
|
3
|
+
module Braspag::Request
|
4
|
+
class CreateSaleRequest < BraspagRequest
|
5
|
+
attr_accessor :environment
|
6
|
+
private :environment
|
7
|
+
|
8
|
+
def initialize(merchant, environment)
|
9
|
+
super(merchant)
|
10
|
+
|
11
|
+
@environment = environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(sale)
|
15
|
+
uri = URI.parse(@environment.api + "v2/sales")
|
16
|
+
|
17
|
+
Braspag::Sale.from_json(send_request("POST", uri, sale))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "braspag/api/request/braspag_request"
|
2
|
+
|
3
|
+
module Braspag::Request
|
4
|
+
class QuerySaleRequest < BraspagRequest
|
5
|
+
attr_accessor :environment
|
6
|
+
private :environment
|
7
|
+
|
8
|
+
def initialize(merchant, environment)
|
9
|
+
super(merchant)
|
10
|
+
|
11
|
+
@environment = environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(payment_id)
|
15
|
+
uri = URI.parse(@environment.api_query + "v2/sales/" + payment_id)
|
16
|
+
|
17
|
+
Braspag::Sale.from_json(send_request("GET", uri))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "braspag/api/request/braspag_request"
|
2
|
+
|
3
|
+
module Braspag::Request
|
4
|
+
class UpdateSaleRequest < BraspagRequest
|
5
|
+
attr_accessor :environment,
|
6
|
+
:type,
|
7
|
+
:service_tax_amount,
|
8
|
+
:amount
|
9
|
+
|
10
|
+
private :environment, :type
|
11
|
+
|
12
|
+
def initialize(type, merchant, environment)
|
13
|
+
super(merchant)
|
14
|
+
|
15
|
+
@environment = environment
|
16
|
+
@type = type
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(payment_id)
|
20
|
+
uri = URI.parse(@environment.api + "v2/sales/" + payment_id + "/" + type)
|
21
|
+
params = {}
|
22
|
+
|
23
|
+
if (amount != nil)
|
24
|
+
params["amount"] = amount
|
25
|
+
end
|
26
|
+
|
27
|
+
if (service_tax_amount != nil)
|
28
|
+
params["serviceTaxAmount"] = service_tax_amount
|
29
|
+
end
|
30
|
+
|
31
|
+
uri.query = URI.encode_www_form(params)
|
32
|
+
|
33
|
+
Braspag::Payment.from_json(send_request("PUT", uri))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Sale
|
3
|
+
attr_accessor :merchant_order_id,
|
4
|
+
:customer,
|
5
|
+
:payment
|
6
|
+
|
7
|
+
def initialize(merchant_order_id)
|
8
|
+
@merchant_order_id = merchant_order_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json(*options)
|
12
|
+
hash = as_json(*options)
|
13
|
+
hash.reject! {|k,v| v.nil?}
|
14
|
+
hash.to_json(*options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_json(data)
|
18
|
+
if (data != nil)
|
19
|
+
sale = Sale.new(data["MerchantOrderId"] || nil)
|
20
|
+
|
21
|
+
sale.customer = Customer.from_json(data["Customer"] || nil)
|
22
|
+
sale.payment = Payment.from_json(data["Payment"] || nil)
|
23
|
+
|
24
|
+
return sale
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def as_json(options={})
|
30
|
+
{
|
31
|
+
MerchantOrderId: @merchant_order_id,
|
32
|
+
Customer: @customer,
|
33
|
+
Payment: @payment
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Braspag
|
2
|
+
# API Environment URLs
|
3
|
+
#
|
4
|
+
# @attr [String] api API URL
|
5
|
+
# @attr [String] apiQuery API Query URL
|
6
|
+
class Environment
|
7
|
+
attr_accessor :api,
|
8
|
+
:api_query
|
9
|
+
|
10
|
+
def initialize(api, api_query)
|
11
|
+
@api = api
|
12
|
+
@api_query = api_query
|
13
|
+
end
|
14
|
+
|
15
|
+
# The production environment
|
16
|
+
#
|
17
|
+
# @return [Environment] a configured Environment for production
|
18
|
+
def self.production()
|
19
|
+
return Environment.new("https://api.braspag.com.br/",
|
20
|
+
"https://apiquery.braspag.com.br/")
|
21
|
+
end
|
22
|
+
|
23
|
+
# The sandbox environment
|
24
|
+
#
|
25
|
+
# @return [Environment] a configured Environment for testing
|
26
|
+
def self.sandbox()
|
27
|
+
return Environment.new("https://apisandbox.braspag.com.br/",
|
28
|
+
"https://apiquerysandbox.braspag.com.br/")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Braspag
|
2
|
+
# Merchant identification on Braspag
|
3
|
+
#
|
4
|
+
# @attr [String] merchant_id the merchant identification number
|
5
|
+
# @attr [String] merchant_key the merchant identification key
|
6
|
+
class Merchant
|
7
|
+
attr_accessor :merchant_id,
|
8
|
+
:merchant_key
|
9
|
+
|
10
|
+
# @param merchant_id [String] the merchant identification number
|
11
|
+
# @param merchant_key [String] the merchant identification key
|
12
|
+
def initialize(merchant_id, merchant_key)
|
13
|
+
@merchant_id = merchant_id
|
14
|
+
@merchant_key = merchant_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: braspag-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Braspag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: uuidtools
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
description: Integração com a API da Braspag
|
70
|
+
email:
|
71
|
+
- desenvolvedores@braspag.com.br
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/braspag/api.rb
|
77
|
+
- lib/braspag/api/address.rb
|
78
|
+
- lib/braspag/api/credit_card.rb
|
79
|
+
- lib/braspag/api/customer.rb
|
80
|
+
- lib/braspag/api/payment.rb
|
81
|
+
- lib/braspag/api/recurrent_payment.rb
|
82
|
+
- lib/braspag/api/request/braspag_error.rb
|
83
|
+
- lib/braspag/api/request/braspag_request.rb
|
84
|
+
- lib/braspag/api/request/create_sale_request.rb
|
85
|
+
- lib/braspag/api/request/query_sale_request.rb
|
86
|
+
- lib/braspag/api/request/update_sale_request.rb
|
87
|
+
- lib/braspag/api/sale.rb
|
88
|
+
- lib/braspag/api/version.rb
|
89
|
+
- lib/braspag/environment.rb
|
90
|
+
- lib/braspag/merchant.rb
|
91
|
+
homepage: https://github.com/braspag/BraspagApiiRubySdk
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.0.0
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: SDK API Braspag
|
115
|
+
test_files: []
|