opay 1.0.0.beta → 1.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.
data/README.md CHANGED
@@ -1,3 +1,32 @@
1
+ [![Build Status](https://travis-ci.org/olownia/opay.png)](https://travis-ci.org/olownia/opay)
2
+
1
3
  # Opay
2
4
 
3
- [![Build Status](https://travis-ci.org/olownia/opay.png)](https://travis-ci.org/olownia/opay)
5
+ Opay is a payu.pl payment provider for Rails apps.
6
+
7
+ ## Installation
8
+
9
+ Add this to your Gemfile:
10
+
11
+ ``` ruby
12
+ gem 'opay'
13
+ ```
14
+
15
+ and run `bundle install`.
16
+
17
+ Next, run:
18
+
19
+ ``` bash
20
+ # add an initializer to config/initializers with all of the configuration options
21
+ $ rails g opay:install
22
+ # This will add the necessary migrations to your app's db/migrate directory
23
+ rake opay:install:migrations
24
+ # This will run any pending migrations
25
+ rake db:migrate
26
+ ```
27
+ then add the following to your routes.rb file:
28
+
29
+ ``` ruby
30
+ # config/routes.rb
31
+ mount Opay::Engine => '/opay'
32
+ ```
@@ -2,5 +2,6 @@ module Opay
2
2
  class Payment < ActiveRecord::Base
3
3
  belongs_to :payable, polymorphic: true
4
4
  attr_accessible :provider, :amount, :finished, :session_id
5
+ validates :payable, :provider, :amount, :session_id, presence: true
5
6
  end
6
7
  end
@@ -6,4 +6,6 @@ Opay.configure do |config|
6
6
  config.pos_auth_key = ''
7
7
  config.key1 = ''
8
8
  config.key1 = ''
9
- end
9
+
10
+ # config.test_mode = true
11
+ end
@@ -13,6 +13,8 @@ module Opay
13
13
  config_accessor :key1
14
14
  config_accessor :key2
15
15
 
16
+ config_accessor :test_mode
17
+
16
18
  reset_config
17
19
  end
18
20
 
@@ -32,6 +34,8 @@ module Opay
32
34
  config.pos_auth_key = 'pos_auth_key'
33
35
  config.key1 = 'key1'
34
36
  config.key2 = 'key2'
37
+
38
+ config.test_mode = false
35
39
  end
36
40
  end
37
41
 
data/lib/opay/engine.rb CHANGED
@@ -16,6 +16,7 @@ module Opay
16
16
  initializer 'opay.initialize' do
17
17
  ActiveSupport.on_load(:action_view) do
18
18
  include Opay::Helpers::FormHelper
19
+ include Opay::Helpers::PayuHelper
19
20
  end
20
21
  end
21
22
 
@@ -9,7 +9,7 @@ module Opay
9
9
  options[:url] = Opay::Providers::Payu.url(:new_payment)
10
10
  options[:html] = { id: "payu_payment_form_#{record.id}", class: 'payu_payment_form' }
11
11
 
12
- record.create_payment!(session_id: record.payment_session_id, provider: 'payu', amount: record.amount)
12
+ record.create_payment!(session_id: record.payment_session_id, provider: 'payu', amount: record.amount) if record.payment.blank?
13
13
 
14
14
  form_for(record, options, &block)
15
15
  end
@@ -25,9 +25,11 @@ module Opay
25
25
 
26
26
  options[:amount] ||= object.amount
27
27
  options[:desc] ||= object.payment_description
28
- options[:client_ip] ||= request.env['HTTP_USER_AGENT']
28
+ options[:client_ip] ||= @template.request.remote_ip
29
29
  options[:js] = 0
30
30
 
31
+ options[:pay_type] = 't' if Opay.config.test_mode
32
+
31
33
 
32
34
  fields = options.map { |key, val| @template.hidden_field_tag(key, val) }.join("\n")
33
35
  js = "<script type=\"text/javascript\"><!-- document.forms['payu_payment_form_#{object.id}'].js.value = 1; --></script>"
data/lib/opay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opay
2
- VERSION = '1.0.0.beta'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -10,6 +10,16 @@
10
10
  <%= @order.amount %>
11
11
  </p>
12
12
 
13
+ <p>
14
+ <b>Paid:</b>
15
+ <%= @order.finished? %>
16
+ </p>
17
+
18
+ <%= opay_form_for(@order) do |f| %>
19
+ <%= f.payment_info first_name: 'Jan', last_name: 'Kowalski', email: 'kowalski@gmail.com', desc: 'Test payment' %>
20
+ <%= f.submit 'pay with payu' %>
21
+ <% end %>
22
+
13
23
 
14
24
  <%= link_to 'Edit', edit_order_path(@order) %> |
15
25
  <%= link_to 'Back', orders_path %>
@@ -6,4 +6,6 @@ Opay.configure do |config|
6
6
  config.pos_auth_key = 'DiEKzTD'
7
7
  config.key1 = 'c0c4b1a6b72b610f9342ea6820ee3a9c'
8
8
  config.key2 = '2af5c662cab479e5471ca76326a57563'
9
+
10
+ config.test_mode = true
9
11
  end
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+ root to: 'orders#index'
2
3
  resources :orders
3
4
  mount Opay::Engine => '/opay'
4
5
  end
Binary file
Binary file