gopay 0.1.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.
@@ -0,0 +1,6 @@
1
+ .idea
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ test/test.yml
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use gopay
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gopay.gemspec
4
+ gemspec
@@ -0,0 +1,104 @@
1
+ h1. About GoPay
2
+
3
+ GoPay is a library making it easy to access "GoPay.cz":http://www.gopay.cz paygate from Ruby.
4
+
5
+ h2. Quick Start
6
+
7
+ GoPay is distributed primarily via gem, but it can be also placed to "vendor/plugins" as a Rails plugin.
8
+
9
+ h2. Configuration
10
+
11
+ First, you have to include it in your Gemfile or install manually and require:
12
+
13
+ <pre>
14
+
15
+ # Gemfile
16
+ gem 'gopay'
17
+
18
+ # Manually
19
+ gem install gopay
20
+ require 'gopay'
21
+
22
+ </pre>
23
+
24
+ GoPay can be configured within a config block (placed in config/initializers/gopay.rb for Rails, for instance):
25
+
26
+ <pre>
27
+
28
+ GoPay.configure do |config|
29
+ config.environment = :test
30
+ config.goid = "XXXXX"
31
+ config.secret = "XXXXX"
32
+ config.success_url = "http://example.com/success"
33
+ config.failed_url = "http://example.com/failed"
34
+ end
35
+
36
+ </pre>
37
+
38
+ It can also take a YAML file with configuration:
39
+
40
+ <pre>
41
+
42
+ # YAML file (config.yml):
43
+ goid: XXXXX
44
+ secret: XXXXX
45
+ success_url: http://www.success_url.cz
46
+ failed_url: http://www.failed_url.cz
47
+
48
+
49
+ # Ruby:
50
+ GoPay.configure_from_yaml("config.yml"))
51
+
52
+ </pre>
53
+
54
+ Such YAML config file can be also placed in Rails config dir (named gopay.yml) - it will be autoloaded.
55
+
56
+ h2. Usage
57
+
58
+ <pre>
59
+ # first you have to init a payment
60
+ payment = GoPay::EshopPayment.new(:variable_symbol => "gopay_test_#{GoPay.configuration.goid}",
61
+ :total_price_in_cents => 100,
62
+ :product_name => "productName",
63
+ :payment_channel => "cz_gp_w"
64
+ )
65
+ # and request its creation on paygate:
66
+ payment.create # =>
67
+ # #<GoPay::EshopPayment:0x7fa27c0fab88
68
+ # @last_response=
69
+ # {:"@xmlns:ns1"=>"urn:AxisEPaymentProvider",
70
+ # :total_price=>"100",
71
+ # :variable_symbol=>"gopay_test_8531903182",
72
+ # :result=>"CALL_COMPLETED",
73
+ # :payment_channel=>
74
+ # {:"@xsi:type"=>"soapenc:string",
75
+ # :"@xmlns:soapenc"=>"http://schemas.xmlsoap.org/soap/encoding/"},
76
+ # :eshop_go_id=>"8531903182",
77
+ # :session_state=>"WAITING",
78
+ # :"@xsi:type"=>"ns1:EPaymentStatus",
79
+ # :buyer_go_id=>
80
+ # {:"@xsi:type"=>"soapenc:long",
81
+ # :"@xmlns:soapenc"=>"http://schemas.xmlsoap.org/soap/encoding/"},
82
+ # :product_name=>"productName",
83
+ # :payment_session_id=>"3000523838",
84
+ # :result_description=>"WAITING",
85
+ # :url=>"http://www.failed_url.cz",
86
+ # :encrypted_signature=>
87
+ # "b653c3b55e981abb29ff9a6b25eb1153abb4d5e888b4675594b636456146c189fba2f81e6303dfa3a5b661f6d58385a0"},
88
+ # @payment_channel="cz_gp_w",
89
+ # @payment_session_id="3000523838",
90
+ # @product_name="productName",
91
+ # @total_price_in_cents=100,
92
+
93
+ # After user gets back to success/failed url, you can check status of payment:
94
+ payment = GoPay::EshopPayment.new(:variable_symbol => "XXXXX",
95
+ :total_price_in_cents => price.to_i,
96
+ :product_name => name,
97
+ :payment_session_id => payment_session_id,
98
+ :payment_channels => ["cz_gp_w"])
99
+
100
+ payment.actual_session_state # => "PAYMENT_DONE"
101
+ payment.is_in_state?(GoPay::PAYMENT_DONE) # => true
102
+
103
+ </pre>
104
+
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.pattern = 'test/*_test.rb'
7
+ t.ruby_opts << '-I test'
8
+ t.verbose = true
9
+ end
10
+
11
+
12
+ desc "Uninstall, build and install again"
13
+ task :install_gopay do
14
+ sh "gem uninstall gopay"
15
+ sh "gem build gopay.gemspec"
16
+ sh "gem install gopay"
17
+ end
@@ -0,0 +1,24 @@
1
+ urls:
2
+ test:
3
+ full_integration: https://testgw.gopay.cz/gw/pay-full-v2
4
+ wsdl: https://testgw.gopay.cz/axis/EPaymentServiceV2?wsdl
5
+ base_integration: https://testgw.gopay.cz/gw/pay-base-v2
6
+ get_account_statement_url: https://testgw.gopay.cz/gw/services/get-account-statement
7
+ production:
8
+ full_integration: https://gate.gopay.cz/gw/pay-full-v2
9
+ wsdl: https://gate.gopay.cz/axis/EPaymentServiceV2?wsdl
10
+ base_integration: https://gate.gopay.cz/gw/pay-base-v2
11
+ get_account_statement_url: https://gate.gopay.cz/gw/services/get-account-statement
12
+ messages:
13
+ payment_done: Platba byla úspěšně provedena.<br>Děkujeme Vám za využití našich služeb.
14
+ canceled: Platba byla zrušena.<br>Opakujte platbu znovu, prosím.
15
+ timeouted: Platba byla zrušena.<br>Opakujte platbu znovu, prosím.
16
+ waiting: Platba zatím nebyla provedena. O provedení platby Vás budeme neprodleně informovat pomocí emailu s potvrzením platby. Pokud neobdržíte do následujícího pracovního dne potvrzovací email o platbě, kontaktujte podporu GoPay na emailu podpora@gopay.cz.
17
+ waiting_offline: Platba zatím nebyla provedena. Na platební bráně GoPay jste získali platební údaje a na Váš email Vám byly zaslány informace k provedení platby. O provedení platby Vás budeme budeme neprodleně informovat pomocí emailu s potvrzením platby.
18
+ failed: V průběhu platby nastala chyba. Kontaktujte podporu GoPay na emailu podpora@gopay.cz.
19
+ icons:
20
+ fast_payment: https://www.gopay.cz/download/PT_rychloplatba.png
21
+ gift: https://www.gopay.cz/download/PT_daruj.png
22
+ buynow: https://www.gopay.cz/download/PT_buynow.png
23
+ donate: https://www.gopay.cz/download/PT_donate.png
24
+
@@ -0,0 +1,240 @@
1
+ CZE: Česká Republika
2
+ AFG: Afghánistán
3
+ ALA: Alandské ostrovy
4
+ ALA: Albánie
5
+ ALG: Alžírsko
6
+ AME: Americká Samoa
7
+ US_: Americké Virginské Ostrovy
8
+ AGL: Angola
9
+ ANG: Anguila
10
+ ATA: Antarktida
11
+ ANT: Antigua
12
+ ARG: Argentina
13
+ ARM: Arménie
14
+ ARU: Aruba
15
+ AUS: Austrálie
16
+ BMS: Bahamy
17
+ BAH: Bahrajn
18
+ BAN: Bangladeš
19
+ BAR: Barbados
20
+ MYA: Barma
21
+ BGM: Belgie
22
+ BEL: Belize
23
+ BEN: Benin
24
+ BER: Bermudy
25
+ BTN: Bhútán
26
+ BOL: Bolívie
27
+ BOS: Bosna a hercegovina
28
+ BOT: Botswana
29
+ BRA: Brasilia
30
+ BRI: Britské Virginské Ostrovy
31
+ BRU: Brunej
32
+ BUL: Bulharsko
33
+ BKF: Burkina Faso
34
+ BUR: Burundi
35
+ BLR: Bělorusko
36
+ COT: Břeh slonoviny
37
+ CHL: Chile
38
+ CRO: Chorvatsko
39
+ COO: Cookovy ostrovy
40
+ DOM: Dominika
41
+ DRP: Dominikánská Republika
42
+ DEN: Dánsko
43
+ DJI: Džibutsko
44
+ EGY: Egypt
45
+ ECU: Ekvádor
46
+ ERI: Eritrea
47
+ EST: Estonsko
48
+ ETH: Etiopie
49
+ FAR: Faerské ostrovy
50
+ FLK: Falklandy
51
+ FIJ: Fidži
52
+ PHI: Filipíny
53
+ FIN: Finsko
54
+ FRA: Francie
55
+ FRE: Francouzká Guayana
56
+ PYF: Francouzká Polynezie
57
+ GAB: Gabon
58
+ GAM: Gambie
59
+ GHA: Ghana
60
+ GIB: Gibraltar
61
+ GRE: Grenada
62
+ GEO: Gruzia
63
+ GRL: Grónsko
64
+ GDL: Guadeloupe
65
+ GUM: Guam
66
+ GUA: Guatemala
67
+ GUY: Guayana
68
+ GGY: Guernsey
69
+ GUI: Guinea
70
+ GBS: Guinea-Bissau
71
+ HAI: Haiti
72
+ NED: Holandsko
73
+ HON: Honduras
74
+ HKG: Hongkong
75
+ IND: Indie
76
+ IDS: Indonésie
77
+ IRE: Irsko
78
+ IRA: Irák
79
+ ICE: Island
80
+ ITA: Itálie
81
+ ISR: Izrael
82
+ JAM: Jamajka
83
+ JAP: Japonsko
84
+ YEM: Jemen
85
+ JEY: Jersey
86
+ SOU: Jižní Afrika
87
+ SGS: Jižní Georgie a Jižní Sandwichovy ostrovy
88
+ SKO: Jižní Korea
89
+ ATF: Jižní francouzské teritorie
90
+ JOR: Jordánsko
91
+ CAY: Kajmanské ostrovy
92
+ CAM: Kambodža
93
+ CMR: Kamerun
94
+ CAN: Kanada
95
+ CAP: Kapverdské ostrovy
96
+ QAT: Katar
97
+ KAZ: Kazachstán
98
+ KEN: Keňa
99
+ KIR: Kiribati
100
+ CCK: Kokosové ostrovy
101
+ COL: Kolumbie
102
+ COM: Komorské ostrovy
103
+ CON: Kongo
104
+ COD: Konžská Demokratická Republika
105
+ COS: Kostarika
106
+ CUB: Kuba
107
+ KUW: Kuvajt
108
+ CYP: Kypr
109
+ KYR: Kyrgystán
110
+ LAO: Laos
111
+ LES: Lesotho
112
+ LEB: Libanon
113
+ LBY: Libye
114
+ LIB: Libérie
115
+ LIE: Lichtenštejnsko
116
+ LIT: Litva
117
+ LAT: Lotyšsko
118
+ LUX: Lucenbursko
119
+ MAC: Macao
120
+ MAD: Madagaskar
121
+ MKD: Makedonie = " FYROM
122
+ MLW: Malawi
123
+ MAL: Maledivy
124
+ MLI: Mali
125
+ MLS: Malijsie
126
+ MLT: Malta
127
+ MOR: Maroko
128
+ MHL: Marshallovy ostrovy
129
+ MAR: Martinik
130
+ MRT: Mauretánie
131
+ MAU: Mauricius
132
+ MYT: Mayotte
133
+ HUN: Maďarsko
134
+ UMI: Menší odlehlé ostrovy Spojených států
135
+ MEX: Mexico
136
+ FSM: Mikronésie
137
+ MOL: Moldavsko
138
+ MCO: Monako
139
+ MON: Mongolsko
140
+ MTT: Monserat
141
+ MOZ: Mosambik
142
+ NAM: Namibie
143
+ NEP: Nepál
144
+ NIG: Niger
145
+ NGR: Nigérie
146
+ NIC: Nikaragua
147
+ NIU: Niue
148
+ NET: Nizozemské Antily
149
+ NWY: Norsko
150
+ CDN: Nová Kaledonie
151
+ GER: Německo
152
+ OMA: Omán
153
+ BVT: Ostrov Bouvet
154
+ HMD: Ostrov Heard a McDonaldovy ostrovy
155
+ IMN: Ostrov Man
156
+ NFK: Ostrov Norfolk
157
+ SJM: Ostrov Svalbard a Jan Mayen
158
+ TCI: Ostrovy Turks a Caicos
159
+ PLW: Palauská republika
160
+ PSE: Palestinian territory
161
+ PAN: Panama
162
+ PAP: Papua-Nová Guinea
163
+ PAR: Paraguay
164
+ PER: Peru
165
+ PCN: Pitcairnovy ostrovy
166
+ POL: Polsko
167
+ PUE: Portoriko
168
+ POR: Portugalsko
169
+ PAK: Pákistán
170
+ AUT: Rakousko
171
+ MNE: Republika Černá hora
172
+ REU: Reunion
173
+ EQU: Rovníková Guinea
174
+ ROM: Rumunsko
175
+ RUS: Rusko
176
+ RWA: Rwanda
177
+ EL_: Salvador
178
+ SAN: San Marino
179
+ SAU: Saúdiská Arábie
180
+ SEN: Senegal
181
+ KOR: Severní Korea
182
+ SEY: Seychely
183
+ SIE: Sierra Leone
184
+ SIN: Singapur
185
+ SLO: Slovensko
186
+ SLV: Slovinsko
187
+ SOM: Somálsko
188
+ UAE: Spojené Arabské Emiráty
189
+ UNI: Spojené státy americké
190
+ MNP: Společenství Severních Marian
191
+ YUG: Srbská republika
192
+ SRI: Srí Lanka
193
+ CEN: Středoafrická Republika
194
+ SUR: Surinam
195
+ SHN: Svatá Helena
196
+ SLU: Svatá Lucie
197
+ SKN: Svatý Krištof a Nevis
198
+ SAO: Svatý Tomáš a Princův ostrov
199
+ ST: Svatý Vincenc a Grenadiny
200
+ SWA: Svazijsko
201
+ SUD: Súdán
202
+ SYR: Sýrie
203
+ TAN: Tanzanie
204
+ WLF: Teritorium ostrovů Wallisa a Futuna
205
+ SPM: Teritoriální společenství Saint-Pierre a Miquelon
206
+ TWN: Thaj-wan
207
+ THA: Thajsko
208
+ TLS: Timor-Leste
209
+ TOG: Togo
210
+ TKL: Tokelau
211
+ TON: Tonga
212
+ TRI: Trinidad a Tobago
213
+ TUN: Tunisko
214
+ TUR: Turecko
215
+ TKM: Turkmenistán
216
+ TUV: Tuvalu
217
+ TAJ: Tádžikistán
218
+ UGA: Uganda
219
+ UKR: Ukrajina
220
+ URU: Uruguay
221
+ UZB: Uzbekistán
222
+ VAN: Vanuatu
223
+ VAT: Vatikán – Svatá stolice
224
+ GBR: Velká Británie
225
+ VEN: Venezuela
226
+ VIE: Vietnam
227
+ CXR: Vánoční ostrovy
228
+ ZAM: Zambie
229
+ ZIM: Zimbabwe
230
+ ESH: Západní Sahara
231
+ WES: Západní Samoa
232
+ AZE: Ázerbádžán
233
+ IRN: Írán
234
+ CHA: Čad
235
+ CHN: Čína
236
+ GRC: Řecko
237
+ SOL: Šalomounovy ostrovy
238
+ SPA: Španělsko
239
+ SWE: Švédsko
240
+ SWI: Švýcarsko
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gopay/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gopay"
7
+ s.version = GoPay::VERSION
8
+ s.authors = ["papricek"]
9
+ s.email = ["patrikjira@gmail.com"]
10
+ s.homepage = "http://gopay.defactory.net"
11
+ s.summary = "A little gem making integration of GoPay easy"
12
+ s.description = "GoPay is a library making it easy to access GoPay http://www.gopay.cz paygate from Ruby. It offers some basic wrapper around soap calls in the form of AR-like models. Its autoconfigurable from Rails."
13
+
14
+ s.rubyforge_project = "gopay"
15
+
16
+ s.add_dependency("savon")
17
+ s.add_development_dependency("shoulda")
18
+ s.add_development_dependency("mocha")
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+
22
+ s.test_files = `git ls-files -- test/*`.split("\n")
23
+ s.require_paths = ["lib"]
24
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "gopay"
@@ -0,0 +1,15 @@
1
+ require "pp"
2
+
3
+ require "gopay/config"
4
+ require "gopay/crypt"
5
+
6
+ require "gopay/models/payment"
7
+ require "gopay/models/eshop_payment"
8
+ require "gopay/models/customer_eshop_payment"
9
+ require "gopay/models/buyer_payment"
10
+ require "gopay/models/payment_identity"
11
+ require "gopay/models/payment_method"
12
+
13
+ require "gopay/models/base_payment"
14
+
15
+ require "gopay/railtie" if defined?(::Rails) && ::Rails::VERSION::MAJOR >= 3
@@ -0,0 +1,62 @@
1
+ require "yaml"
2
+
3
+ module GoPay
4
+
5
+ BASE_PATH = File.expand_path("../../../", __FILE__)
6
+ STATUSES = {:created => "CREATED", :payment_method_chosen => "PAYMENT_METHOD_CHOSEN",
7
+ :paid => "PAID", :authorized => "AUTHORIZED",
8
+ :canceled => "CANCELED", :timeouted => "TIMEOUTED",
9
+ :refunded => "REFUNDED", :failed => "FAILED",
10
+ :call_completed => "CALL_COMPLETED", :call_failed => "CALL_FAILED",
11
+ :unknown => "UNKNOWN"}
12
+
13
+ def self.configure
14
+ yield configuration
15
+ end
16
+
17
+ def self.configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def self.configure_from_yaml(path)
22
+ yaml = YAML.load_file(path)
23
+ return unless yaml
24
+ configuration.goid = yaml["goid"]
25
+ configuration.success_url = yaml["success_url"]
26
+ configuration.failed_url = yaml["failed_url"]
27
+ configuration.secure_key = yaml["secure_key"]
28
+ return configuration
29
+ end
30
+
31
+ def self.configure_from_rails
32
+ path = ::Rails.root.join("config", "gopay.yml")
33
+ configure_from_yaml(path) if File.exists?(path)
34
+ env = if defined?(::Rails) && ::Rails.respond_to?(:env)
35
+ ::Rails.env.to_sym
36
+ elsif defined?(::RAILS_ENV)
37
+ ::RAILS_ENV.to_sym
38
+ end
39
+ configuration.environment ||= (env == :development) ? :test : env
40
+ warn "GoPay wasnt properly configured." if GoPay.configuration.goid.blank?
41
+ configuration
42
+ end
43
+
44
+ class Configuration
45
+ attr_accessor :environment, :goid, :success_url, :failed_url, :secure_key
46
+ attr_reader :country_codes, :messages
47
+
48
+ def initialize
49
+ @country_codes = YAML.load_file File.join(BASE_PATH, "config", "country_codes.yml")
50
+ config = YAML.load_file(File.join(BASE_PATH, "config", "config.yml"))
51
+ @urls = config["urls"]
52
+ @messages = config["messages"]
53
+ end
54
+
55
+ def urls
56
+ env = @environment.nil? ? "test" : @environment.to_s
57
+ @urls[env]
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,37 @@
1
+ require "digest/sha1"
2
+ require "openssl"
3
+
4
+ module GoPay
5
+
6
+ module Crypt
7
+ extend self
8
+
9
+ def sha1(string)
10
+ Digest::SHA1.hexdigest(string)
11
+ end
12
+
13
+ def encrypt(string)
14
+ string = sha1(string)
15
+ des = OpenSSL::Cipher::Cipher.new("des-ede3")
16
+ des.encrypt
17
+ des.key = GoPay.configuration.secure_key
18
+ result = des.update(string)
19
+ result.unpack("H*").to_s
20
+ end
21
+
22
+ def decrypt(encrypted_data, padding_off = false)
23
+ encrypted_data = bin2hex(encrypted_data)
24
+ des = OpenSSL::Cipher::Cipher.new("des-ede3")
25
+ des.decrypt
26
+ des.padding = 0 if padding_off
27
+ des.key = GoPay.configuration.secure_key
28
+ result = ""
29
+ result << des.update(encrypted_data)
30
+ end
31
+
32
+ def bin2hex(bin)
33
+ bin.scan(/../).map { | tuple | tuple.hex.chr }.to_s
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,177 @@
1
+ require "savon"
2
+
3
+ Savon.configure { |config| config.log = false }
4
+
5
+ module GoPay
6
+
7
+ class BasePayment
8
+
9
+ def initialize(attributes = {})
10
+ attributes.each do |key, value|
11
+ instance_variable_set(:"@#{key}", value) if self.respond_to?(key)
12
+ end
13
+ @target_goid ||= GoPay.configuration.goid.to_s
14
+ @secure_key ||= GoPay.configuration.secure_key.to_s
15
+ @payment_channels ||= []
16
+ @payment_channels = @payment_channels.join(',')
17
+ end
18
+
19
+ attr_reader :target_goid, :product_name, :total_price_in_cents, :currency,
20
+ :order_number, :payment_channels, :default_payment_channel, :secure_key,
21
+ :first_name, :last_name, :city, :street, :postal_code, :country_code,
22
+ :email, :phone_number, :p1, :p2, :p3, :p4, :lang,
23
+ :session_state
24
+
25
+ attr_accessor :payment_session_id, :response
26
+
27
+ def create
28
+ client = Savon::Client.new GoPay.configuration.urls["wsdl"]
29
+ soap_response = client.request "createPayment" do |soap|
30
+ soap.body = {"paymentCommand" => payment_command_hash}
31
+ end
32
+ self.response = soap_response.to_hash[:create_payment_response][:create_payment_return]
33
+ self.payment_session_id = response[:payment_session_id]
34
+ valid_response?(response, GoPay::STATUSES[:created])
35
+ end
36
+
37
+ def load(validated_status = nil)
38
+ client = Savon::Client.new GoPay.configuration.urls["wsdl"]
39
+ soap_response = client.request "paymentStatus" do |soap|
40
+ soap.body = {"paymentSessionInfo" => payment_session_hash}
41
+ end
42
+ self.response = soap_response.to_hash[:payment_status_response][:payment_status_return]
43
+ valid_payment_session?(response, validated_status)
44
+ end
45
+
46
+ def is_in_status?(status)
47
+ load(status)
48
+ end
49
+
50
+ def payment_command_hash
51
+ {"targetGoId" => target_goid.to_i,
52
+ "productName" => product_name,
53
+ "totalPrice" => total_price_in_cents,
54
+ "currency" => currency,
55
+ "orderNumber" => order_number,
56
+ "successURL" => GoPay.configuration.success_url,
57
+ "failedURL" => GoPay.configuration.failed_url,
58
+ "preAuthorization" => false,
59
+ "defaultPaymentChannel" => default_payment_channel,
60
+ "recurrentPayment" => false,
61
+ "encryptedSignature" => GoPay::Crypt.encrypt(concat_payment_command),
62
+ "customerData" => {
63
+ "firstName" => first_name,
64
+ "lastName" => last_name,
65
+ "city" => city,
66
+ "street" => street,
67
+ "postalCode" => postal_code,
68
+ "countryCode" => country_code,
69
+ "email" => email,
70
+ "phoneNumber" => phone_number},
71
+ "paymentChannels" => payment_channels,
72
+ "lang" => lang}
73
+ end
74
+
75
+ def payment_session_hash
76
+ {"targetGoId" => target_goid.to_i,
77
+ "paymentSessionId" => payment_session_id,
78
+ "encryptedSignature" => GoPay::Crypt.encrypt(concat_payment_session)}
79
+ end
80
+
81
+ def valid_response?(response, status)
82
+ raise "CALL NOT COMPLETED " if response[:result] != GoPay::STATUSES[:call_completed]
83
+ goid_valid = (response[:target_go_id].to_s == target_goid)
84
+
85
+ response_valid = {:session_state => status,
86
+ :product_name => product_name,
87
+ :total_price => total_price_in_cents.to_s
88
+ }.all? { |key, value| response[key].to_s == value.to_s }
89
+
90
+ response_valid && goid_valid
91
+ end
92
+
93
+ def valid_payment_session?(response, status = nil)
94
+ raise "CALL NOT COMPLETED " if response[:result] != GoPay::STATUSES[:call_completed]
95
+ status_valid = if status
96
+ response[:session_state] == status
97
+ else
98
+ GoPay::STATUSES.values.include?(response[:session_state])
99
+ end
100
+ response_valid = {:order_number => order_number,
101
+ :product_name => product_name,
102
+ :target_go_id => target_goid,
103
+ :total_price => total_price_in_cents,
104
+ :currency => currency
105
+ }.all? { |key, value|
106
+ response[key].to_s == value.to_s }
107
+
108
+ signature_valid = GoPay::Crypt.sha1(concat_payment_status(response)) == GoPay::Crypt.decrypt(response[:encrypted_signature])
109
+
110
+ status_valid && response_valid && signature_valid
111
+ end
112
+
113
+ def valid_identity?(params, padding_off = false)
114
+ params['targetGoId'] == target_goid.to_s &&
115
+ params['orderNumber'] == order_number.to_s &&
116
+ GoPay::Crypt.sha1(concat_payment_identity(params)) == GoPay::Crypt.decrypt(params['encryptedSignature'], padding_off)
117
+ end
118
+
119
+ def concat_payment_identity(params)
120
+ [params['targetGoId'],
121
+ params['paymentSessionId'],
122
+ params['parentPaymentSessionId'],
123
+ params['orderNumber'],
124
+ secure_key].map { |attr| attr.to_s.strip }.join("|")
125
+ end
126
+
127
+ def concat_payment_command
128
+ [target_goid,
129
+ product_name.strip,
130
+ total_price_in_cents,
131
+ currency,
132
+ order_number,
133
+ GoPay.configuration.failed_url,
134
+ GoPay.configuration.success_url,
135
+ 0, #preAuthorization
136
+ 0, #recurrentPayment
137
+ nil, #recurrenceDateTo
138
+ nil, #recurrenceCycle
139
+ nil, #recurrencePeriod,
140
+ payment_channels,
141
+ secure_key].map { |attr| attr.to_s }.join("|")
142
+ end
143
+
144
+ def concat_payment_session
145
+ [target_goid,
146
+ payment_session_id,
147
+ secure_key].map { |attr| attr.to_s.strip }.join("|")
148
+ end
149
+
150
+ def concat_payment_status(response)
151
+ [response[:target_go_id],
152
+ response[:product_name],
153
+ response[:total_price],
154
+ response[:currency],
155
+ response[:order_number],
156
+ response[:recurrent_payment] ? 1 : 0,
157
+ response[:parent_payment_session_id],
158
+ response[:pre_authorization] ? 1 : 0,
159
+ response[:result],
160
+ response[:session_state],
161
+ response[:session_sub_state],
162
+ response[:payment_channel],
163
+ secure_key].map { |attr| attr.is_a?(Hash) ? "" : attr.to_s }.join("|")
164
+ end
165
+
166
+ def gopay_url
167
+ return unless payment_session_id
168
+ parameters = {"sessionInfo.targetGoId" => target_goid,
169
+ "sessionInfo.paymentSessionId" => payment_session_id,
170
+ "sessionInfo.encryptedSignature" => GoPay::Crypt.encrypt(self.concat_payment_session)}
171
+ query_string = parameters.map { |key, value| "#{key}=#{value}" }.join("&")
172
+ GoPay.configuration.urls["full_integration"] + "?" + query_string
173
+ end
174
+
175
+ end
176
+
177
+ end
@@ -0,0 +1,25 @@
1
+ require "savon"
2
+
3
+ Savon.configure { |config| config.log = false }
4
+
5
+ module GoPay
6
+ class PaymentMethod
7
+
8
+ attr_reader :code, :offline, :payment_method, :logo
9
+
10
+ def initialize(attributes = {})
11
+ attributes.each do |key, value|
12
+ instance_variable_set(:"@#{key}", value) if self.respond_to?(key)
13
+ end
14
+ end
15
+
16
+ def self.all
17
+ client = Savon::Client.new GoPay.configuration.urls["wsdl"]
18
+ response = client.request("paymentMethodList")
19
+ response.to_hash[:payment_method_list_response][:payment_method_list_return][:payment_method_list_return].map do |item|
20
+ PaymentMethod.new(item)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module GoPay
2
+
3
+ class Railtie < ::Rails::Railtie
4
+ config.after_initialize do GoPay.configure_from_rails end
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module GoPay
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "test_helper"
3
+
4
+ class ConfigTest < Test::Unit::TestCase
5
+
6
+ context "GoPay configured" do
7
+
8
+ should "load both config and country_codes yml files" do
9
+ assert_equal "Česká Republika", GoPay.configuration.country_codes["CZE"]
10
+ assert_equal "https://testgw.gopay.cz/gw/pay-full-v2", GoPay.configuration.urls["full_integration"]
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,31 @@
1
+ require "test_helper"
2
+
3
+ class CryptTest < Test::Unit::TestCase
4
+
5
+ context "GoPay configured" do
6
+
7
+ setup do
8
+ GoPay.configuration.stubs(:goid).returns('1234567890')
9
+ GoPay.configuration.stubs(:secure_key).returns('405ed9cacf63d5b123d65d09')
10
+ @base_payment = GoPay::BasePayment.new(:order_number => 'xxxxyyyy',
11
+ :product_name => "productName",
12
+ :total_price_in_cents => 10000,
13
+ :default_payment_channel => "cz_vb",
14
+ :currency => 'CZK',
15
+ :payment_channels => ["cz_ge", "cz_vb", "cz_sms"],
16
+ :email => 'patrikjira@gmail.com')
17
+ end
18
+
19
+ should "generate sha1 hexdigest for an object" do
20
+ assert_equal "8dc10d197e260b55ac6aea7702246ef87435404e",
21
+ GoPay::Crypt.sha1(@base_payment.concat_payment_command)
22
+ end
23
+
24
+ should "generate encrypted signature for an object" do
25
+ assert_equal "1fa2d2682dead62ba7bdb0f34ba304888f9cbb26df18b5a69d2cdeb73d7511b14791c68cc7eadb61",
26
+ GoPay::Crypt.encrypt(@base_payment.concat_payment_command)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,63 @@
1
+ require "test_helper"
2
+
3
+ class ModelsTest < Test::Unit::TestCase
4
+
5
+ context "GoPay configured" do
6
+
7
+ should "load payment methods" do
8
+ assert GoPay::PaymentMethod.all.first.is_a?(GoPay::PaymentMethod)
9
+ end
10
+
11
+ context "when having test BasePayment" do
12
+ setup do
13
+ @base_payment = GoPay::BasePayment.new(:order_number => 'xxxxyyyy',
14
+ :product_name => "productName",
15
+ :total_price_in_cents => 10000,
16
+ :default_payment_channel => "cz_vb",
17
+ :currency => 'CZK',
18
+ :payment_channels => ["cz_ge", "cz_vb", "cz_sms"],
19
+ :email => 'patrikjira@gmail.com')
20
+ end
21
+
22
+ should "create and verify this payment on paygate" do
23
+ assert @base_payment.create
24
+ assert @base_payment.payment_session_id.to_i > 0
25
+ assert @base_payment.response.is_a?(Hash)
26
+ end
27
+
28
+ should "load payment, verify it and check status" do
29
+ @base_payment.create
30
+ assert @base_payment.load
31
+ assert @base_payment.is_in_status?(GoPay::STATUSES[:created])
32
+ end
33
+
34
+ end
35
+
36
+ context "when having test BasePayment with stubbed credentials" do
37
+ setup do
38
+ GoPay.configuration.stubs(:goid).returns('1234567890')
39
+ GoPay.configuration.stubs(:secure_key).returns('405ed9cacf63d5b123d65d09')
40
+ @base_payment = GoPay::BasePayment.new(:order_number => 'xxxxyyyy',
41
+ :product_name => "productName",
42
+ :total_price_in_cents => 10000,
43
+ :default_payment_channel => "cz_vb",
44
+ :currency => 'CZK',
45
+ :payment_channels => ["cz_ge", "cz_vb", "cz_sms"],
46
+ :email => 'patrikjira@gmail.com')
47
+ end
48
+
49
+
50
+ should "validate base payment identity" do
51
+ params = {'targetGoId' => GoPay.configuration.goid.to_s,
52
+ 'orderNumber' => 'xxxxyyyy',
53
+ 'paymentSessionId' => '123456',
54
+ 'encryptedSignature' => 'e8557aba66dde7923f7ae4594fde08b4812ed5d2a5b9ed6b66a372e8d3c41f0b91da996af1fe7fad'}
55
+
56
+ assert @base_payment.valid_identity?(params, true)
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,7 @@
1
+ goid: XXXXYYYYZZ
2
+ success_url: http://www.example.com/gopay/soap/callback
3
+ failed_url: http://www.example.com/gopay/soap/callback
4
+ callback_url: http://www.example.com/gopay/soap/callback
5
+ action_url: http://www.example.com/gopay/soap/callback
6
+ lang: cs
7
+ secure_key: SECUREKEYSECUREKEY123
@@ -0,0 +1,16 @@
1
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), "../lib")
2
+
3
+ require "rubygems"
4
+ require 'test/unit'
5
+ require "shoulda"
6
+ require 'mocha'
7
+
8
+ require "gopay"
9
+ require "awesome_print"
10
+
11
+ GoPay.configure do |config|
12
+ config.environment = :test
13
+ end
14
+
15
+ # create your own test.yml (see test.example.yml)
16
+ GoPay.configure_from_yaml(File.join(File.dirname(__FILE__), "test.yml"))
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gopay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - papricek
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-23 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: savon
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: mocha
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: GoPay is a library making it easy to access GoPay http://www.gopay.cz paygate from Ruby. It offers some basic wrapper around soap calls in the form of AR-like models. Its autoconfigurable from Rails.
63
+ email:
64
+ - patrikjira@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - .rvmrc
74
+ - Gemfile
75
+ - README.textile
76
+ - Rakefile
77
+ - config/config.yml
78
+ - config/country_codes.yml
79
+ - gopay.gemspec
80
+ - init.rb
81
+ - lib/gopay.rb
82
+ - lib/gopay/config.rb
83
+ - lib/gopay/crypt.rb
84
+ - lib/gopay/models/base_payment.rb
85
+ - lib/gopay/models/payment_method.rb
86
+ - lib/gopay/railtie.rb
87
+ - lib/gopay/version.rb
88
+ - test/config_test.rb
89
+ - test/crypt_test.rb
90
+ - test/models_test.rb
91
+ - test/test.example.yml
92
+ - test/test_helper.rb
93
+ homepage: http://gopay.defactory.net
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project: gopay
122
+ rubygems_version: 1.8.21
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: A little gem making integration of GoPay easy
126
+ test_files:
127
+ - test/config_test.rb
128
+ - test/crypt_test.rb
129
+ - test/models_test.rb
130
+ - test/test.example.yml
131
+ - test/test_helper.rb