rubycicd_uat 2.0.7

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.
@@ -0,0 +1,52 @@
1
+ module Kount
2
+ ##
3
+ # Convenience class to provide a list of PTYP values
4
+ class PaymentTypes
5
+ # Credit card (VISA, MasterCard, Amercian Express, etc)
6
+ CREDIT_CARD = 'CARD'
7
+ #Generic Token
8
+ TOKEN = 'TOKEN'
9
+ # PayPal
10
+ PAYPAL = 'PYPL'
11
+ # Check
12
+ CHECK = 'CHEK'
13
+ # Merchant issued gift card (not the ones with VISA/MC on them)
14
+ GIFT_CARD = 'GIFT'
15
+ # Carte Bleue
16
+ CARTE_BLEUE = 'CARTE_BLEUE'
17
+ # Sofort
18
+ SOFORT = 'SOFORT'
19
+ # Elv
20
+ ELV = 'ELV'
21
+ # Poli
22
+ POLI = 'POLI'
23
+ # Neteller
24
+ NETELLER = 'NETELLER'
25
+ # Giropay
26
+ GIROPAY = 'GIROPAY'
27
+ # BPay
28
+ BPAY = 'BPAY'
29
+ # Interac
30
+ INTERAC = 'INTERAC'
31
+ # Apple Pay
32
+ APPLE_PAY = 'APAY'
33
+ # Skrill
34
+ SKRILL = 'SKRILL'
35
+ # Moneybooker (basically another name for Skrill)
36
+ MONEYBOOKERS = 'SKRILL'
37
+ # Mercado Pago
38
+ MERCADO_PAGO = 'MERCADE_PAGO'
39
+ # Bill Me Later
40
+ BILL_ME_LATER = 'BLML'
41
+ # Google Checkout
42
+ GOOGLE_CHECKOUT = 'GOOG'
43
+ # Green Dot Money Pack
44
+ GREEN_DOT_MONEY_PACK = 'GDMP'
45
+ # Single Euro Payments Area
46
+ SINGLE_EURO_PAYMENTS_AREA = 'SEPA'
47
+ # None
48
+ NONE = 'NONE'
49
+ # Other
50
+ OTHER = 'OTHER'
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ require 'kount/security_mash'
2
+ require 'logger'
3
+
4
+ module Kount
5
+ ##
6
+ # This class acts as an abstract class for each type of request.
7
+ class Request
8
+ attr_accessor :params
9
+
10
+ # Initialize a Request object
11
+ #
12
+ # Example usage
13
+ # Not used directly. Use Inquiry or Update instead.
14
+ #
15
+ # @param initial_params [Hash] Initial params for request
16
+ def initialize(initial_params = {})
17
+ @logger = Logger.new("Logs.log")
18
+ raise "Cannot directly instantiate a #{self.class}." if
19
+ self.class == Request
20
+ @params = initial_params
21
+ @logger.info("Request Objects : #{@params}")
22
+ end
23
+
24
+ # Add params to the current request object
25
+ # @param hash [Hash] Hash of values to be added
26
+ def add_params(hash)
27
+ @params.merge!(hash)
28
+ end
29
+
30
+ # This method creates the final state of the params collection such that
31
+ # it can be sent to RIS. Items that are specific to either the Inquiry
32
+ # or Update calls are delegated to the prepare_params method in each
33
+ # respective class.
34
+ #
35
+ # @param version [String] RIS version
36
+ # @param merchant_id [String] Merchant ID
37
+ # @param response_format [String] Response format (JSON)
38
+ # @param _ksalt [String] Kount supplied secret salt for KHASH
39
+ def prepare_params(version, merchant_id, response_format, _ksalt = '')
40
+ # The KSALT is not used here, however, it is used in the corresponding
41
+ # subclass prepare_params methods.
42
+ if merchant_id == '' # Check if merchant_id is set or not
43
+ @logger.debug("Merchant Id not set.")
44
+ elsif version.empty? # Check VERSION is set or not
45
+ @logger.debug("Version not set")
46
+ end
47
+ params.merge!(VERS: version, MERC: merchant_id, FRMT: response_format)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,90 @@
1
+ module Kount
2
+ ##
3
+ # This class extends the Request class.
4
+ class Inquiry < Request
5
+ attr_accessor :cart
6
+
7
+ # Initialize an Inquiry object
8
+ #
9
+ # Example usage
10
+ # {:MACK => "Y", :AUTH => "A"}
11
+ #
12
+ # @param initial_params [Hash] Initial params for request
13
+ def initialize(initial_params = {})
14
+ super(initial_params)
15
+ @cart = Cart.new
16
+ # We want Request to default to MODE Q unless a different mode has
17
+ # been passed.
18
+ add_params(MODE: 'Q') unless initial_params.key?(:MODE)
19
+ end
20
+
21
+ # @param version [String] RIS version
22
+ # @param merchant_id [String] Merchant ID
23
+ # @param response_format [String] Response format (JSON)
24
+ # @param ksalt [String] Kount supplied secret salt for KHASH
25
+ def prepare_params(version, merchant_id, response_format, ksalt)
26
+ super(version, merchant_id, response_format, ksalt)
27
+ begin
28
+ params.merge! collect_cart_items
29
+ # The Kount::Request has no knowledge of the KSALT or merchant_id, both
30
+ # of which are needed for KHASH. Request form params have everything we
31
+ # need at this point to do the KHASH if needed.
32
+ fixup_payment_params(ksalt, merchant_id)
33
+ end
34
+ params
35
+ end
36
+
37
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38
+ def fixup_payment_params(ksalt, merchant_id)
39
+ ptok = params[:PTOK]
40
+ case params[:PTYP]
41
+ when 'CARD', 'TOKEN'
42
+ #ptok = Kount::SecurityMash.hash_credit_card(ptok, ksalt)
43
+ ptok = Kount::Khash.hash_payment_token(ptok, ksalt)
44
+ params.merge!(PTOK: ptok, PENC: 'KHASH')
45
+ when 'GIFT', 'OTHER'
46
+ #ptok = Kount::SecurityMash.hash_gift_card(ptok, ksalt, merchant_id)
47
+ ptok = Kount::Khash.hash_gift_card(ptok, ksalt, merchant_id)
48
+ params.merge!(PTOK: ptok, PENC: 'KHASH')
49
+ when 'CHEK', 'OTHER'
50
+ ptok = Kount::Khash.hash_check_payment(ptok, ksalt)
51
+ params.merge!(PTOK: ptok, PENC: 'KHASH')
52
+ when 'NONE'
53
+ params.merge!(PTOK: nil, PENC: nil)
54
+ else
55
+ params[:PENC] ||= 'NONE'
56
+ end
57
+ end
58
+
59
+ # Pulls the cart data into the request params hash
60
+ def collect_cart_items
61
+ {
62
+ PROD_TYPE: cart.get_item(:TYPE),
63
+ PROD_DESC: cart.get_item(:DESC),
64
+ PROD_ITEM: cart.get_item(:ITEM),
65
+ PROD_PRICE: cart.get_item(:PRICE),
66
+ PROD_QUANT: cart.get_item(:QUANT)
67
+ }
68
+ end
69
+
70
+ # Puts the cart object into the request for processing
71
+ # @param cart [Kount::Cart] Cart object
72
+ def add_cart(cart)
73
+ @cart = cart
74
+ end
75
+
76
+ # Add UDF to request
77
+ # @param name [String] UDF label name
78
+ # @param value [String] UDF value
79
+ def add_udf(name, value)
80
+ @params.merge!("UDF[#{name}]" => value)
81
+ end
82
+
83
+ # Convenience method to create the payment params
84
+ # @param type [String] Payment type
85
+ # @param token [String] Payment token
86
+ def add_payment(type, token = '')
87
+ add_params(PTYP: type, PTOK: token)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,28 @@
1
+ module Kount
2
+ ##
3
+ # This class extends the Request class and is used in the
4
+ # process of sending updates to an existing transaction
5
+ # generated by a previous Inquiry request.
6
+ class Update < Request
7
+ # Initialize an Update object
8
+ #
9
+ # Example usage
10
+ # {:MACK => "Y", :AUTH => "A"}
11
+ #
12
+ # @param initial_params [Hash] Initial params for request
13
+ def initialize(initial_params = {})
14
+ super(initial_params)
15
+ # Default to mode U unless mode X is explicitly set
16
+ add_params(MODE: 'U') unless initial_params[:MODE] == 'X'
17
+ end
18
+
19
+ # @param version [String] RIS version
20
+ # @param merchant_id [String] Merchant ID
21
+ # @param response_format [String] Response format (JSON)
22
+ # @param ksalt [String] Kount supplied secret salt for KHASH
23
+ def prepare_params(version, merchant_id, response_format, ksalt)
24
+ super(version, merchant_id, response_format, ksalt)
25
+ params
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,73 @@
1
+ require 'kount'
2
+ require_relative 'Response'
3
+ require 'kount/utils/khash'
4
+
5
+
6
+ class RisRequest
7
+
8
+ options = {
9
+ merchant_id: 900431, # required (6 digit number, assigned by Kount)
10
+ key: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5MDA0MzEiLCJhdWQiOiJLb3VudC4xIiwiaWF0IjoxNTYzOTM4NjA2LCJzY3AiOnsia2EiOnRydWUsImtjIjp0cnVlLCJhcGkiOnRydWUsInJpcyI6dHJ1ZX19.WidWQkNcPeVRlBdu77cgsyQOSMRqzQHnzH3S70cnU38', #required (created in the AWC web app by merchant)
11
+ ksalt: '1b^jIFD)e1@<ZKuH"A+?Ea`p+ATAo6@:Wee+EM+(FD5Z2/N<', #required (provided by Kount)
12
+ is_test: true, # RIS endpoint is set to Kount Test Server setting
13
+ timeout:3
14
+ }
15
+
16
+
17
+ client = Kount.new(options)
18
+ inquiry = Kount::Inquiry.new(
19
+ SITE: "DEFAULT",
20
+ MACK: "Y",
21
+ AUTH: "A",
22
+ ORDR: "989898900",
23
+ TOTL: "8240",
24
+ EMAL: "test@example.com",
25
+ MODE:'Q',
26
+ ANID: "+380931234567",
27
+ B2A1: "Street F",
28
+ B2A2: "",
29
+ B2CC: "US",
30
+ B2CI: "LA",
31
+ B2ST: "LA",
32
+ B2PC: "",
33
+ B2PN: "+380931234567",
34
+ NAME: "Smith",
35
+ S2A1: "Street A",
36
+ S2A2: "",
37
+ S2PC: "",
38
+ S2PN: "+380931234567",
39
+ S2CC: "US",
40
+ S2CI: "LA",
41
+ S2ST: "LA",
42
+ PTYP: "CARD",
43
+ PTOK: "123456XXXXXXXXXX3456",
44
+ PENC: "MASK",
45
+ CURR: "USD",
46
+ IPAD: "192.168.0.1",
47
+ SESS: "5qteg2qjenchtasga2ro3862cg"
48
+ )
49
+
50
+ $i=0
51
+ $num=3
52
+ # inquiryArr = Array.new
53
+ while $i < $num do
54
+ puts("Inside loop = #{$i}")
55
+
56
+ inquiry.add_udf("PROMO",45678)
57
+ cart = Kount::Cart.new()
58
+ cart.add_item('32 inch LCD TV', 'Electronics', 'Television', '44', '1000')
59
+ inquiry.add_cart(cart)
60
+ # puts inquiry
61
+ # inquiryList = Hash.new(inquiry)
62
+ response = client.get_response(inquiry)
63
+ puts response
64
+ $i +=1
65
+ end
66
+ # inquiryArr = Array.new(inquiry)
67
+ # puts inquiryList[5]
68
+ # response = client.get_response(inquiryList)
69
+ #puts response
70
+ # ris = Response::Resp.new(response)
71
+ # puts ris.get_mode()
72
+ end
73
+ RisRequest.new()
@@ -0,0 +1,82 @@
1
+ require 'digest/sha1'
2
+ module Kount
3
+ ##
4
+ # This class implements the Kount KHASH for cards and gift cards.
5
+
6
+ class SecurityMash
7
+ # @param plain_text [String] String to be hashed
8
+ # @param ptyp [String] Payment type code: CARD, GIFT, or OTHER
9
+ # @return [String] KHASH version of string
10
+ def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '')
11
+ if ptyp == 'CARD'
12
+ hash_credit_card(plain_text, ksalt)
13
+ else
14
+ hash_gift_card(plain_text, ksalt, merchant_id)
15
+ end
16
+ end
17
+
18
+ # Hash a credit card number.
19
+ # Preserves first six characters of the input so that hashed cards can be
20
+ # categorized by Bank Identification Number (BIN).
21
+ #
22
+ # Example usage:
23
+ # hashed = Kount::SecurityMash.hash_credit_card("4111111111111111")
24
+ # Expect: 411111WMS5YA6FUZA1KC
25
+ # hashed = Kount::SecurityMash.hash_credit_card("5199185454061655")
26
+ # Expect: 5199182NOQRXNKTTFL11
27
+ # hashed = Kount::SecurityMash.hash_credit_card("4259344583883")
28
+ # Expect: 425934FEXQI1QS6TH2O5
29
+ #
30
+ # @param plain_text [String] String to be hashed
31
+ # @return [String] KHASH version of string
32
+ def self.hash_credit_card(plain_text, ksalt)
33
+ return plain_text if khashed?(plain_text)
34
+ first_six = plain_text[0..5]
35
+ mashed = mash(plain_text, 14, ksalt)
36
+ "#{first_six}#{mashed}"
37
+ end
38
+
39
+ # Hash a gift card number.
40
+ # Use the six characters of the merchant id so that hashed cards can be
41
+ # unique across the entire domain.
42
+ #
43
+ # Example usage:
44
+ # hashed = Kount::SecurityMash.hash_gift_card("123456", "3245876")
45
+ # Expect: 1234569HXH32Y5NNJCGB
46
+
47
+ # @param plain_text [String] String to be hashed
48
+ # @return [String] KHASH version of string
49
+ def self.hash_gift_card(plain_text, ksalt, merchant_id)
50
+ mashed = mash(plain_text, 14, ksalt)
51
+ "#{merchant_id}#{mashed}"
52
+ end
53
+
54
+ # Compute a base64 hash of the provided data.
55
+ #
56
+ # @param data [String] Data to hash
57
+ # @param len [int] Length of hash to retain
58
+ # @return [String] Hashed data
59
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
60
+ def self.mash(data, len, m)
61
+ a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
62
+ r = Digest::SHA1.hexdigest("#{data}.#{m}")
63
+ c = ''
64
+ len = 17 if len > 17
65
+ limit = 2 * len
66
+ i = 0
67
+ while i < limit
68
+ c << a[r[i..i + 6].to_i(16) % 36]
69
+ i += 2
70
+ end
71
+ c
72
+ end
73
+
74
+ # end mash
75
+
76
+ # @param val [String] Token that may or may not be khashed
77
+ # @return [Boolean] True if token is already khashed
78
+ def self.khashed?(val)
79
+ true if val =~ /(\d{6}[A-Z0-9]{14})/
80
+ end
81
+ end # end KountSecurityMash
82
+ end
@@ -0,0 +1,56 @@
1
+ module Kount
2
+ class Khash
3
+ # @param plain_text [String] String to be hashed
4
+ # @param ptyp [String] Payment type code: CARD, GIFT, or OTHER
5
+ # @return [String] KHASH version of string
6
+ def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '')
7
+ if ptyp == 'CARD'
8
+ HashPaymentToken(plain_text, ksalt)
9
+ elsif ptyp == 'CHEK'
10
+ HashCheckPayment(plain_text, ksalt)
11
+ else
12
+ HashGiftCard(plain_text, ksalt, merchant_id)
13
+ end
14
+ end
15
+
16
+ def self.getkhash(data, len, m)
17
+ a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
18
+ r = Digest::SHA1.hexdigest("#{data}.#{m}")
19
+ c = ''
20
+ len = 17 if len > 17
21
+ limit = 2 * len
22
+ i = 0
23
+ while i < limit
24
+ c << a[r[i..i + 6].to_i(16) % 36]
25
+ i += 2
26
+ end
27
+ c
28
+ end
29
+
30
+ def self.hash_payment_token(plain_text, ksalt)
31
+ return plain_text if khashed?(plain_text)
32
+ first_six = plain_text[0..5]
33
+ mashed = getkhash(plain_text, 14, ksalt)
34
+ "#{first_six}#{mashed}"
35
+ end
36
+
37
+ def self.hash_check_payment(plain_text, ksalt)
38
+ return plain_text if khashed?(plain_text)
39
+ first_six = plain_text[0..5]
40
+ mashed = getkhash(plain_text, 14, ksalt)
41
+ "#{first_six}#{mashed}"
42
+ end
43
+
44
+ def self.hash_gift_card(plain_text, ksalt, merchant_id)
45
+ mashed = getkhash(plain_text, 14, ksalt)
46
+ "#{merchant_id}#{mashed}"
47
+ end
48
+
49
+ # @param val [String] Token that may or may not be khashed
50
+ # @return [Boolean] True if token is already khashed
51
+ def self.khashed?(val)
52
+ true if val =~ /(\d{6}[A-Z0-9]{14})/
53
+ end
54
+
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubycicd_uat
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.7
5
+ platform: ruby
6
+ authors:
7
+ - SanjeevITT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: A wrapper to facilitate making RUBY CI/CD RIS calls
48
+ email: ruby@sanjeev.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/kount.rb
54
+ - lib/kount/Logs.log
55
+ - lib/kount/Response.rb
56
+ - lib/kount/cart.rb
57
+ - lib/kount/client.rb
58
+ - lib/kount/payment_types.rb
59
+ - lib/kount/request.rb
60
+ - lib/kount/request/inquiry.rb
61
+ - lib/kount/request/update.rb
62
+ - lib/kount/ris_inquiry.rb
63
+ - lib/kount/security_mash.rb
64
+ - lib/kount/utils/khash.rb
65
+ homepage: http://rubygems.org/gems/rubycicd_uat
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2.3'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.5
83
+ requirements: []
84
+ rubygems_version: 3.0.3
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Ruby CI/CD Services Wrapper
88
+ test_files: []