activemerchant-flexpay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: efc9425bc7f5df4e9b319613ddcae599d26092fb7907559586bb1caea2e7ca3b
4
+ data.tar.gz: 4839c1c35b69db9e716911fabbf9cfb7f0e4457b271c781b3e55b62e586c9972
5
+ SHA512:
6
+ metadata.gz: 282871f197a5692e75f8017abb4c5083be78bc17e7a259642a359f94875e7196f4c81fc787909cb52abb2a871545143ac59c3a39e84e266cd7209f84543e25f6
7
+ data.tar.gz: 2324cc724ea6a4124d3b8bba95e52aeed101886e3ec52a6429900393b7dcd623767ed82d5e328a9fa4b90434dc85b0e4e978666af2c5076142398330c9be3129
@@ -0,0 +1,9 @@
1
+ Gemfile.lock
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in active_merchant-flex_pay.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Piers Chambers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # ActiveMerchant::FlexPay
2
+
3
+ Active Merchant extension to support FlexPay.io
4
+
5
+ [![Version ][rubygems_badge]][rubygems]
6
+ [![Travis CI ][travis_badge]][travis]
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'activemerchant-flexpay'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ See activemerchant gem.
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ 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
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/varyonic/activemerchant-flexpay.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ [rubygems_badge]: http://img.shields.io/gem/v/activemerchant-flexpay.svg
39
+ [rubygems]: https://rubygems.org/gems/activemerchant-flexpay
40
+ [travis_badge]: http://img.shields.io/travis/varyonic/activemerchant-flexpay/master.svg
41
+ [travis]: https://travis-ci.org/varyonic/activemerchant-flexpay
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => 'test:units'
11
+
12
+ namespace :test do
13
+ Rake::TestTask.new(:units) do |t|
14
+ t.pattern = 'test/unit/**/*_test.rb'
15
+ t.libs << 'test'
16
+ t.verbose = true
17
+ end
18
+
19
+ desc 'Run all tests that do not require network access'
20
+ task :local => ['test:units', 'rubocop']
21
+
22
+ Rake::TestTask.new(:remote) do |t|
23
+ t.pattern = 'test/remote/**/*_test.rb'
24
+ t.libs << 'test'
25
+ t.verbose = true
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "active_merchant/flex_pay/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activemerchant-flexpay"
8
+ spec.version = ActiveMerchant::FlexPay::VERSION
9
+ spec.authors = ["Piers Chambers"]
10
+ spec.email = ["piers@varyonic.com"]
11
+
12
+ spec.summary = %q{Active Merchant extension to support FlexPay.io}
13
+ spec.homepage = "https://github.com/varyonic/activemerchant-flexpay"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency 'activemerchant'
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency('test-unit', '~> 3')
30
+ spec.add_development_dependency('mocha', '~> 1')
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_merchant/flex_pay"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,215 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class FlexPayGateway < Gateway
4
+ self.live_url = self.test_url = 'https://api.flexpay.io/v1'
5
+
6
+ self.supported_countries = ['US']
7
+ self.default_currency = 'USD'
8
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
9
+
10
+ self.homepage_url = 'https://support.flexpay.io/support/home'
11
+ self.display_name = 'FlexPay'
12
+
13
+ self.money_format = :cents
14
+
15
+ STANDARD_ERROR_CODE_MAPPING = {
16
+ # Soft decline
17
+ '20000' => STANDARD_ERROR_CODE[:call_issuer],
18
+ '20003' => STANDARD_ERROR_CODE[:card_declined],
19
+ # Hard decline
20
+ '30001' => STANDARD_ERROR_CODE[:pickup_card],
21
+ '30002' => STANDARD_ERROR_CODE[:pickup_card], # may be lost or stolen
22
+ '30012' => STANDARD_ERROR_CODE[:incorrect_number],
23
+ '30015' => STANDARD_ERROR_CODE[:processing_error], # invalid amount, eg. refund
24
+ '30026' => STANDARD_ERROR_CODE[:expired_card],
25
+ '33049' => STANDARD_ERROR_CODE[:invalid_cvc],
26
+ # Validation error
27
+ '50055' => STANDARD_ERROR_CODE[:invalid_expiry_date], # month missing
28
+ '50056' => STANDARD_ERROR_CODE[:invalid_expiry_date], # month invalid
29
+ '50057' => STANDARD_ERROR_CODE[:invalid_expiry_date], # year missing
30
+ '50058' => STANDARD_ERROR_CODE[:invalid_expiry_date], # year invalid
31
+ '50131' => STANDARD_ERROR_CODE[:processing_error], # transaction not found, eg. void
32
+ }
33
+
34
+ def initialize(options={})
35
+ requires!(options, :api_key)
36
+ super
37
+ end
38
+
39
+ def purchase(money, payment, options={})
40
+ post = {}
41
+ add_invoice(post, money, options)
42
+ add_payment(post, payment)
43
+ add_address(post, payment, options)
44
+ add_customer_data(post, options)
45
+
46
+ commit('gateways/charge', post)
47
+ end
48
+
49
+ def authorize(money, payment, options={})
50
+ post = {}
51
+ add_invoice(post, money, options)
52
+ add_payment(post, payment)
53
+ add_address(post, payment, options)
54
+ add_customer_data(post, options)
55
+
56
+ commit('gateways/authorize', post)
57
+ end
58
+
59
+ def capture(money, authorization, options={})
60
+ post = {}
61
+ post[:amount] = amount(money)
62
+ post[:merchantTransactionId] = generate_unique_id
63
+ commit("transactions/#{authorization}/capture", post)
64
+ end
65
+
66
+ def refund(money, authorization, options={})
67
+ post = {}
68
+ post[:amount] = amount(money)
69
+ post[:merchantTransactionId] = generate_unique_id
70
+ commit("transactions/#{authorization}/refund", post)
71
+ end
72
+
73
+ def void(authorization, options={})
74
+ post = {}
75
+ post[:merchantTransactionId] = generate_unique_id
76
+ commit("transactions/#{authorization}/void", post)
77
+ end
78
+
79
+ def verify(credit_card, options={})
80
+ MultiResponse.run(:use_first_response) do |r|
81
+ r.process { authorize(100, credit_card, options) }
82
+ r.process(:ignore_result) { void(r.authorization, options) }
83
+ end
84
+ end
85
+
86
+ def supports_scrubbing?
87
+ true
88
+ end
89
+
90
+ def scrub(transcript)
91
+ transcript.
92
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
93
+ gsub(%r(("creditCardNumber\\?":\\?")[^"]*)i, '\1[FILTERED]').
94
+ gsub(%r(("cvv\\?":\\?")[^"]*)i, '\1[FILTERED]')
95
+ end
96
+
97
+ private
98
+
99
+ def add_customer_data(post, options)
100
+ if options[:email].present?
101
+ post[:paymentMethod][:email] = options[:email]
102
+ else
103
+ post[:customerId] = options[:customer_id] || generate_unique_id
104
+ end
105
+ add_shipping_address(post, options[:shipping_address]) if options[:shipping_address]
106
+ end
107
+
108
+ def add_address(post, creditcard, options)
109
+ address = options[:billing_address] || options[:address] || {}
110
+ post[:paymentMethod][:address1] = address[:address1] if address[:address1].present?
111
+ post[:paymentMethod][:address2] = address[:address2] if address[:address2].present?
112
+ post[:paymentMethod][:postalCode] = address[:zip]
113
+ post[:paymentMethod][:city] = address[:city]
114
+ post[:paymentMethod][:state] = address[:state]
115
+ post[:paymentMethod][:country] = address[:country] if address[:country]
116
+ end
117
+
118
+ def add_shipping_address(post, address)
119
+ post[:shippingAddress] = {}
120
+ post[:shippingAddress][:address1] = address[:address1] if address[:address1].present?
121
+ post[:shippingAddress][:address2] = address[:address2] if address[:address2].present?
122
+ post[:shippingAddress][:postalCode] = address[:zip]
123
+ post[:shippingAddress][:city] = address[:city]
124
+ post[:shippingAddress][:state] = address[:state]
125
+ post[:shippingAddress][:country] = address[:country] if address[:country]
126
+ end
127
+
128
+ def add_invoice(post, money, options)
129
+ post[:merchantTransactionId] = generate_unique_id
130
+ post[:orderId] = options[:order_id] || post[:merchantTransactionId]
131
+ post[:amount] = amount(money)
132
+ post[:currencyCode] = (options[:currency] || currency(money))
133
+ end
134
+
135
+ def add_payment(post, payment)
136
+ post[:retainOnSuccess] = 'true'
137
+ post[:paymentMethod] = {
138
+ creditCardNumber: payment.number,
139
+ expiryMonth: payment.month,
140
+ expiryYear: payment.year,
141
+ cvv: payment.verification_value,
142
+ fullName: payment.name
143
+ }
144
+ post[:retryCount] = 0
145
+ end
146
+
147
+ def headers(api_key)
148
+ {
149
+ 'Authorization' => "Basic #{api_key}",
150
+ 'Content-Type' => 'application/json',
151
+ 'User-Agent' => "ActiveMerchant::FlexPay/#{ActiveMerchant::FlexPay::VERSION}"
152
+ }
153
+ end
154
+
155
+ def parse(body)
156
+ return {} if body.blank?
157
+ JSON.parse(body).fetch('transaction')
158
+ rescue JSON::ParserError
159
+ message = 'Unparsable response received from FlexPay. Please contact FlexPay if you continue to receive this message.'
160
+ message += " (The raw response returned by the API was #{body.inspect})"
161
+ { 'message' => message }
162
+ end
163
+
164
+ def commit(uri, parameters)
165
+ url = (test? ? test_url : live_url)
166
+ headers = headers(@options[:api_key])
167
+ response = parse(ssl_post(get_url(uri), post_data(parameters), headers))
168
+
169
+ Response.new(
170
+ success_from(response),
171
+ message_from(response),
172
+ response,
173
+ authorization: authorization_from(response),
174
+ avs_result: AVSResult.new(code: response['response']['avsCode']),
175
+ cvv_result: CVVResult.new(response['response']['cvvCode']),
176
+ test: test?,
177
+ error_code: error_code_from(response)
178
+ )
179
+ rescue ResponseError => e
180
+ case e.response.code
181
+ when '401', '405'
182
+ return Response.new(false, e.response.message, {}, :test => test?)
183
+ end
184
+ raise
185
+ end
186
+
187
+ def get_url(uri)
188
+ url = (test? ? test_url : live_url)
189
+ "#{url}/#{uri}"
190
+ end
191
+
192
+ def success_from(response)
193
+ response['responseCode'] == '10000'
194
+ end
195
+
196
+ def message_from(response)
197
+ response['message']
198
+ end
199
+
200
+ def authorization_from(response)
201
+ response['transactionId']
202
+ end
203
+
204
+ def post_data(parameters = {})
205
+ JSON.generate(transaction: parameters)
206
+ end
207
+
208
+ def error_code_from(response)
209
+ unless success_from(response)
210
+ STANDARD_ERROR_CODE_MAPPING[response['responseCode']]
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,3 @@
1
+ require "active_merchant"
2
+ require "active_merchant/flex_pay/version"
3
+ require "active_merchant/billing/gateways/flex_pay"
@@ -0,0 +1,5 @@
1
+ module ActiveMerchant
2
+ module FlexPay
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'active_merchant/flex_pay'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activemerchant-flexpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piers Chambers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemerchant
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ description:
84
+ email:
85
+ - piers@varyonic.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - activemerchant-flexpay.gemspec
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/active_merchant/billing/gateways/flex_pay.rb
101
+ - lib/active_merchant/flex_pay.rb
102
+ - lib/active_merchant/flex_pay/version.rb
103
+ - lib/activemerchant-flexpay.rb
104
+ homepage: https://github.com/varyonic/activemerchant-flexpay
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Active Merchant extension to support FlexPay.io
127
+ test_files: []