Skip to content
Munir Wanis edited this page Feb 24, 2016 · 1 revision

Create Buyer

require 'stone_ecommerce'

# variable with merchant key
merchantKey = '85328786-8BA6-420F-9948-5352F5A183EB'

# instantiate class with request methods
# :sandbox for sandbox ambient
# :production for production ambient
gateway = Gateway::Gateway.new(:sandbox, merchantKey)

# Creates the address
address = Gateway::BuyerAddress.new
address.AddressType = 'Residential'
address.City = 'Tatooine'
address.Complement = ''
address.Country = 'Brazil'
address.District = 'Mos Eisley'
address.Number = '123'
address.State = 'RJ'
address.Street = 'Mos Eisley Cantina'
address.ZipCode = '20001000'

# Creates the buyer request
buyer_request = Gateway::CreateBuyerRequest.new
buyer_request.AddressCollection << address
buyer_request.Birthdate = DateTime.new(1990,8,20,0,0,0).strftime("%Y-%m-%dT%H:%M:%S")
buyer_request.BuyerReference = 'C3PO'
buyer_request.DocumentNumber = '12345678901'
buyer_request.DocumentType = 'CPF'
buyer_request.Email = 'lskywalker@r2d2.com'
buyer_request.EmailType = 'Personal'
buyer_request.Gender = 'M'
buyer_request.HomePhone = '(21)123456789'
buyer_request.MobilePhone = '(21)987654321'
buyer_request.Name = 'Luke Skywalker'
buyer_request.PersonType = 'Person'
buyer_request.WorkPhone = '(21)28467902'

response = gateway.CreateBuyer(buyer_request)

puts response

Get Buyer

require 'stone_ecommerce'

# variable with merchant key
merchantKey = '85328786-8BA6-420F-9948-5352F5A183EB'

# instantiate class with request methods
# :sandbox for sandbox ambient
# :production for production ambient
gateway = Gateway::Gateway.new(:sandbox, merchantKey)

# sends the request with buyerkey
response = gateway.GetBuyer('247210dc-e02e-4c2c-9120-652e18aa8de8')

puts response