bacardi 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94d0a157f37d2267427152855927745a3ec4028b
4
+ data.tar.gz: 805174b269bb4dcb89d4db5f1161ccaaef92fcf6
5
+ SHA512:
6
+ metadata.gz: 3233f1eebbe02a1bfdd7b204ae0b387dc6283dc62b5de410d839d713f7248b3072780c03d2a62948ec566b2408f6b7b373a3a1c6121cc4effd204ec90eebd291
7
+ data.tar.gz: 166430847805d4601ba61b1d77e4009f32f88b7ee2f4645d88c0f8915f15efd48d6e8c09e2f99ce9a2697588cbe063447258839b2956c6cbd0f9753b10c95416
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neon.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Bala Paranj
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,39 @@
1
+ # Bacardi
2
+
3
+ To experiment with that code, run `bin/console` for an interactive prompt. Read the specs to see how to use the mapper class for implementing fraud checks when processing Paypal IPN notifications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bacardi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bacardi
20
+
21
+ ## Usage
22
+
23
+ Refer the specs.
24
+
25
+ ## Development
26
+
27
+ 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.
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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/bparanj/neon.
34
+
35
+ ## License
36
+
37
+ Copyright Bala Paranj
38
+
39
+ All Rights Reserved
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bacardi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bacardi"
8
+ spec.version = Bacardi::VERSION
9
+ spec.authors = ["Bala Paranj"]
10
+ spec.email = ["bparanj@gmail.com"]
11
+
12
+ spec.summary = %q{Fraud checks for IPN Payment notification.}
13
+ spec.description = %q{This gem checks for spoofed receiver email and fraudulent change in amount for the purchased product.}
14
+ spec.homepage = "http://www.rubyplus.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'money', "~> 6.6"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3"
27
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "neon"
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_relative '../lib/neon/product_amount'
14
+ require_relative '../lib/neon/notification'
15
+ require_relative '../lib/neon/payment'
16
+
17
+ require "irb"
18
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require "bacardi/version"
@@ -0,0 +1,16 @@
1
+ module Bacardi
2
+
3
+ class FraudCheck
4
+
5
+ def initialize(order, notifier)
6
+ @order = order
7
+ @notifier = notifier
8
+ end
9
+
10
+ def no_malicious_product_change?
11
+ (@order.product_id == @notifier.item_number) && (@order.product_name == @notifier.item_name)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,27 @@
1
+ require 'bigdecimal'
2
+
3
+ module Bacardi
4
+
5
+ class Notification
6
+ def initialize(notifier)
7
+ @notifier = notifier
8
+ end
9
+
10
+ def paid_currency
11
+ @notifier.currency
12
+ end
13
+
14
+ def paid_gross
15
+ BigDecimal.new((@notifier.gross.to_f.abs.to_i) * 100)
16
+ end
17
+
18
+ def confirmation_number
19
+ @notifier.invoice
20
+ end
21
+
22
+ def receiver_email
23
+ @notifier.account
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,17 @@
1
+ require 'bigdecimal'
2
+
3
+ module Bacardi
4
+ class Payment
5
+ def initialize(transaction)
6
+ @transaction = transaction
7
+ end
8
+
9
+ def actual_currency
10
+ @transaction.currency
11
+ end
12
+
13
+ def actual_gross
14
+ BigDecimal.new((@transaction.gross.to_f.abs.to_i) * 100)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'money'
2
+
3
+ module Bacardi
4
+ class ProductAmount
5
+ def initialize(notification, payment)
6
+ @notification = notification
7
+ @payment = payment
8
+ end
9
+
10
+ def correct?
11
+ actual_gross = @payment.actual_gross
12
+ actual_currency = @payment.actual_currency
13
+ paid_gross = @notification.paid_gross
14
+ paid_currency = @notification.paid_currency
15
+
16
+ actual = ::Money.new(actual_gross, actual_currency)
17
+ paid = ::Money.new(paid_gross, paid_currency)
18
+ actual == paid
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ module Bacardi
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bacardi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Bala Paranj
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: money
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.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.3'
69
+ description: This gem checks for spoofed receiver email and fraudulent change in amount
70
+ for the purchased product.
71
+ email:
72
+ - bparanj@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bacardi.gemspec
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/bacardi.rb
88
+ - lib/bacardi/fraud_check.rb
89
+ - lib/bacardi/notification.rb
90
+ - lib/bacardi/payment.rb
91
+ - lib/bacardi/product_amount.rb
92
+ - lib/bacardi/version.rb
93
+ homepage: http://www.rubyplus.com
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Fraud checks for IPN Payment notification.
117
+ test_files: []