Class: Opay::Providers::Payu
- Inherits:
-
Object
- Object
- Opay::Providers::Payu
- Defined in:
- lib/opay/providers/payu.rb
Constant Summary collapse
- PAYU_URL =
'https://www.platnosci.pl/paygw/UTF'
Class Method Summary collapse
- .create_form_sig(options) ⇒ Object
- .create_sig(*values) ⇒ Object
- .process(pos_id, session_id, ts, sig) ⇒ Object
- .url(action) ⇒ Object
- .verify_sig(sig, *values) ⇒ Object
Class Method Details
.create_form_sig(options) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/opay/providers/payu.rb', line 75 def self.create_form_sig() sig_string = '' %w( pos_id pay_type session_id pos_auth_key amount desc desc2 trsDesc order_id first_name last_name payback_login street street_hn street_an city post_code country email phone language client_ip ts ).each do |key| sig_string += [key.to_sym].to_s if .has_key?(key.to_sym) end create_sig(sig_string) end |
.create_sig(*values) ⇒ Object
67 68 69 |
# File 'lib/opay/providers/payu.rb', line 67 def self.create_sig(*values) Digest::MD5.hexdigest(values.join + Opay.config.payu_key1) end |
.process(pos_id, session_id, ts, sig) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/opay/providers/payu.rb', line 10 def self.process(pos_id, session_id, ts, sig) return false unless verify_sig(sig, pos_id, session_id, ts) ts = Time.now.to_i.to_s params = { 'pos_id' => pos_id, 'session_id' => session_id, 'ts' => ts, 'sig' => create_sig(pos_id, session_id, ts) } connection = Net::HTTP.new('www.platnosci.pl', 443) connection.use_ssl = true response = connection.start do |http| post = Net::HTTP::Post.new(url(:get_payment_info)) post.set_form_data(params) http.request(post) end info = Hash.from_xml(response.body) return false if info['response']['status'] == 'ERROR' pos_id = info['response']['trans']['pos_id'] session_id = info['response']['trans']['session_id'] order_id = info['response']['trans']['order_id'] status = info['response']['trans']['status'] amount = info['response']['trans']['amount'] desc = info['response']['trans']['desc'] ts = info['response']['trans']['ts'] sig = info['response']['trans']['sig'] return false unless verify_sig(sig, pos_id, session_id, order_id, status, amount, desc, ts) if status.to_i == 99 payment = Opay::Payment.where(session_id: session_id).first! payment.payable.finish return true end return false end |
.url(action) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opay/providers/payu.rb', line 56 def self.url(action) payu_url = Opay.config.process_payments_localy == true ? '/opay/payu/paygw/UTF' : PAYU_URL case action when :new_payment "#{payu_url}/NewPayment" when :get_payment_info "#{payu_url}/Payment/get/xml" end end |
.verify_sig(sig, *values) ⇒ Object
71 72 73 |
# File 'lib/opay/providers/payu.rb', line 71 def self.verify_sig(sig, *values) sig == Digest::MD5.hexdigest(values.join + Opay.config.payu_key2) end |