amex_enhanced_authorization 0.3.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec1a4a492c700a91947daad158fc2a24e240d7c36170e48ca33465aae30b09dc
4
- data.tar.gz: 7cac1d5df02f10862d964834bb2bf7b0b4a493e37f490625cdd48223d2c43c16
3
+ metadata.gz: f92d48c4a6da7df0bdcaa400cfc6c83a91c245b0d67f86664aa65db5518d8492
4
+ data.tar.gz: cc81b1ddf4bc65c03e53ed4a1fcefee4b4939ac2a7f5a88649adf5e7c328fb0d
5
5
  SHA512:
6
- metadata.gz: 519ebbcdaf6fce451615e02dd9db8b8aa35dabda0a39d54e7d764d2bcdfd42c0b66b769db86aa67fd51c6d5f7149c4e815d497b9cd2a4c4be262be1ca1fb9970
7
- data.tar.gz: b7ba76ce6998284ffa842be4f932f1b50c90aa79fc5414b3de536e1ff53c8e294751d6cb7667e37e2faa2d966e9e65189ea15cc41b196d85219d19284227865e
6
+ metadata.gz: 159be671b9a3c9669eb9cbddf0ee7301d37d231b457ebc5c618df07636b2eb04f68e569c597c9e2812f0b3d7e6a5080b69ca8593e064e046c586c1be19554fa8
7
+ data.tar.gz: 1be8d12c7c384cd083c77a2b0f3c0ff909d3780002114f80dade78e681880b09f2934c870c8749db73e8e462a5a171180422400c4d89c2683b267db65ba2fa15
@@ -0,0 +1,29 @@
1
+ ---
2
+
3
+ name: ci
4
+
5
+ on: [push]
6
+
7
+ jobs:
8
+ test:
9
+
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ ruby-version: ['3.0', '3.3']
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
22
+ - name: Run tests
23
+ env:
24
+ AEEA_CLIENT_ID: ${{ secrets.AEEA_CLIENT_ID }}
25
+ AEEA_CLIENT_SECRET: ${{ secrets.AEEA_CLIENT_SECRET }}
26
+ AEEA_CERT: ${{ secrets.AEEA_CERT }}
27
+ AEEA_KEY: ${{ secrets.AEEA_KEY }}
28
+
29
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AmexEnhancedAuthorization
2
2
 
3
- [![Travis CI Status](https://secure.travis-ci.org/varyonic/amex_enhanced_authorization.svg)](https://travis-ci.org/varyonic/amex_enhanced_authorization)
3
+ [![Github Actions ][actions_badge]][actions]
4
4
 
5
5
  Unofficial Ruby wrapper for American Express Enhanced Authorization
6
6
  published via the [amex developer portal](https://developer.americanexpress.com/products/enhanced-authorization-v2/),
@@ -20,18 +20,30 @@ And then execute:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ See [specs](https://github.com/varyonic/amex_enhanced_authorization/blob/master/spec/amex_enhanced_authorization_spec.rb) for sample usage.
24
24
 
25
25
  ## Development
26
26
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+ After checking out the repo, run `bin/setup` to install dependencies, then run `rake spec` to run the tests. The following environment variables are required:
28
28
 
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+ AEEA_CLIENT_ID
30
+ AEEA_CLIENT_SECRET
31
+ AEEA_CERT
32
+ AEEA_KEY
33
+
34
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
35
 
31
36
  ## Contributing
32
37
 
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/amex_enhanced_authorization.
38
+ Bug reports and pull requests are [welcome on GitHub](https://github.com/varyonic/amex_enhanced_authorization).
34
39
 
35
40
  ## License
36
41
 
37
42
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ Read the [LICENSE](LICENSE.txt) for details.
45
+
46
+ Copyright (c) 2019-2021 [Varyonic](https://www.varyonic.com).
47
+
48
+ [actions_badge]: https://github.com/varyonic/amex_enhanced_authorization/workflows/ci/badge.svg
49
+ [actions]: https://github.com/varyonic/amex_enhanced_authorization/actions
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.17"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake"
27
26
  spec.add_development_dependency "rspec", "~> 3.0"
28
27
  end
@@ -3,14 +3,26 @@ module AmexEnhancedAuthorization
3
3
  attr_reader :host
4
4
  attr_reader :base_path
5
5
  attr_reader :client_id, :client_secret
6
+ attr_reader :options
6
7
  attr_accessor :logger
7
8
 
9
+ # @param [String] host, e.g. 'api.americanexpress.com'
10
+ # @param [String] client_id
11
+ # @param [String] client_secret
12
+ # @param [Logger] logger
13
+ # @param [Hash] **options - additional HTTPS options
14
+ # @option [Symbol] :verify_mode, eg. OpenSSL::SSL::VERIFY_PEER (default)
15
+ # @option [OpenSSL::X509::Certificate] :cert
16
+ # @option [OpenSSL::PKey::EC] :key
17
+ # @option [String] :ca_file - String file path
8
18
  def initialize(host:,
9
19
  client_id:, client_secret:,
10
- logger: Logger.new('/dev/null'))
20
+ logger: null_logger,
21
+ **options)
11
22
  @host = host
12
23
  @base_path = "/risk/fraud/v2/apiplatform/enhanced_authorizations".freeze
13
24
  @client_id, @client_secret = client_id, client_secret
25
+ @options = options
14
26
  @logger = logger
15
27
  end
16
28
 
@@ -23,7 +35,7 @@ module AmexEnhancedAuthorization
23
35
  resource_path = "#{base_path}/#{route}"
24
36
  authorization = hmac_authorization(method, resource_path, payload)
25
37
  request = Request.new(method, "https://#{host}#{resource_path}", client_id, logger)
26
- request.send(payload, authorization)
38
+ request.send(payload, authorization, **options)
27
39
  end
28
40
 
29
41
  # @param [String] method, e.g. 'POST'
@@ -39,5 +51,9 @@ module AmexEnhancedAuthorization
39
51
  def hmac_digest(s)
40
52
  Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, client_secret, s.to_s))
41
53
  end
54
+
55
+ def null_logger
56
+ Logger.new('/dev/null')
57
+ end
42
58
  end
43
59
  end
@@ -8,6 +8,9 @@ module AmexEnhancedAuthorization
8
8
  attr_reader :uri, :request
9
9
  attr_reader :logger
10
10
 
11
+ # @param [String] method, e.g. 'POST'
12
+ # @param [String] path, e.g. '/payments/digital/v2/tokens/provisioning'
13
+ # @param [Logger] logger
11
14
  def initialize(method, path, logger)
12
15
  @uri = URI(path)
13
16
  @request = Net::HTTP.const_get(method.capitalize).new(@uri)
@@ -16,10 +19,12 @@ module AmexEnhancedAuthorization
16
19
 
17
20
  # Add provided headers and invoke request over HTTPS.
18
21
  # @return response
19
- def send(data)
22
+ def send(data, options)
20
23
  headers.each_pair { |k, v| request[k] = v }
21
- log_request_response(headers, data) do
22
- https(uri).request(request)
24
+ log_request_response(headers, data, options) do
25
+ options[:cert] = OpenSSL::X509::Certificate.new(options[:cert]) if options[:cert].is_a?(String)
26
+ options[:key] = OpenSSL::PKey::RSA.new(options[:key]) if options[:key].is_a?(String)
27
+ https(uri, options).request(request)
23
28
  end
24
29
  end
25
30
 
@@ -30,15 +35,21 @@ module AmexEnhancedAuthorization
30
35
 
31
36
  protected
32
37
 
33
- def https(uri)
34
- Net::HTTP.new(uri.host, uri.port).tap { |http| http.use_ssl = true }
38
+ def https(uri, options = {})
39
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
40
+ http.use_ssl = true
41
+ # Set any supported Net::HTTP options from the options hash
42
+ %i[verify_mode cert key ca_file].each do |opt|
43
+ http.public_send("#{opt}=", options[opt]) if options[opt]
44
+ end
45
+ end
35
46
  end
36
47
 
37
48
  # Log URI, method, data
38
49
  # Start timer.
39
50
  # Yield to request block.
40
51
  # Log response and time taken.
41
- def log_request_response(headers, data = nil)
52
+ def log_request_response(headers, data = nil, options = {})
42
53
  logger.info "[#{self.class.name}] request = #{request.method} #{uri}#{data ? '?' + data : ''}"
43
54
  logger.info "[#{self.class.name}] headers = #{headers}"
44
55
  response = nil
@@ -33,21 +33,25 @@ module AmexEnhancedAuthorization
33
33
  def purchaser_information
34
34
  @purchaser_information ||= {
35
35
  customer_email: customer_email,
36
- billing_address: ascify(billing_address),
37
- billing_postal_code: billing_postal_code,
38
- billing_first_name: billing_first_name,
39
- billing_last_name: ascify(billing_last_name),
36
+ billing_address: munge(billing_address, /[^A-Za-z0-9 ]/, 70),
37
+ billing_postal_code: munge(billing_postal_code, /[^A-Za-z0-9\- ]/, 9),
38
+ billing_first_name: munge(billing_first_name, /[^A-Za-z0-9 ]/, 30),
39
+ billing_last_name: munge(billing_last_name, /[^A-Za-z0-9 ]/, 30),
40
40
  billing_phone_number: billing_phone_number,
41
- shipto_address: shipto_address,
41
+ shipto_address: munge(shipto_address, /[^A-Za-z0-9 ]/, 50),
42
42
  shipto_postal_code: shipto_postal_code,
43
43
  shipto_first_name: shipto_first_name,
44
- shipto_last_name: ascify(shipto_last_name),
44
+ shipto_last_name: munge(shipto_last_name, /[^A-Za-z0-9 ]/, 30),
45
45
  shipto_phone_number: shipto_phone_number,
46
46
  shipto_country_code: shipto_country_code,
47
47
  device_ip: device_ip,
48
48
  }.compact
49
49
  end
50
50
 
51
+ def munge(s, exp, length)
52
+ s && ascify(s).gsub(exp, ' ')[0..(length-1)]
53
+ end
54
+
51
55
  def ascify(s)
52
56
  s && s.tr(
53
57
  "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
@@ -11,10 +11,10 @@ module AmexEnhancedAuthorization
11
11
  end
12
12
 
13
13
  # Return response on success or log failure and throw error.
14
- def send(data, authorization)
14
+ def send(data, authorization, **options)
15
15
  @authorization = authorization
16
16
  request.body = data if data
17
- response = super(data)
17
+ response = super(data, options.compact)
18
18
  fail_unless_expected_response response, Net::HTTPSuccess
19
19
  response.body
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module AmexEnhancedAuthorization
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amex_enhanced_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piers Chambers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-17 00:00:00.000000000 Z
11
+ date: 2025-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.17'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.17'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,16 +38,16 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '3.0'
55
- description:
41
+ description:
56
42
  email:
57
43
  - piers@varyonic.com
58
44
  executables: []
59
45
  extensions: []
60
46
  extra_rdoc_files: []
61
47
  files:
48
+ - ".github/workflows/ci.yaml"
62
49
  - ".gitignore"
63
50
  - ".rspec"
64
- - ".travis.yml"
65
51
  - Gemfile
66
52
  - LICENSE.txt
67
53
  - README.md
@@ -79,7 +65,7 @@ homepage: https://github.com/varyonic/amex_enhanced_authorization
79
65
  licenses:
80
66
  - MIT
81
67
  metadata: {}
82
- post_install_message:
68
+ post_install_message:
83
69
  rdoc_options: []
84
70
  require_paths:
85
71
  - lib
@@ -94,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
80
  - !ruby/object:Gem::Version
95
81
  version: '0'
96
82
  requirements: []
97
- rubygems_version: 3.0.3
98
- signing_key:
83
+ rubygems_version: 3.3.26
84
+ signing_key:
99
85
  specification_version: 4
100
86
  summary: Unofficial Ruby wrapper for American Express Enhanced Authorization.
101
87
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.2
7
- before_install: gem install bundler -v 1.17.2