opay 1.2.0 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 747aa37e7c6ff0a8eeb4390278429281ef59c10e
4
- data.tar.gz: daee2818c97f3f244a910ea6e3c4352d772843ee
3
+ metadata.gz: 1e8f928442b8ec8574bf991b8cb84f432db244dc
4
+ data.tar.gz: d2e823a50f0fb5bfeb025e85585cfd4c3092528b
5
5
  SHA512:
6
- metadata.gz: d293a80d291ed13cce69aaeab38f5b0ac585f8802c01f10504dfa5701e14e739cc2e1559038afed62ec5414fa1891e6de153c862e58e1f080042d85db8f73e3f
7
- data.tar.gz: ea0d95847596742c92461c221e7b8f284f3c1067589545251aa36ac8c0968e52afeac7e52de3348fd4b2ff4feb649372a9cdc6712fe047262d15fefe201bc402
6
+ metadata.gz: bff5fbf5fcbe35af5d6d488a60db457da8ea020b5de434be6baae7254a4e36c5b1c43eea565b96a1a7c175eb6551e51fa58d37b6c46be741e4c8d81d50c2fc91
7
+ data.tar.gz: 4efcc5b64ec2b30ccac4158eef60cf6c72d2e67bf353a30393359ccb6ecca570c8ad9b335021808770779ee9ff38be7a0f964bbbc916981906b94a2c41e4cfd4
data/README.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  # Opay
4
4
 
5
- Opay is a payu.pl payment provider for Rails apps.
5
+ Opay is a payment solution for Rails apps.
6
+
7
+ Currently supported engines:
8
+ * payu
9
+ * paypal express payment
6
10
 
7
11
  ## Installation
8
12
 
@@ -28,6 +32,9 @@ then add the following to your routes.rb file:
28
32
 
29
33
  ``` ruby
30
34
  # config/routes.rb
35
+ get 'success' => 'controller#success', as: :success_payment
36
+ get 'cancel' => 'controller#cancel', as: :cancel_payment
37
+
31
38
  mount Opay::Engine => '/opay'
32
39
  ```
33
40
 
@@ -36,15 +43,29 @@ declare which of your models recive payments
36
43
  ``` ruby
37
44
  class ModelName < ActiveRecord::Base
38
45
  include Opay::Payable
46
+
47
+ after_payment do
48
+ # optional after payment callback
49
+ end
50
+
51
+ def amount
52
+ 100
53
+ def
39
54
  end
40
55
  ```
41
56
 
42
57
  create payment form
43
58
 
44
59
  ``` haml
45
- = opay_form_for(@model_name) do |f|
60
+ = opay_form_for(@model_name, provider: :payu) do |f|
46
61
  = f.payment_info first_name: 'Jan', last_name: 'Kowalski', email: 'kowalski@gmail.com', desc: 'Payment description'
47
62
  = f.submit 'pay with payu'
48
63
  ```
49
64
 
65
+ ``` haml
66
+ = opay_form_for(@model_name, provider: :paypal) do |f|
67
+ = f.payment_info desc: 'Test payment', client_ip: '127.0.0.1'
68
+ = f.submit 'pay with payu'
69
+ ```
70
+
50
71
  set up online url in payu.pl to: `/opay/payu/online`
@@ -4,15 +4,20 @@ module Opay
4
4
  class PaypalController < ApplicationController
5
5
  def new
6
6
  unless Opay.config.process_payments_localy
7
- redirect_to Providers::Paypal.create_payment(params[:session_id], params[:desc], params[:client_ip])
7
+ redirect_to Providers::Paypal.create_payment(
8
+ params[:session_id],
9
+ params[:desc],
10
+ params[:client_ip],
11
+ params[:confirm_url],
12
+ params[:cancel_url],
13
+ )
8
14
  end
9
15
  end
10
16
 
11
- def create
12
- if Providers::Paypal.confirm_payment(params[:token], params[:PayerID], request.remote_ip)
17
+ def confirm
18
+ if Providers::Paypal.process(params[:token], params[:PayerID], request.remote_ip)
13
19
  redirect_to main_app.root_path, notice: I18n.t('opay.payment.success')
14
20
  end
15
- # render text: Providers::Payu.process(params[:pos_id], params[:session_id], params[:ts], params[:sig]) ? 'OK' : ''
16
21
  end
17
22
  end
18
23
  end
data/config/routes.rb CHANGED
@@ -11,8 +11,8 @@ Opay::Engine.routes.draw do
11
11
 
12
12
  # paypal
13
13
  scope 'paypal' do
14
- patch 'new' => 'paypal#new', as: :new_paypal_payment
15
- get 'create' => 'paypal#create', as: :paypals_path
14
+ patch 'new' => 'paypal#new', as: :paypal_new_payment
15
+ get 'confirm' => 'paypal#confirm', as: :paypal_confirm_payment
16
16
  end
17
17
 
18
18
  if Opay.config.process_payments_localy
@@ -4,6 +4,9 @@ Opay.configure do |config|
4
4
  config.test_mode = true
5
5
  # config.process_payments_localy = true if Rails.env.development?
6
6
 
7
+ config.success_url = :success_payment_url
8
+ config.cancel_url = :cancel_payment_url
9
+
7
10
  # payu configuration
8
11
  config.payu_pos_id = ENV['PAYU_POS_ID']
9
12
  config.payu_pos_auth_key = ENV['PAYU_POS_AUTH_KEY']
@@ -21,8 +21,8 @@ module Opay
21
21
  config_accessor :test_mode
22
22
  config_accessor :process_payments_localy
23
23
 
24
- config_accessor :success_path
25
- config_accessor :cancel_path
24
+ config_accessor :success_url
25
+ config_accessor :cancel_url
26
26
 
27
27
  reset_config
28
28
  end
@@ -38,6 +38,9 @@ module Opay
38
38
  configure do |config|
39
39
  config.providers = [:payu, :paypal]
40
40
 
41
+ config.success_url = :success_payment_url
42
+ config.cancel_url = :cancel_payment_url
43
+
41
44
  # payu configuration
42
45
  config.payu_pos_id = ENV['PAYU_POS_ID']
43
46
  config.payu_pos_auth_key = ENV['PAYU_POS_AUTH_KEY']
@@ -5,11 +5,28 @@ module Opay
5
5
 
6
6
  def opay_form_for(record, options = {}, &block)
7
7
  # for future purposes
8
- payu_form_for(record, options, &block)
8
+ @payment_provider = options[:provider]
9
+
10
+ raise ArgumentError, 'Empty payment provider' if @payment_provider.blank? || Opay.config.providers.include?(@payment_provider) == false
11
+
12
+ case @payment_provider
13
+ when :payu
14
+ return payu_form_for(record, options, &block)
15
+ when :paypal
16
+ return paypal_form_for(record, options, &block)
17
+ end
18
+
9
19
  end
10
20
 
11
21
  def payment_info(options = {})
12
- payu_payment_info(options)
22
+ raise ArgumentError, 'Empty payment provider' if @options[:provider].blank? || Opay.config.providers.include?(@options[:provider]) == false
23
+
24
+ case @options[:provider]
25
+ when :payu
26
+ payu_payment_info(options)
27
+ when :paypal
28
+ paypal_payment_info(options)
29
+ end
13
30
  end
14
31
 
15
32
  end
@@ -7,13 +7,15 @@ module Opay
7
7
  record.prepare_payment
8
8
 
9
9
  options[:builder] ||= Opay::FormBuilder
10
- options[:url] = opay.new_paypal_payment_path
10
+ options[:url] = opay.paypal_new_payment_path
11
11
  options[:html] = { id: "paypal_payment_form_#{record.id}", class: 'opay-form opay-paypal-form' }
12
12
 
13
13
  form_for(record, options, &block)
14
14
  end
15
15
 
16
16
  def paypal_payment_info(options = {})
17
+ options[:confirm_url] ||= @template.opay.paypal_confirm_payment_url
18
+ options[:cancel_url] ||= @template.main_app.send(Opay.config.cancel_url)
17
19
  options[:session_id] ||= object.payment_session_id
18
20
  options[:amount] ||= object.amount
19
21
 
@@ -2,20 +2,14 @@ module Opay
2
2
  module Providers
3
3
 
4
4
  class Paypal
5
- PAYU_URL = 'https://www.platnosci.pl/paygw/UTF'
6
-
7
- def self.process(pos_id, session_id, ts, sig)
8
- return false
9
- end
10
-
11
- def self.create_payment(session_id, description, ip)
5
+ def self.create_payment(session_id, description, ip, confirm_url, cancel_url)
12
6
  # for future items list
13
7
  payment = Opay::Payment.where(session_id: session_id).first!
14
8
 
15
9
  response = geteway.setup_purchase(payment.amount.to_i,
16
10
  ip: ip,
17
- return_url: 'http://localhost:3000/opay/paypal/create',
18
- cancel_return_url: 'http://localhost:3000/?cancel',
11
+ return_url: confirm_url,
12
+ cancel_return_url: cancel_url,
19
13
  order_id: session_id,
20
14
  items: [{
21
15
  name: description,
@@ -31,7 +25,7 @@ module Opay
31
25
  end
32
26
  end
33
27
 
34
- def self.confirm_payment(token, payer_id, ip)
28
+ def self.process(token, payer_id, ip)
35
29
  payment = Opay::Payment.where(session_id: token).first!
36
30
 
37
31
  if Opay.config.process_payments_localy
data/lib/opay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opay
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -3,6 +3,9 @@
3
3
  Opay.configure do |config|
4
4
  config.providers = [:payu, :paypal]
5
5
 
6
+ # config.success_url = :success_payment_path
7
+ # config.cancel_url = :cancel_payment_path
8
+
6
9
  # payu configuration
7
10
  config.payu_pos_id = 123456
8
11
  config.payu_pos_auth_key = 'DiEKzTD'
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '208a3c5620024393a948003c0ac3e620bb8c623adc1b6bbe6921584a4c3fd358712c5cea0e56451b71c811dcd3b8fd5bbf5327c062c9b45f5540b897991bd4c2'
7
+ Dummy::Application.config.secret_key_base = '208a3c5620024393a948003c0ac3e620bb8c623adc1b6bbe6921584a4c3fd358712c5cea0e56451b71c811dcd3b8fd5bbf5327c062c9b45f5540b897991bd4c2'
@@ -1,5 +1,9 @@
1
1
  Rails.application.routes.draw do
2
2
  root to: 'orders#index'
3
3
  resources :orders
4
+
5
+ get 'success' => 'payments#success', as: :success_payment
6
+ get 'cancel' => 'payments#cancel', as: :cancel_payment
7
+
4
8
  mount Opay::Engine => '/opay'
5
9
  end
Binary file
Binary file