offsite_payments 2.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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +70 -0
  4. data/lib/offsite_payments.rb +46 -0
  5. data/lib/offsite_payments/action_view_helper.rb +72 -0
  6. data/lib/offsite_payments/helper.rb +119 -0
  7. data/lib/offsite_payments/integrations.rb +14 -0
  8. data/lib/offsite_payments/integrations/a1agregator.rb +245 -0
  9. data/lib/offsite_payments/integrations/authorize_net_sim.rb +580 -0
  10. data/lib/offsite_payments/integrations/bit_pay.rb +150 -0
  11. data/lib/offsite_payments/integrations/bogus.rb +32 -0
  12. data/lib/offsite_payments/integrations/chronopay.rb +283 -0
  13. data/lib/offsite_payments/integrations/citrus.rb +227 -0
  14. data/lib/offsite_payments/integrations/direc_pay.rb +339 -0
  15. data/lib/offsite_payments/integrations/directebanking.rb +237 -0
  16. data/lib/offsite_payments/integrations/doku.rb +171 -0
  17. data/lib/offsite_payments/integrations/dotpay.rb +166 -0
  18. data/lib/offsite_payments/integrations/dwolla.rb +160 -0
  19. data/lib/offsite_payments/integrations/e_payment_plans.rb +146 -0
  20. data/lib/offsite_payments/integrations/easy_pay.rb +137 -0
  21. data/lib/offsite_payments/integrations/epay.rb +161 -0
  22. data/lib/offsite_payments/integrations/first_data.rb +133 -0
  23. data/lib/offsite_payments/integrations/gestpay.rb +201 -0
  24. data/lib/offsite_payments/integrations/hi_trust.rb +179 -0
  25. data/lib/offsite_payments/integrations/ipay88.rb +240 -0
  26. data/lib/offsite_payments/integrations/klarna.rb +291 -0
  27. data/lib/offsite_payments/integrations/liqpay.rb +216 -0
  28. data/lib/offsite_payments/integrations/maksuturva.rb +231 -0
  29. data/lib/offsite_payments/integrations/mollie_ideal.rb +213 -0
  30. data/lib/offsite_payments/integrations/moneybookers.rb +199 -0
  31. data/lib/offsite_payments/integrations/nochex.rb +228 -0
  32. data/lib/offsite_payments/integrations/pag_seguro.rb +255 -0
  33. data/lib/offsite_payments/integrations/paxum.rb +114 -0
  34. data/lib/offsite_payments/integrations/pay_fast.rb +269 -0
  35. data/lib/offsite_payments/integrations/paydollar.rb +142 -0
  36. data/lib/offsite_payments/integrations/payflow_link.rb +194 -0
  37. data/lib/offsite_payments/integrations/paypal.rb +362 -0
  38. data/lib/offsite_payments/integrations/paypal_payments_advanced.rb +23 -0
  39. data/lib/offsite_payments/integrations/paysbuy.rb +71 -0
  40. data/lib/offsite_payments/integrations/payu_in.rb +266 -0
  41. data/lib/offsite_payments/integrations/payu_in_paisa.rb +46 -0
  42. data/lib/offsite_payments/integrations/platron.rb +153 -0
  43. data/lib/offsite_payments/integrations/pxpay.rb +271 -0
  44. data/lib/offsite_payments/integrations/quickpay.rb +232 -0
  45. data/lib/offsite_payments/integrations/rbkmoney.rb +110 -0
  46. data/lib/offsite_payments/integrations/robokassa.rb +154 -0
  47. data/lib/offsite_payments/integrations/sage_pay_form.rb +425 -0
  48. data/lib/offsite_payments/integrations/two_checkout.rb +332 -0
  49. data/lib/offsite_payments/integrations/universal.rb +180 -0
  50. data/lib/offsite_payments/integrations/valitor.rb +200 -0
  51. data/lib/offsite_payments/integrations/verkkomaksut.rb +143 -0
  52. data/lib/offsite_payments/integrations/web_pay.rb +186 -0
  53. data/lib/offsite_payments/integrations/webmoney.rb +119 -0
  54. data/lib/offsite_payments/integrations/wirecard_checkout_page.rb +359 -0
  55. data/lib/offsite_payments/integrations/world_pay.rb +273 -0
  56. data/lib/offsite_payments/notification.rb +71 -0
  57. data/lib/offsite_payments/return.rb +37 -0
  58. data/lib/offsite_payments/version.rb +3 -0
  59. metadata +270 -0
@@ -0,0 +1,23 @@
1
+ module OffsitePayments
2
+ module Integrations
3
+ module PaypalPaymentsAdvanced
4
+ mattr_accessor :service_url
5
+ self.service_url = 'https://payflowlink.paypal.com'
6
+
7
+ def self.notification(post, options = {})
8
+ PayflowLink::Notification.new(post)
9
+ end
10
+
11
+ def self.return(query_string, options = {})
12
+ Return.new(query_string)
13
+ end
14
+
15
+ class Helper < PayflowLink::Helper
16
+ def initialize(order, account, options)
17
+ super
18
+ add_field('partner', 'PayPal')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ module OffsitePayments #:nodoc:
2
+ module Integrations #:nodoc:
3
+ module Paysbuy
4
+ mattr_accessor :test_url
5
+ self.test_url = 'https://demo.paysbuy.com/paynow.aspx'
6
+
7
+ mattr_accessor :production_url
8
+ self.production_url = 'https://www.paysbuy.com/paynow.aspx'
9
+
10
+ def self.service_url
11
+ mode = OffsitePayments.mode
12
+ case mode
13
+ when :production
14
+ self.production_url
15
+ when :test
16
+ self.test_url
17
+ else
18
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
19
+ end
20
+ end
21
+
22
+ def self.helper(order, account, options = {})
23
+ Helper.new(order, account, options)
24
+ end
25
+
26
+ def self.notification(query_string, options = {})
27
+ Notification.new(query_string, options)
28
+ end
29
+
30
+ class Helper < OffsitePayments::Helper
31
+ mapping :account, 'biz'
32
+ mapping :amount, 'amt'
33
+ mapping :order, 'inv'
34
+ mapping :description, 'itm'
35
+ mapping :notify_url, 'postURL'
36
+ end
37
+
38
+ class Notification < OffsitePayments::Notification
39
+ SUCCESS = '00'
40
+ FAIL = '99'
41
+ PENDING = '02'
42
+
43
+ def complete?
44
+ status == 'Completed'
45
+ end
46
+
47
+ def item_id
48
+ params['result'][2..-1]
49
+ end
50
+
51
+ def status
52
+ status_code = params['result'][0..1]
53
+ case status_code
54
+ when SUCCESS
55
+ 'Completed'
56
+ when FAIL
57
+ 'Failed'
58
+ when PENDING
59
+ 'Pending'
60
+ else
61
+ raise "Unknown status code"
62
+ end
63
+ end
64
+
65
+ def acknowledge(authcode = nil)
66
+ true
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,266 @@
1
+ module OffsitePayments #:nodoc:
2
+ module Integrations #:nodoc:
3
+ module PayuIn
4
+ mattr_accessor :test_url
5
+ mattr_accessor :production_url
6
+
7
+ self.test_url = 'https://test.payu.in/_payment.php'
8
+ self.production_url = 'https://secure.payu.in/_payment.php'
9
+
10
+ def self.service_url
11
+ OffsitePayments.mode == :production ? self.production_url : self.test_url
12
+ end
13
+
14
+ def self.notification(post, options = {})
15
+ Notification.new(post, options)
16
+ end
17
+
18
+ def self.return(post, options = {})
19
+ Return.new(post, options)
20
+ end
21
+
22
+ def self.checksum(merchant_id, secret_key, payload_items )
23
+ Digest::SHA512.hexdigest([merchant_id, *payload_items, secret_key].join("|"))
24
+ end
25
+
26
+ class Helper < OffsitePayments::Helper
27
+
28
+ CHECKSUM_FIELDS = [ 'txnid', 'amount', 'productinfo', 'firstname', 'email', 'udf1', 'udf2', 'udf3', 'udf4',
29
+ 'udf5', 'udf6', 'udf7', 'udf8', 'udf9', 'udf10']
30
+
31
+ mapping :amount, 'amount'
32
+ mapping :account, 'key'
33
+ mapping :order, 'txnid'
34
+ mapping :description, 'productinfo'
35
+
36
+ mapping :customer, :first_name => 'firstname',
37
+ :last_name => 'lastname',
38
+ :email => 'email',
39
+ :phone => 'phone'
40
+
41
+ mapping :billing_address, :city => 'city',
42
+ :address1 => 'address1',
43
+ :address2 => 'address2',
44
+ :state => 'state',
45
+ :zip => 'zip',
46
+ :country => 'country'
47
+
48
+ # Which tab you want to be open default on PayU
49
+ # CC (CreditCard) or NB (NetBanking)
50
+ mapping :mode, 'pg'
51
+
52
+ mapping :notify_url, 'notify_url'
53
+ mapping :return_url, ['surl', 'furl']
54
+ mapping :cancel_return_url, 'curl'
55
+ mapping :checksum, 'hash'
56
+
57
+ mapping :user_defined, { :var1 => 'udf1',
58
+ :var2 => 'udf2',
59
+ :var3 => 'udf3',
60
+ :var4 => 'udf4',
61
+ :var5 => 'udf5',
62
+ :var6 => 'udf6',
63
+ :var7 => 'udf7',
64
+ :var8 => 'udf8',
65
+ :var9 => 'udf9',
66
+ :var10 => 'udf10'
67
+ }
68
+
69
+ def initialize(order, account, options = {})
70
+ super
71
+ @options = options
72
+ self.pg = 'CC'
73
+ end
74
+
75
+ def form_fields
76
+ sanitize_fields
77
+ @fields.merge(mappings[:checksum] => generate_checksum)
78
+ end
79
+
80
+ def generate_checksum
81
+ checksum_payload_items = CHECKSUM_FIELDS.map { |field| @fields[field] }
82
+
83
+ PayuIn.checksum(@fields["key"], @options[:credential2], checksum_payload_items )
84
+ end
85
+
86
+ def sanitize_fields
87
+ ['address1', 'address2', 'city', 'state', 'country', 'productinfo', 'email', 'phone'].each do |field|
88
+ @fields[field].gsub!(/[^a-zA-Z0-9\-_@\/\s.]/, '') if @fields[field]
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ class Notification < OffsitePayments::Notification
95
+ def initialize(post, options = {})
96
+ super(post, options)
97
+ @merchant_id = options[:credential1]
98
+ @secret_key = options[:credential2]
99
+ end
100
+
101
+ def complete?
102
+ status == "Completed"
103
+ end
104
+
105
+ def status
106
+ case transaction_status.downcase
107
+ when 'success' then 'Completed'
108
+ when 'failure' then 'Failed'
109
+ when 'pending' then 'Pending'
110
+ end
111
+ end
112
+
113
+ def invoice_ok?( order_id )
114
+ order_id.to_s == invoice.to_s
115
+ end
116
+
117
+ # Order amount should be equal to gross - discount
118
+ def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ) )
119
+ BigDecimal.new( gross ) == order_amount && BigDecimal.new( discount.to_s ) == order_discount
120
+ end
121
+
122
+ # Status of transaction return from the PayU. List of possible values:
123
+ # <tt>SUCCESS</tt>::
124
+ # <tt>PENDING</tt>::
125
+ # <tt>FAILURE</tt>::
126
+ def transaction_status
127
+ params['status']
128
+ end
129
+
130
+ # ID of this transaction (PayU.in number)
131
+ def transaction_id
132
+ params['mihpayid']
133
+ end
134
+
135
+ # Mode of Payment
136
+ #
137
+ # 'CC' for credit-card
138
+ # 'NB' for net-banking
139
+ # 'CD' for cheque or DD
140
+ # 'CO' for Cash Pickup
141
+ def type
142
+ params['mode']
143
+ end
144
+
145
+ # What currency have we been dealing with
146
+ def currency
147
+ 'INR'
148
+ end
149
+
150
+ def item_id
151
+ params['txnid']
152
+ end
153
+
154
+ # This is the invoice which you passed to PayU.in
155
+ def invoice
156
+ params['txnid']
157
+ end
158
+
159
+ # Merchant Id provided by the PayU.in
160
+ def account
161
+ params['key']
162
+ end
163
+
164
+ # original amount send by merchant
165
+ def gross
166
+ params['amount']
167
+ end
168
+
169
+ # This is discount given to user - based on promotion set by merchants.
170
+ def discount
171
+ params['discount']
172
+ end
173
+
174
+ # Description offer for what PayU given the offer to user - based on promotion set by merchants.
175
+ def offer_description
176
+ params['offer']
177
+ end
178
+
179
+ # Information about the product as send by merchant
180
+ def product_info
181
+ params['productinfo']
182
+ end
183
+
184
+ # Email of the customer
185
+ def customer_email
186
+ params['email']
187
+ end
188
+
189
+ # Phone of the customer
190
+ def customer_phone
191
+ params['phone']
192
+ end
193
+
194
+ # Firstname of the customer
195
+ def customer_first_name
196
+ params['firstname']
197
+ end
198
+
199
+ # Lastname of the customer
200
+ def customer_last_name
201
+ params['lastname']
202
+ end
203
+
204
+ # Full address of the customer
205
+ def customer_address
206
+ { :address1 => params['address1'], :address2 => params['address2'],
207
+ :city => params['city'], :state => params['state'],
208
+ :country => params['country'], :zipcode => params['zipcode'] }
209
+ end
210
+
211
+ def user_defined
212
+ @user_defined ||= 10.times.map { |i| params["udf#{i + 1}"] }
213
+ end
214
+
215
+ def checksum
216
+ params['hash']
217
+ end
218
+
219
+ def message
220
+ @message || params['error']
221
+ end
222
+
223
+ def acknowledge(authcode = nil)
224
+ checksum_ok?
225
+ end
226
+
227
+ def checksum_ok?
228
+ checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, gross, invoice]
229
+
230
+ unless Digest::SHA512.hexdigest([@secret_key, *checksum_fields, @merchant_id].join("|")) == checksum
231
+ @message = 'Return checksum not matching the data provided'
232
+ return false
233
+ end
234
+ true
235
+ end
236
+ end
237
+
238
+ class Return < OffsitePayments::Return
239
+ def initialize(query_string, options = {})
240
+ super
241
+ @notification = Notification.new(query_string, options)
242
+ end
243
+
244
+ def transaction_id
245
+ @notification.transaction_id
246
+ end
247
+
248
+ def status( order_id, order_amount )
249
+ if @notification.invoice_ok?( order_id ) && @notification.amount_ok?( BigDecimal.new(order_amount) )
250
+ @notification.status
251
+ else
252
+ 'Mismatch'
253
+ end
254
+ end
255
+
256
+ def success?
257
+ status( @params['txnid'], @params['amount'] ) == 'Completed'
258
+ end
259
+
260
+ def message
261
+ @notification.message
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,46 @@
1
+ module OffsitePayments
2
+ module Integrations
3
+ module PayuInPaisa
4
+ mattr_accessor :test_url
5
+ mattr_accessor :production_url
6
+
7
+ self.test_url = 'https://test.payu.in/_payment.php'
8
+ self.production_url = 'https://secure.payu.in/_payment.php'
9
+
10
+ def self.service_url
11
+ OffsitePayments.mode == :production ? self.production_url : self.test_url
12
+ end
13
+
14
+ def self.notification(post, options = {})
15
+ Notification.new(post, options)
16
+ end
17
+
18
+ def self.return(post, options = {})
19
+ Return.new(post, options)
20
+ end
21
+
22
+ class Helper < PayuIn::Helper
23
+ mapping :service_provider, 'service_provider'
24
+
25
+ def initialize(order, account, options = {})
26
+ super
27
+ self.service_provider = 'payu_paisa'
28
+ self.user_defined = { :var2 => order }
29
+ end
30
+ end
31
+
32
+ class Notification < PayuIn::Notification
33
+ def item_id
34
+ params['udf2']
35
+ end
36
+ end
37
+
38
+ class Return < PayuIn::Return
39
+ def initialize(query_string, options = {})
40
+ super
41
+ @notification = Notification.new(query_string, options)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,153 @@
1
+ require 'builder'
2
+
3
+ module OffsitePayments #:nodoc:
4
+ module Integrations #:nodoc:
5
+ # Platron API: www.platron.ru/PlatronAPI.pdf‎
6
+ module Platron
7
+ mattr_accessor :service_url
8
+ self.service_url = 'https://www.platron.ru/payment.php'
9
+
10
+ def self.notification(raw_post)
11
+ Notification.new(raw_post)
12
+ end
13
+
14
+ def self.generate_signature_string(params, path, secret)
15
+ sorted_params = params.sort_by{|k,v| k.to_s}.collect{|k,v| v}
16
+ [path, sorted_params, secret].flatten.compact.join(';')
17
+ end
18
+
19
+ def self.generate_signature(params, path, secret)
20
+ Digest::MD5.hexdigest(generate_signature_string(params, path, secret))
21
+ end
22
+
23
+ class Helper < OffsitePayments::Helper
24
+ def initialize(order, account, options = {})
25
+ @secret_key = options.delete(:secret)
26
+ @path = options.delete(:path)
27
+ description = options.delete(:description)
28
+ super
29
+ self.add_field('pg_salt', rand(36**15).to_s(36))
30
+ self.add_field('pg_description', description)
31
+ end
32
+
33
+ def form_fields
34
+ @fields.merge('pg_sig' => Common.generate_signature(@fields, @path, @secret_key))
35
+ end
36
+
37
+ def params
38
+ @fields
39
+ end
40
+
41
+ mapping :account, 'pg_merchant_id'
42
+ mapping :amount, 'pg_amount'
43
+ mapping :order, 'pg_order_id'
44
+ mapping :description, 'pg_description'
45
+ mapping :currency, 'pg_currency'
46
+ end
47
+
48
+ class Notification < OffsitePayments::Notification
49
+ def initialize(*args)
50
+ super
51
+ @signature = params.delete('pg_sig')
52
+ end
53
+
54
+ def complete?
55
+ params['pg_result']
56
+ end
57
+
58
+ def order_id
59
+ params['pg_order_id']
60
+ end
61
+
62
+ def platron_payment_id
63
+ params['pg_payment_id']
64
+ end
65
+
66
+ def currency
67
+ params['pg_ps_currency']
68
+ end
69
+
70
+ def payment_system
71
+ params['pg_payment_system']
72
+ end
73
+
74
+ def user_phone
75
+ params['pg_user_phone']
76
+ end
77
+
78
+ def card_brand
79
+ params['pg_card_brand']
80
+ end
81
+
82
+ def captured
83
+ params['pg_captured']
84
+ end
85
+
86
+ def overpayment
87
+ params['pg_overpayment']
88
+ end
89
+
90
+ def failure_code
91
+ params['pg_failure_code']
92
+ end
93
+
94
+ def failure_description
95
+ params['pg_failure_description']
96
+ end
97
+
98
+ def payment_date
99
+ params['pg_payment_date']
100
+ end
101
+
102
+ def salt
103
+ params['pg_salt']
104
+ end
105
+
106
+ def signature
107
+ @signature
108
+ end
109
+
110
+ def net_amount
111
+ params['pg_net_amount']
112
+ end
113
+
114
+ def ps_amount
115
+ params['pg_ps_amount']
116
+ end
117
+
118
+ def ps_full_amount
119
+ params['pg_ps_full_amount']
120
+ end
121
+
122
+ def amount
123
+ params['pg_amount']
124
+ end
125
+
126
+ def secret
127
+ @options[:secret]
128
+ end
129
+
130
+ def path
131
+ @options[:path]
132
+ end
133
+
134
+ def acknowledge(authcode = nil)
135
+ signature == Platron.generate_signature(params, path, secret)
136
+ end
137
+
138
+ def success_response(path,secret)
139
+ salt = rand(36**15).to_s(36)
140
+ xml = ""
141
+ doc = Builder::XmlMarkup.new(:target => xml)
142
+ sign = Platron.generate_signature({:pg_status => 'ok', :pg_salt => salt}, path, secret)
143
+ doc.response do
144
+ doc.pg_status 'ok'
145
+ doc.pg_salt salt
146
+ doc.pg_sig sign
147
+ end
148
+ xml
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end