class Przelewy24::Client
Attributes
crc[R]
gateway_url[R]
merchant_id[R]
pos_id[R]
Public Class Methods
new(merchant_id, pos_id, crc, mode = :sandbox)
click to toggle source
# File lib/przelewy24/client.rb, line 8 def initialize(merchant_id, pos_id, crc, mode = :sandbox) @merchant_id = merchant_id @pos_id = pos_id @crc = crc if mode == :production @gateway_url = 'secure.przelewy24.pl' elsif mode == :sandbox @gateway_url = 'sandbox.przelewy24.pl' elsif mode == :sandbox2 @gateway_url = 'sandbox2.przelewy24.pl' else raise InvalidGatewayUrl end end
Public Instance Methods
create_transaction(data = {})
click to toggle source
# File lib/przelewy24/client.rb, line 39 def create_transaction(data = {}) Transaction.new(data.reverse_merge(merchant_id: merchant_id, pos_id: pos_id, crc: crc)) end
register_transaction(transaction)
click to toggle source
# File lib/przelewy24/client.rb, line 43 def register_transaction(transaction) connection = Net::HTTP.new(gateway_url, 443) connection.use_ssl = true response = connection.start do |http| post = Net::HTTP::Post.new('/trnRegister') post.set_form_data(transaction.to_data) http.request(post) end HttpResponse.new(response) end
test_connection()
click to toggle source
# File lib/przelewy24/client.rb, line 24 def test_connection signature = Digest::MD5.hexdigest("#{merchant_id}|#{crc}") connection = Net::HTTP.new(gateway_url, 443) connection.use_ssl = true response = connection.start do |http| post = Net::HTTP::Post.new('/testConnection') post.set_form_data(p24_merchant_id: merchant_id, p24_pos_id: merchant_id, p24_sign: signature) http.request(post) end HttpResponse.new(response) end
verify_transaction(data = {})
click to toggle source
# File lib/przelewy24/client.rb, line 56 def verify_transaction(data = {}) connection = Net::HTTP.new(gateway_url, 443) connection.use_ssl = true signature = Digest::MD5.hexdigest([ data['p24_session_id'], data['p24_order_id'], data['p24_amount'], data['p24_currency'], crc ].join('|')) response = connection.start do |http| post = Net::HTTP::Post.new('/trnVerify') post.set_form_data(data.merge('p24_sign' => signature)) http.request(post) end HttpResponse.new(response) end