rails-gp-webpay 0.1.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7594fc71523b5d85a28d0a09f2e9c026dfba4e4fe7c43514fdd58f67fa5f149f
4
- data.tar.gz: e0dc36655ec80dacf065b1227b87f477059fdb9d515aa9d7c3ccc707e43b118a
3
+ metadata.gz: 5dc1dfcd0fd2a4f7fcb8cb988aab6d4fe9a97c25c583bae6b1152cc60a96d351
4
+ data.tar.gz: 30b30ee89e2fff8b84f33e60f34c321c647b479b2c7605e2766213a3f334df53
5
5
  SHA512:
6
- metadata.gz: b2ef81c8629b7c685317e3edf73f3f8a45386f4e891004118516ad91f82918b1be742e6c1188c38639cdaed7f673489f453cdd587b5a72eca452edd56a7af6ae
7
- data.tar.gz: edb5588491e3263b9c464c00e20c87cdfb6d03ea0a7c1fe59a2ddaac15b6b95df924acc68ff035063a2584a206cfc303066169fd1f9d1d98a193d2123cfd4014
6
+ metadata.gz: c161135d1e53f089f7d85f9bb564630c61aec1389fd5d2b8a4a3bcbe3fa222780b34f3b674682cb050aa6c605e37e75105aa93690d996b4ea4af284fb8a0f116
7
+ data.tar.gz: d12a30aea8d02467d5e489b2bc819368b3ac9e6bd96265ce233ed377651a885006816b4baa2ecc979a5c5c51374fd7f07249d26ed56e89ffceca13fafcb4d022
@@ -1,5 +1,5 @@
1
1
  class GpWebpayController < GpWebpay.config.parent_controller.constantize
2
- skip_before_action :verify_authenticity_token if defined?(verify_authenticity_token)
2
+ skip_before_action :verify_authenticity_token if defined?(:verify_authenticity_token)
3
3
  prepend_before_action :set_external_order_number
4
4
  prepend_before_action :validate_gpwebpay_response
5
5
  prepend_before_action :set_gpwebpay_response
data/changelog.md CHANGED
@@ -1,4 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2
4
+ Add merchant number to stubs
5
+
6
+ ## 0.2
7
+ Add spec helpers
8
+
3
9
  ## 0.1
4
10
  Init
@@ -15,7 +15,17 @@ module GpWebpay
15
15
  end
16
16
 
17
17
  def [](config_name)
18
- @configurations[config_name]
18
+ return if config_name.blank?
19
+
20
+ @configurations[config_name] || find_configuration_by_merchant_number(config_name)
21
+ end
22
+
23
+ def find_configuration_by_merchant_number(merchant_number)
24
+
25
+ config = @configurations.find { |_key, value| puts _key;value.merchant_number.to_s == merchant_number.to_s }
26
+ return nil if config.blank?
27
+
28
+ config[-1]
19
29
  end
20
30
 
21
31
  def add_configuration(merchant_number:, default: false)
@@ -25,7 +35,7 @@ module GpWebpay
25
35
  end
26
36
 
27
37
  def remove_configuration(merchant_number:)
28
- @configurations[merchant_number] = nil
38
+ @configurations.delete(merchant_number)
29
39
  @configurations[:default] = @configurations[@configurations.keys[0]]
30
40
  end
31
41
 
@@ -9,15 +9,17 @@
9
9
 
10
10
  module GpWebpay
11
11
  module Http
12
- class CreateOrder < BaseSignedRequest
13
- def initialize(attributes, locale, merchant_number: nil, url_attributes: {})
14
- super(attributes, locale, 'CREATE_ORDER', merchant_number: merchant_number, url_attributes: url_attributes)
15
- end
12
+ module Services
13
+ class CreateOrder < BaseSignedRequest
14
+ def initialize(attributes, locale, merchant_number: nil, url_attributes: {})
15
+ super(attributes, locale, 'CREATE_ORDER', merchant_number: merchant_number, url_attributes: url_attributes)
16
+ end
16
17
 
17
- protected
18
+ protected
18
19
 
19
- def callback_url
20
- GpWebpay::Engine.routes.url_helpers.gp_webpay_orders_path({ merchant_number: config.merchant_number, locale: locale }.merge(url_attributes))
20
+ def callback_url
21
+ GpWebpay::Engine.routes.url_helpers.gp_webpay_orders_url({ merchant_number: config.merchant_number, locale: locale }.merge(url_attributes))
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -0,0 +1,20 @@
1
+ ##
2
+ # Service object creates request data for GP Webpay CARD_VERIFICATION operation.
3
+
4
+ module GpWebpay
5
+ module Http
6
+ module Services
7
+ class VerifyCard < BaseSignedRequest
8
+ def initialize(attributes, locale, merchant_number: nil, url_attributes: {})
9
+ super(attributes, locale, 'CARD_VERIFICATION', merchant_number: merchant_number, url_attributes: url_attributes)
10
+ end
11
+
12
+ protected
13
+
14
+ def callback_url
15
+ GpWebpay::Engine.routes.url_helpers.gp_webpay_cards_url({ merchant_number: config.merchant_number, locale: locale }.merge(url_attributes))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,104 @@
1
+ require 'savon/mock/spec_helper'
2
+
3
+ module GpWebpay
4
+ module SpecHelper
5
+ class Interface
6
+ include Savon::SpecHelper
7
+ include RSpec::Mocks::ExampleMethods
8
+
9
+ def params_with_digest(params, merchant_number = :default)
10
+ config = GpWebpay.config[merchant_number] || GpWebpay.config.default
11
+ params.merge(
12
+ 'DIGEST' => GpWebpay::OpensslSecurity.generate_digest(config, params.values.join('|'))
13
+ )
14
+ end
15
+
16
+ def params_with_both_digests(params, merchant_number = :default)
17
+ config = GpWebpay.config[merchant_number] || GpWebpay.config.default
18
+ params.merge(
19
+ 'DIGEST' => GpWebpay::OpensslSecurity.generate_digest(config, params.values.join('|')),
20
+ 'DIGEST1' => GpWebpay::OpensslSecurity.generate_digest(config, "#{params.values.join('|')}|#{config.merchant_number}")
21
+ )
22
+ end
23
+
24
+ def stub_card_token(token, status: 'VERIFIED', success: true, valid: true)
25
+ allow(GpWebpay::Ws::Services::GetTokenStatus)
26
+ .to receive(:call).with(hash_including(token_data: token, message_id: anything))
27
+ .and_return(instance_double(GpWebpay::Ws::WsResponse, valid?: valid, success?: success, status: status))
28
+ end
29
+
30
+ def stub_master_payment_status(payment_number, status: 'OK', success: true, valid: true)
31
+ allow(GpWebpay::Ws::Services::GetMasterPaymentStatus)
32
+ .to receive(:call).with(hash_including(payment_number: payment_number, message_id: anything))
33
+ .and_return(instance_double(GpWebpay::Ws::WsResponse, valid?: valid, success?: success, status: status))
34
+ end
35
+
36
+ def stub_payment_status(payment_number, status: 'VERIFIED', sub_status: 'SETTLED', success: true, valid: true)
37
+ allow(GpWebpay::Ws::Services::GetPaymentStatus)
38
+ .to receive(:call).with(hash_including(payment_number: payment_number, message_id: anything))
39
+ .and_return(instance_double(GpWebpay::Ws::WsResponse,
40
+ valid?: valid, success?: success, status: status,
41
+ params: { sub_status: sub_status }))
42
+ end
43
+
44
+ def stub_usage_based_payment(attributes, merchant_number:, valid: true, success: true, status: '', result_text: 'OK', response_token_data: nil)
45
+ allow(GpWebpay::Ws::Services::ProcessUsageBasedPayment)
46
+ .to receive(:call).with(
47
+ hash_including(
48
+ {
49
+ message_id: anything,
50
+ payment_number: anything,
51
+ order_number: anything,
52
+ currency_code: anything,
53
+ capture_flag: '1'
54
+ }.merge(attributes)
55
+ ),
56
+ merchant_number: merchant_number,
57
+ ).and_return(instance_double(GpWebpay::Ws::WsResponse,
58
+ valid?: valid, success?: success, status: status, result_text: result_text,
59
+ pr_code: success ? '0' : '123', sr_code: success ? '0' : '4',
60
+ params: { token_data: response_token_data || attributes[:token_data] }))
61
+ end
62
+
63
+ def stub_token_revoke(token, valid: true, success: true, status: 'REVOKED', result_text: 'OK')
64
+ allow(GpWebpay::Ws::Services::ProcessTokenRevoke)
65
+ .to receive(:call).with(
66
+ hash_including({ message_id: anything }.merge(token_data: token))
67
+ ).and_return(instance_double(GpWebpay::Ws::WsResponse,
68
+ valid?: valid, success?: success, status: status, result_text: result_text,
69
+ pr_code: success ? '0' : '123', sr_code: success ? '0' : '4'))
70
+ end
71
+
72
+ def stub_refund_payment(attributes, valid: true, success: true, status: '', result_text: 'OK')
73
+ allow(GpWebpay::Ws::Services::ProcessRefundPayment)
74
+ .to receive(:call).with(
75
+ hash_including({ message_id: anything }.merge(attributes))
76
+ ).and_return(instance_double(GpWebpay::Ws::WsResponse,
77
+ valid?: valid, success?: success, status: status, result_text: result_text,
78
+ pr_code: success ? '0' : '123', sr_code: success ? '0' : '4'))
79
+ end
80
+
81
+ def stub_capture_reverse(attributes, valid: true, success: true, status: '', result_text: 'OK')
82
+ allow(GpWebpay::Ws::Services::ProcessCaptureReverse)
83
+ .to receive(:call).with(
84
+ hash_including({ message_id: anything }.merge(attributes))
85
+ ).and_return(instance_double(GpWebpay::Ws::WsResponse,
86
+ valid?: valid, success?: success, status: status, result_text: result_text,
87
+ pr_code: success ? '0' : '123', sr_code: success ? '0' : '4'))
88
+ end
89
+
90
+ def stub_cancel_capture(attributes, valid: true, success: true, status: '', result_text: 'OK')
91
+ allow(GpWebpay::Ws::Services::ProcessCancelCapture)
92
+ .to receive(:call).with(
93
+ hash_including({ message_id: anything }.merge(attributes))
94
+ ).and_return(instance_double(GpWebpay::Ws::WsResponse,
95
+ valid?: valid, success?: success, status: status, result_text: result_text,
96
+ pr_code: success ? '0' : '123', sr_code: success ? '0' : '4'))
97
+ end
98
+ end
99
+
100
+ def gp_webpay
101
+ @gp_webpay ||= Interface.new
102
+ end
103
+ end
104
+ end
@@ -1,3 +1,3 @@
1
1
  module GpWebpay
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # @param [Hash] attributes for GP Webpay
13
13
  #
14
- # @return [GpwebpayWsResponse] response value object
14
+ # @return [GpWebpay::Ws::WsResponse] response value object
15
15
 
16
16
  module GpWebpay
17
17
  module Ws
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # @param [Hash] attributes for GP Webpay
7
7
  #
8
- # @return [GpwebpayWsResponse] response value object
8
+ # @return [GpWebpay::Ws::WsResponse] response value object
9
9
 
10
10
  module GpWebpay
11
11
  module Ws
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @param [Hash] attributes for GP Webpay
5
5
  #
6
- # @return [GpwebpayWsResponse] response value object
6
+ # @return [GpWebpay::Ws::WsResponse] response value object
7
7
 
8
8
  module GpWebpay
9
9
  module Ws
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # @param [Hash] attributes for GP Webpay
7
7
  #
8
- # @return [GpwebpayWsResponse] response value object
8
+ # @return [GpWebpay::Ws::WsResponse] response value object
9
9
 
10
10
  module GpWebpay
11
11
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -16,14 +16,22 @@ module GpWebpay
16
16
  RESPONSE_ENTITY_NAME = :card_on_file_payment_response
17
17
  SERVICE_EXCEPTION = :card_on_file_payment_service_exception
18
18
 
19
+ def initialize(attributes, merchant_number: :default)
20
+ config = GpWebpay.config[merchant_number] || GpWebpay.config.default
21
+ merged_attributes = {
22
+ return_url: GpWebpay::Engine.routes.url_helpers.gp_webpay_orders_url({ merchant_number: config.merchant_number })
23
+ }.merge(attributes)
24
+ super(merged_attributes, merchant_number: merchant_number)
25
+ end
26
+
19
27
  def rescue_from_soap(exception)
20
28
  response = WsResponse.from_fault_error(exception.to_hash, self.class::SERVICE_EXCEPTION, config.merchant_number)
21
29
 
22
30
  if response.valid? && response.params[:authentication_link].present?
23
31
  raise GpWebpayConfirmationRequired.new('GP Webpay requires authentication', response.params[:authentication_link])
24
- else
25
- response
26
32
  end
33
+
34
+ response
27
35
  end
28
36
 
29
37
  class GpWebpayConfirmationRequired < GpWebpay::Error
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -16,9 +16,8 @@ module GpWebpay
16
16
  RESPONSE_ENTITY_NAME = :token_payment_response
17
17
  SERVICE_EXCEPTION = :payment_service_exception
18
18
 
19
- def initialize(attributes)
20
- super
21
- @attributes = attributes.except(:return_url)
19
+ def initialize(attributes, merchant_number: :default)
20
+ super(attributes.except(:return_url), merchant_number: merchant_number)
22
21
  end
23
22
  end
24
23
  end
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # @param [Hash] attributes for GP Webpay
6
6
  #
7
- # @return [GpwebpayWsResponse] response value object
7
+ # @return [GpWebpay::Ws::WsResponse] response value object
8
8
 
9
9
  module GpWebpay
10
10
  module Ws
@@ -15,6 +15,14 @@ module GpWebpay
15
15
  RESPONSE_NAME = :process_usage_based_payment_response
16
16
  RESPONSE_ENTITY_NAME = :usage_based_payment_response
17
17
  SERVICE_EXCEPTION = :payment_service_exception
18
+
19
+ def initialize(attributes, merchant_number: :default)
20
+ config = GpWebpay.config[merchant_number] || GpWebpay.config.default
21
+ merged_attributes = {
22
+ return_url: GpWebpay::Engine.routes.url_helpers.gp_webpay_orders_url({ merchant_number: config.merchant_number })
23
+ }.merge(attributes)
24
+ super(merged_attributes, merchant_number: merchant_number)
25
+ end
18
26
  end
19
27
  end
20
28
  end
@@ -1,8 +1,6 @@
1
1
  module GpWebpay
2
2
  module Ws
3
3
  class WsResponse < Response
4
- attr_accessor :validation_response
5
-
6
4
  def self.from_success(hash, response_name, response_entity_name, merchant_number)
7
5
  validation_response = hash.dig(response_name, response_entity_name)
8
6
  new(
@@ -15,9 +15,9 @@ require 'gp_webpay/http/base_signed_request'
15
15
  require 'gp_webpay/http/external_url'
16
16
  require 'gp_webpay/http/http_response'
17
17
  require 'gp_webpay/http/http_request'
18
- require 'gp_webpay/http/create_order'
19
- require 'gp_webpay/http/verify_card'
20
18
  require 'gp_webpay/http/validate_result'
19
+ require 'gp_webpay/http/services/verify_card'
20
+ require 'gp_webpay/http/services/create_order'
21
21
 
22
22
  require 'gp_webpay/ws/ws_request'
23
23
  require 'gp_webpay/ws/validate_result'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-gp-webpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lubomir Vnenk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-21 00:00:00.000000000 Z
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -74,17 +74,17 @@ files:
74
74
  - config/wsdl/GPwebpayAdditionalInfoResponse_v1.xsd
75
75
  - config/wsdl/cws_v1.wsdl
76
76
  - config/wsdl/swaref.xsd
77
- - lib/gp_webpay.rb
78
77
  - lib/gp_webpay/configuration.rb
79
78
  - lib/gp_webpay/engine.rb
80
79
  - lib/gp_webpay/error.rb
81
80
  - lib/gp_webpay/http/base_signed_request.rb
82
- - lib/gp_webpay/http/create_order.rb
83
81
  - lib/gp_webpay/http/external_url.rb
84
82
  - lib/gp_webpay/http/http_request.rb
85
83
  - lib/gp_webpay/http/http_response.rb
84
+ - lib/gp_webpay/http/services/create_order.rb
85
+ - lib/gp_webpay/http/services/verify_card.rb
86
86
  - lib/gp_webpay/http/validate_result.rb
87
- - lib/gp_webpay/http/verify_card.rb
87
+ - lib/gp_webpay/mock/spec_helper.rb
88
88
  - lib/gp_webpay/openssl_security.rb
89
89
  - lib/gp_webpay/response.rb
90
90
  - lib/gp_webpay/service.rb
@@ -106,6 +106,7 @@ files:
106
106
  - lib/gp_webpay/ws/validate_result.rb
107
107
  - lib/gp_webpay/ws/ws_request.rb
108
108
  - lib/gp_webpay/ws/ws_response.rb
109
+ - lib/rails-gp-webpay.rb
109
110
  homepage: https://github.com/lubosch/gp_webpay
110
111
  licenses:
111
112
  - MIT
@@ -1,18 +0,0 @@
1
- ##
2
- # Service object creates request data for GP Webpay CARD_VERIFICATION operation.
3
-
4
- module GpWebpay
5
- module Http
6
- class VerifyCard < BaseSignedRequest
7
- def initialize(attributes, locale, merchant_number: nil, url_attributes: {})
8
- super(attributes, locale, 'CARD_VERIFICATION', merchant_number: merchant_number, url_attributes: url_attributes)
9
- end
10
-
11
- protected
12
-
13
- def callback_url
14
- GpWebpay::Engine.routes.url_helpers.gp_webpay_cards_path({ merchant_number: config.merchant_number, locale: locale }.merge(url_attributes))
15
- end
16
- end
17
- end
18
- end