rails-gp-webpay 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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +41 -0
  3. data/Rakefile +6 -0
  4. data/app/controllers/gp_webpay/cards_controller.rb +11 -0
  5. data/app/controllers/gp_webpay/orders_controller.rb +11 -0
  6. data/app/controllers/gp_webpay_controller.rb +18 -0
  7. data/changelog.md +4 -0
  8. data/config/keys/cert.pem +8 -0
  9. data/config/keys/pkey.pem +13 -0
  10. data/config/routes.rb +4 -0
  11. data/config/wsdl/GPwebpayAdditionalInfoResponse_v1.xsd +194 -0
  12. data/config/wsdl/cws_v1.wsdl +2355 -0
  13. data/config/wsdl/swaref.xsd +59 -0
  14. data/lib/gp_webpay.rb +55 -0
  15. data/lib/gp_webpay/configuration.rb +65 -0
  16. data/lib/gp_webpay/engine.rb +7 -0
  17. data/lib/gp_webpay/error.rb +4 -0
  18. data/lib/gp_webpay/http/base_signed_request.rb +72 -0
  19. data/lib/gp_webpay/http/create_order.rb +24 -0
  20. data/lib/gp_webpay/http/external_url.rb +13 -0
  21. data/lib/gp_webpay/http/http_request.rb +63 -0
  22. data/lib/gp_webpay/http/http_response.rb +40 -0
  23. data/lib/gp_webpay/http/validate_result.rb +63 -0
  24. data/lib/gp_webpay/http/verify_card.rb +18 -0
  25. data/lib/gp_webpay/openssl_security.rb +16 -0
  26. data/lib/gp_webpay/response.rb +34 -0
  27. data/lib/gp_webpay/service.rb +15 -0
  28. data/lib/gp_webpay/version.rb +3 -0
  29. data/lib/gp_webpay/ws/base_signed_request.rb +69 -0
  30. data/lib/gp_webpay/ws/echo.rb +35 -0
  31. data/lib/gp_webpay/ws/services/get_master_payment_status.rb +32 -0
  32. data/lib/gp_webpay/ws/services/get_payment_status.rb +19 -0
  33. data/lib/gp_webpay/ws/services/get_token_status.rb +21 -0
  34. data/lib/gp_webpay/ws/services/process_cancel_capture.rb +20 -0
  35. data/lib/gp_webpay/ws/services/process_capture_reverse.rb +20 -0
  36. data/lib/gp_webpay/ws/services/process_card_on_file_payment.rb +40 -0
  37. data/lib/gp_webpay/ws/services/process_master_payment_revoke.rb +20 -0
  38. data/lib/gp_webpay/ws/services/process_recurring_payment.rb +20 -0
  39. data/lib/gp_webpay/ws/services/process_refund_payment.rb +20 -0
  40. data/lib/gp_webpay/ws/services/process_token_payment.rb +26 -0
  41. data/lib/gp_webpay/ws/services/process_token_revoke.rb +20 -0
  42. data/lib/gp_webpay/ws/services/process_usage_based_payment.rb +21 -0
  43. data/lib/gp_webpay/ws/validate_result.rb +48 -0
  44. data/lib/gp_webpay/ws/ws_request.rb +39 -0
  45. data/lib/gp_webpay/ws/ws_response.rb +54 -0
  46. metadata +135 -0
@@ -0,0 +1,20 @@
1
+ ##
2
+ # Service object changes credit card token status to "REVOKED".
3
+ # Should be used when user decides to remove card from system.
4
+ #
5
+ # @param [Hash] attributes for GP Webpay
6
+ #
7
+ # @return [GpwebpayWsResponse] response value object
8
+
9
+ module GpWebpay
10
+ module Ws
11
+ module Services
12
+ class ProcessTokenRevoke < BaseSignedRequest
13
+ OPERATION_NAME = :process_token_revoke
14
+ REQUEST_NAME = :token_revoke_request
15
+ RESPONSE_NAME = :process_token_revoke_response
16
+ RESPONSE_ENTITY_NAME = :token_revoke_response
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ ##
2
+ # Service object creates fast payment without need of leaving user from Wilio web / app.
3
+ # It uses VERIFIED credit card token to skip filling card again and 3D secure step.
4
+ #
5
+ # @param [Hash] attributes for GP Webpay
6
+ #
7
+ # @return [GpwebpayWsResponse] response value object
8
+
9
+ module GpWebpay
10
+ module Ws
11
+ module Services
12
+ class ProcessUsageBasedPayment < BaseSignedRequest
13
+ OPERATION_NAME = :process_usage_based_payment
14
+ REQUEST_NAME = :usage_based_payment_request
15
+ RESPONSE_NAME = :process_usage_based_payment_response
16
+ RESPONSE_ENTITY_NAME = :usage_based_payment_response
17
+ SERVICE_EXCEPTION = :payment_service_exception
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ ##
2
+ # Service object validates result received from GP Webpay response by WS in XML format.
3
+ #
4
+ # 1. Use public cert of GP Webpay to verify it comes from GP Webpay.
5
+ # 2. Whitelist allowed attributes which are expected from GP Webpay.
6
+ # 3. Calculate signature and make sure it corresponds to received signature.
7
+ #
8
+ # @param [Hash] Parameters hash received in XML response from GP Webpay.
9
+ #
10
+ # @return [Boolean] true if signature is valid for both digests.
11
+
12
+ module GpWebpay
13
+ module Ws
14
+ class ValidateResult < Service
15
+ attr_reader :params, :config
16
+
17
+ DIGEST_ALLOWED_ATTRIBUTES = %i[
18
+ primary_return_code
19
+ secondary_return_code
20
+ message_id
21
+ state
22
+ status
23
+ sub_status
24
+ auth_code
25
+ token_data
26
+ authentication_link
27
+ ].freeze
28
+
29
+ def initialize(params, config)
30
+ super()
31
+ @params = params
32
+ @config = config
33
+ end
34
+
35
+ def call
36
+ params.present? &&
37
+ params[:signature].present? &&
38
+ OpensslSecurity.validate_digests(config, params[:signature] => digest_verification)
39
+ end
40
+
41
+ private
42
+
43
+ def digest_verification
44
+ @digest_verification ||= params.slice(*(params.keys & DIGEST_ALLOWED_ATTRIBUTES)).values.join('|')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ module GpWebpay
2
+ module Ws
3
+ class WsRequest
4
+ attr_accessor :attributes
5
+
6
+ ATTRS_TO_GP_MAPPER = {
7
+ 'ins0:messageId' => :message_id,
8
+ 'ins0:provider' => :provider,
9
+ 'ins0:merchantNumber' => :merchant_number,
10
+ 'ins0:paymentNumber' => :payment_number,
11
+ 'ins0:masterPaymentNumber' => :master_payment_number,
12
+ 'ins0:orderNumber' => :order_number,
13
+ 'ins0:captureNumber' => :capture_number,
14
+ 'ins0:amount' => :amount,
15
+ 'ins0:currencyCode' => :currency_code,
16
+ 'ins0:captureFlag' => :capture_flag,
17
+ 'ins0:tokenData' => :token_data,
18
+ 'ins0:returnUrl' => :return_url
19
+ }.freeze
20
+
21
+ def initialize(attributes)
22
+ @attributes = attributes || {}
23
+ end
24
+
25
+ def to_gpwebpay
26
+ @to_gpwebpay ||= transform_to_gpwebpay
27
+ end
28
+
29
+ private
30
+
31
+ def transform_to_gpwebpay
32
+ ATTRS_TO_GP_MAPPER.each_with_object({}) do |(k, v), attrs|
33
+ attribute_value = attributes[v] || attributes[v.to_s]
34
+ attrs[k] = attribute_value if attribute_value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ module GpWebpay
2
+ module Ws
3
+ class WsResponse < Response
4
+ attr_accessor :validation_response
5
+
6
+ def self.from_success(hash, response_name, response_entity_name, merchant_number)
7
+ validation_response = hash.dig(response_name, response_entity_name)
8
+ new(
9
+ original_response: hash,
10
+ params: validation_response,
11
+ status: validation_response[:status],
12
+ token: validation_response[:token_data],
13
+ pr_code: validation_response[:primary_return_code],
14
+ sr_code: validation_response[:secondary_return_code],
15
+ merchant_number: merchant_number,
16
+ result_text: 'OK'
17
+ )
18
+ end
19
+
20
+ def self.from_fault_error(hash, exception, merchant_number)
21
+ validation_response = hash.dig(:fault, :detail, exception)
22
+ new(
23
+ original_response: hash,
24
+ params: validation_response,
25
+ status: :error,
26
+ pr_code: validation_response[:primary_return_code],
27
+ sr_code: validation_response[:secondary_return_code],
28
+ result_text: hash.dig(:fault, :faultstring),
29
+ merchant_number: merchant_number
30
+ )
31
+ end
32
+
33
+ def self.from_http_error(hash, merchant_number)
34
+ new(
35
+ original_response: hash,
36
+ params: {},
37
+ status: :error,
38
+ pr_code: nil,
39
+ sr_code: nil,
40
+ result_text: "Internal HTTP request error: '#{hash[:code]}'",
41
+ merchant_number: merchant_number
42
+ )
43
+ end
44
+
45
+ def valid?
46
+ @valid ||= GpWebpay::Ws::ValidateResult.call(params, config)
47
+ end
48
+
49
+ def success?
50
+ @success ||= (status != :error)
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-gp-webpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lubomir Vnenk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ description: Gem for integrating GP Webpay HTTP api and WS recurring payments with
56
+ multiple merchants
57
+ email:
58
+ - lubomir.vnenk@zoho.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - README.md
63
+ - changelog.md
64
+ files:
65
+ - README.md
66
+ - Rakefile
67
+ - app/controllers/gp_webpay/cards_controller.rb
68
+ - app/controllers/gp_webpay/orders_controller.rb
69
+ - app/controllers/gp_webpay_controller.rb
70
+ - changelog.md
71
+ - config/keys/cert.pem
72
+ - config/keys/pkey.pem
73
+ - config/routes.rb
74
+ - config/wsdl/GPwebpayAdditionalInfoResponse_v1.xsd
75
+ - config/wsdl/cws_v1.wsdl
76
+ - config/wsdl/swaref.xsd
77
+ - lib/gp_webpay.rb
78
+ - lib/gp_webpay/configuration.rb
79
+ - lib/gp_webpay/engine.rb
80
+ - lib/gp_webpay/error.rb
81
+ - lib/gp_webpay/http/base_signed_request.rb
82
+ - lib/gp_webpay/http/create_order.rb
83
+ - lib/gp_webpay/http/external_url.rb
84
+ - lib/gp_webpay/http/http_request.rb
85
+ - lib/gp_webpay/http/http_response.rb
86
+ - lib/gp_webpay/http/validate_result.rb
87
+ - lib/gp_webpay/http/verify_card.rb
88
+ - lib/gp_webpay/openssl_security.rb
89
+ - lib/gp_webpay/response.rb
90
+ - lib/gp_webpay/service.rb
91
+ - lib/gp_webpay/version.rb
92
+ - lib/gp_webpay/ws/base_signed_request.rb
93
+ - lib/gp_webpay/ws/echo.rb
94
+ - lib/gp_webpay/ws/services/get_master_payment_status.rb
95
+ - lib/gp_webpay/ws/services/get_payment_status.rb
96
+ - lib/gp_webpay/ws/services/get_token_status.rb
97
+ - lib/gp_webpay/ws/services/process_cancel_capture.rb
98
+ - lib/gp_webpay/ws/services/process_capture_reverse.rb
99
+ - lib/gp_webpay/ws/services/process_card_on_file_payment.rb
100
+ - lib/gp_webpay/ws/services/process_master_payment_revoke.rb
101
+ - lib/gp_webpay/ws/services/process_recurring_payment.rb
102
+ - lib/gp_webpay/ws/services/process_refund_payment.rb
103
+ - lib/gp_webpay/ws/services/process_token_payment.rb
104
+ - lib/gp_webpay/ws/services/process_token_revoke.rb
105
+ - lib/gp_webpay/ws/services/process_usage_based_payment.rb
106
+ - lib/gp_webpay/ws/validate_result.rb
107
+ - lib/gp_webpay/ws/ws_request.rb
108
+ - lib/gp_webpay/ws/ws_response.rb
109
+ homepage: https://github.com/lubosch/gp_webpay
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ homepage_uri: https://github.com/lubosch/gp_webpay
114
+ source_code_uri: https://github.com/lubosch/gp_webpay
115
+ changelog_uri: https://github.com/lubosch/gp_webpay/blob/master/changelog.md
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.4.0
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.1.4
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Gem for integrating GP Webpay HTTP api and WS recurring payments
135
+ test_files: []