shieldpay 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fe82161ac48419d43efafb27812d300e4878108abcb32d6fdf9ba086a3c1227
4
+ data.tar.gz: '08f25acb87847ae5fba863d74d7314af39f89c2905490048923b5007e9ce749f'
5
+ SHA512:
6
+ metadata.gz: 80aaa070ea5e71266e95d6a03e8dc12f27bf8a0f8f7a90ba5ba741a1232703014196c5cd72cde0e0d361ddc655261757c4806244e53fa367262d3cdd1ab5a3a2
7
+ data.tar.gz: 4ec5b19267b505b7ca16235368868f303b0550020734039f8bb313a0684ae2c9e7c834a96b61f01a232e8e7e940d2b12af69783b39653e35858c36976a92a5a2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ .yardoc
3
+ Gemfile.lock
4
+ _yardoc/
5
+ coverage/
6
+ doc/
7
+ pkg/
8
+ spec/reports/
9
+ tmp/
10
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shieldpay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Chris O'Sullivan
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.
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # ShieldPay Ruby gem
2
+ <img src="https://apiuat.shieldpay.com/images/img-shieldpay-logo-color.svg" width="300">
3
+
4
+ Connect to the [ShieldPay api](https://www.shieldpay.com) with this gem.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'shieldpay'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install shieldpay
21
+
22
+ ## Usage
23
+
24
+ ### Configuration
25
+ In order to use the ShieldPay api you need to get an organization key from https://www.shieldpay.com.
26
+
27
+ #### Configuration options
28
+ Setting|Description|Optional
29
+ -------|-----------|--------
30
+ org_key|This is the organization key you need to use the ShieldPay api|No
31
+ country_code|2 character country code that is the default for your payments|Yes
32
+ debug|Turn debug mode on to see extra messages in your api calls|Yes
33
+ default_currency|If you don't set a currency code in your api calls then this is used|Yes
34
+ endpoint_url|The endpoint url used for the api. You can change this if you want to use the test version of the API. Defaults to https://api.shieldpay.com|Yes
35
+
36
+ #### Sample configuration
37
+ ```Ruby
38
+ ShieldPay.configure do |config|
39
+ config.country_code = "GB"
40
+ config.default_currency = "GBP"
41
+ config.org_key = 'XXXYYYZZZ' # this is a pretend org key
42
+ end
43
+ ```
44
+ ### ShieldPay::Customer
45
+ Create a customer using ShieldPay::Customer.create e.g.
46
+
47
+ ```ruby
48
+ customer = ShieldPay::Customer.create(display_name: "Dave Bananas",
49
+ email: "dave@bananas.com",
50
+ mobile_no: "555 12345")
51
+ #=> creates a customer in the ShieldPay database - returning the customer_key
52
+ ```
53
+
54
+ #### ShieldPay::Customer attributes
55
+ Name|Description
56
+ ----|-----------
57
+ `display_name`|The customer's name
58
+ `email`|Their email
59
+ `mobile_no`|...and their mobile
60
+ `customer_key`|After creating the customer, a customer key is generated that should be stored in your database for working with ShieldPay.
61
+
62
+ ### ShieldPay::Company
63
+ Create a company to be a ShieldPay user if you know the company's identifier for your region.
64
+ ```ruby
65
+ customer_key = ShieldPay::Company.create(country_code: "GB",
66
+ email: "dave@bananas.com",
67
+ phone: "555 12345",
68
+ identifier: "ABC123")
69
+ #=> creates a company in the ShieldPay database - returning the customer_key
70
+ ```
71
+ #### ShieldPay::Company attributes
72
+ Name|Description
73
+ ----|-----------
74
+ country_code|The country code for this organization (i.e. GB) Defaults to ShieldPay.configuration.country_code
75
+ email|Email address for contact person
76
+ identifier|Company number for your region (i.e. Companies House Number)
77
+ phone|Contact phone number for company
78
+ customer_key|After creating the company a customer key is generated that should be stored in your database for working with ShieldPay.
79
+
80
+ ### ShieldPay::PaymentRequest
81
+ Used for requesting payment from the supplier to the buyer.
82
+ ```ruby
83
+ payment_request = ShieldPay::PaymentRequest.create_with_email(from_email: "supplier@bananas.com",
84
+ request_from: "Banana Farms Inc.",
85
+ amount: 100.45,
86
+ currency_code: "GBP",
87
+ description: "20 boxes of bananas",
88
+ to_email: "dave@bananafans.com",
89
+ fee_receiver_amount: 15.50,
90
+ fee_receiver_email: "bill@thebananashop.com")
91
+ #=> payment_request now has a payment_request_key to keep track of how the payment request is going.
92
+ ```
93
+
94
+ ### ShieldPay::Webhook
95
+
96
+ Used for adding webhook urls for various events.
97
+ ```ruby
98
+ ShieldPay::WebHook.add(url: "https://www.yoursite.com/shieldpay_callback",
99
+ events: [:initiated, :funds_available])
100
+ ```
101
+
102
+ You can get a list of all the current setup webhooks with `.all`.
103
+ ```ruby
104
+ ShieldPay::WebHook.all
105
+ #=> this returns a list of webhook objects complete with url, events and id
106
+ ```
107
+
108
+ If you want to remove a webhook, use the delete command with the id you returned from the `.all` command.
109
+ ```ruby
110
+ ShieldPay::Webhook.delete("zzzzz-zzzzzzz-zzzzzzz-zzzzzz")
111
+ ```
112
+
113
+ Here's a list of the events you can add webhooks for:
114
+ ```
115
+ initiated
116
+ add_fund
117
+ accepted
118
+ sender_complete
119
+ receiver_complete
120
+ funds_available
121
+ receiver_decline_before_accept
122
+ sender_cancelled_before_funded
123
+ payment_generated
124
+ funding_pending
125
+ sender_cancelled_after_funded
126
+ refund_in_progress
127
+ customer_status
128
+ ```
129
+
130
+
131
+ ## Development
132
+
133
+ 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.
134
+
135
+ 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).
136
+
137
+
138
+ ## Contributing
139
+
140
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thechrisoshow/shieldpay.
141
+
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shieldpay"
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
data/bin/setup ADDED
@@ -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
data/lib/shieldpay.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "shieldpay/helpers"
2
+ require "shieldpay/configuration"
3
+ require "shieldpay/errors"
4
+ require "shieldpay/request"
5
+ require "shieldpay/version"
6
+
7
+ require "shieldpay/bank_detail"
8
+ require "shieldpay/company"
9
+ require "shieldpay/customer"
10
+ require "shieldpay/payment_request"
11
+ require "shieldpay/webhook"
12
+
13
+ module ShieldPay
14
+ class << self
15
+ attr_writer :configuration
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def self.reset
23
+ @configuration = Configuration.new
24
+ end
25
+
26
+ def self.configure
27
+ yield(configuration)
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module ShieldPay
2
+ class BankDetail
3
+ extend Helpers
4
+
5
+ # Bank Detail Params
6
+ # Parameter Optional? Description
7
+ # account_holder_name no Name of the bank account holder
8
+ # bank_account_number no Bank account number
9
+ # customer_key no ShieldPay ID for this customer
10
+ # currency_code no Currently GBP, EUR, USD or SGD
11
+ # routing_number no Sort code or routing number
12
+ # iban yes IBAN (if this isn't set, it defaults to the bank account number)
13
+ def self.update(params={})
14
+ stringify_keys!(params)
15
+ if !params["iban"] || params["iban"].size == 0
16
+ params["iban"] = params["bank_account_number"]
17
+ end
18
+ response = Request.new.post("/BankDetail/AddBankDetail", params)
19
+ response.dig("Data", "Result", "IsSuccess")
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ module ShieldPay
2
+ class Company
3
+ extend Helpers
4
+
5
+ attr_accessor :address, :country_code, :customer_key, :created_on, :email,
6
+ :identifier, :locality, :name, :phone, :post_code,
7
+ :kyc_status
8
+
9
+
10
+ # Contact Params
11
+ # Parameter Optional? Description
12
+ # country_code no The country code for this organization (i.e. GB) Defaults to ShieldPay.configuration.country_code
13
+ # email no Email address for contact person
14
+ # identifier no Company number for your region (i.e. Companies House Number)
15
+ # phone no Contact phone number for company
16
+ def self.create(params={})
17
+ stringify_keys!(params)
18
+ params["country_code"] ||= ShieldPay.configuration.country_code
19
+ response = Request.new.post("/Customer/CreateCompany", params)
20
+
21
+ customer_key = response.dig("Data", "CustomerKey")
22
+ kyc_status = nil
23
+ if customer_key.is_a?(Hash)
24
+ kyc_status = customer_key["KYCStatus"]
25
+ customer_key = customer_key["CustomerKey"]
26
+ end
27
+ new(response["Data"]["Data"]).tap do |c|
28
+ c.country_code = params["country_code"]
29
+ c.customer_key = customer_key
30
+ c.identifier = params["identifier"]
31
+ c.kyc_status = kyc_status
32
+ c.phone = params["phone"]
33
+ end
34
+ end
35
+
36
+ def initialize(attrs)
37
+ @address = attrs["Address"]
38
+ @created_on = Time.parse(attrs["CreatedOn"])
39
+ @email = attrs["Email"]
40
+ @locality = attrs["Locality"]
41
+ @name = attrs["CompanyName"]
42
+ @post_code = attrs["PostalCode"]
43
+ end
44
+
45
+ def kyc_verified?
46
+ @kyc_status
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ module ShieldPay
2
+ class Configuration
3
+ attr_accessor :country_code
4
+ attr_accessor :debug
5
+ attr_accessor :default_currency
6
+ attr_accessor :endpoint_url
7
+ attr_accessor :org_key
8
+
9
+ def initialize
10
+ @org_key = nil
11
+ @country_code = nil
12
+ @debug = nil
13
+ @default_currency = nil
14
+ @endpoint_url = "https://apiuat.shieldpay.com"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ module ShieldPay
2
+ class Customer
3
+ extend Helpers
4
+
5
+ attr_accessor :customer_key, :kyc_verified
6
+
7
+ # Contact Params
8
+ # Parameter Optional? Description
9
+ # display_name no The customer's name
10
+ # email no Email address for contact person
11
+ # mobile_no no This customer's mobile number
12
+ def self.create(params={})
13
+ stringify_keys!(params)
14
+ response = Request.new.post("/Customer/CreateRegisterCustomer", params)
15
+
16
+ customer_key = response["Data"].dig("CustomerKey")
17
+ kyc_verified = response["Data"].dig("KYCStatus") == "Verified"
18
+ new.tap do |c|
19
+ c.customer_key = customer_key
20
+ c.kyc_verified = kyc_verified
21
+ end
22
+ end
23
+
24
+
25
+ # Verification Params
26
+ # Parameter
27
+ # title
28
+ # first_name
29
+ # last_name
30
+ # gender
31
+ # date_of_birth
32
+ # flat_number
33
+ # building_number
34
+ # street
35
+ # state
36
+ # town
37
+ # post_code
38
+ # country
39
+ # customer_key
40
+ def self.kyc_verify(params={})
41
+ stringify_keys!(params)
42
+ if params["customer_key"].strip.empty?
43
+ raise ShieldPay::Errors::RequiredField.new("customer_key field is required to verify this customer. You can create a customer_key field using the Customer.create method")
44
+ end
45
+ params["postcode"] = params.delete("post_code")
46
+ params["gender"] = params.delete("gender").upcase
47
+ response = Request.new.post("/Customer/KYCVerification", params)
48
+ kyc_verified = response["Data"].dig("AddressVerified")
49
+ new.tap do |c|
50
+ c.kyc_verified = kyc_verified
51
+ end
52
+ end
53
+
54
+ def kyc_verified?
55
+ @kyc_verified
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,51 @@
1
+ module ShieldPay
2
+ module Errors
3
+
4
+ # standard errors
5
+ class InvalidOrganizationKey < StandardError; end
6
+ class OrganizationKeyDoesntExist < StandardError; end
7
+ class RequiredField < StandardError; end
8
+
9
+ # company errors
10
+ class CompanyAlreadyExists < StandardError; end
11
+ class InvalidCompanyIdentifier < StandardError; end
12
+
13
+ # customer errors
14
+ class AddressNotVerified < StandardError; end
15
+ class CustomerEmailExists < StandardError; end
16
+ class CustomerDoesntExist < StandardError; end
17
+
18
+ ERROR_MATCHING = {
19
+ "Invalid Organization key." => InvalidOrganizationKey,
20
+ "OrganizationKey is not valid." => InvalidOrganizationKey,
21
+ "OrganizationKey is not exists." => OrganizationKeyDoesntExist,
22
+
23
+ "Company identifier already exist. " \
24
+ "Please contact your system administrator" => CompanyAlreadyExists,
25
+ "Company identifier could not be validated" => InvalidCompanyIdentifier,
26
+
27
+ "Email already exists." => CustomerEmailExists,
28
+ "Customer does not exist" => CustomerDoesntExist,
29
+ "Address not verified." => AddressNotVerified,
30
+ "Address not varified, Exception in Request" => AddressNotVerified,
31
+ }
32
+
33
+ def check_for_error(response_body)
34
+ user_message = response_body['coreRes']['userMessage']
35
+ raise_error(user_message) if has_error?(response_body)
36
+ end
37
+
38
+ private
39
+
40
+ def has_error?(response_body)
41
+ response_body['coreRes']['status'].to_i != 1
42
+ end
43
+
44
+ def raise_error(user_message)
45
+ error_klass = ERROR_MATCHING[user_message] || StandardError
46
+
47
+ raise error_klass.new(user_message)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,15 @@
1
+ module ShieldPay
2
+ module Helpers
3
+ def stringify_keys(hash)
4
+ hash.inject({}) do |hash, (key, value)|
5
+ value = value.stringify_keys if value.is_a?(Hash)
6
+ hash[key.to_s] = value
7
+ hash
8
+ end
9
+ end
10
+
11
+ def stringify_keys!(hash)
12
+ hash.replace(stringify_keys(hash))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module ShieldPay
2
+ class PaymentRequest
3
+ extend Helpers
4
+
5
+ attr_accessor :payment_request_key
6
+
7
+ def self.create_with_email(params={})
8
+ stringify_keys!(params)
9
+ params["batch_reference"] = 0
10
+ params["currency_code"] ||= ShieldPay.configuration.default_currency
11
+ params["target_currency_code"] ||= ShieldPay.configuration.default_currency
12
+
13
+ response = Request.new.post("/Transaction/PaymentRequestByEmailId",
14
+ params)
15
+ payment_request_key = response['Data']
16
+ new.tap {|pr| pr.payment_request_key = payment_request_key }
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,83 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module ShieldPay
5
+
6
+ class Request
7
+
8
+ include HTTParty
9
+ include Errors
10
+
11
+ UPPERCASE_KEYS = ["iban"]
12
+
13
+ def post(path, params)
14
+ url = ShieldPay.configuration.endpoint_url + path
15
+ params = add_auth_key(params)
16
+ attrs = {
17
+ body: processed_params(params),
18
+ headers: headers
19
+ }
20
+ attrs[:debug_output] = $stdout if debug_mode?
21
+ response = HTTParty.post(url, attrs)
22
+ parse_response(response)
23
+ end
24
+
25
+ private
26
+
27
+ def add_auth_key(params)
28
+ params["organization_key"] = ShieldPay.configuration.org_key
29
+ params
30
+ end
31
+
32
+ def debug_mode?
33
+ ShieldPay.configuration.debug
34
+ end
35
+
36
+ def display_debug(response)
37
+ if debug_mode?
38
+ puts "-" * 20 + " DEBUG " + "-" * 20
39
+ puts response
40
+ puts "-" * 18 + " END DEBUG " + "-" * 18
41
+ end
42
+ end
43
+
44
+ def headers
45
+ {
46
+ 'Content-Type' => 'application/json',
47
+ 'Accept' => 'application/json'
48
+ }
49
+ end
50
+
51
+ def parse_response(response)
52
+ as_json = JSON.parse(response.body.to_s)
53
+ check_for_error(as_json)
54
+ display_debug(response.body)
55
+ as_json
56
+ end
57
+
58
+ def processed_keys(keys)
59
+ keys.inject({}) do |result, (key, value)|
60
+ if UPPERCASE_KEYS.include?(key)
61
+ result[key.upcase] = value
62
+ else
63
+ result[underscore_to_camel_case(key)] = value
64
+ end
65
+ result
66
+ end
67
+ end
68
+
69
+ def processed_params(params)
70
+ params = processed_keys(params)
71
+ # set the values to strings
72
+ params.inject({}) do |result, (key, value)|
73
+ result[key] = value.to_s
74
+ result
75
+ end.to_json
76
+ end
77
+
78
+ def underscore_to_camel_case(string)
79
+ string.to_s.split('_').collect(&:capitalize).join
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module ShieldPay
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,97 @@
1
+ module ShieldPay
2
+ class Webhook
3
+ extend Helpers
4
+
5
+ attr_accessor :events, :id, :url
6
+
7
+ EVENT_CODES = {
8
+ initiated: "1", add_fund: "2", accepted: "3", sender_complete: "4",
9
+ receiver_complete: "5", funds_available: "6",
10
+ receiver_decline_before_accept: "7", sender_cancelled_before_funded: "8",
11
+ payment_generated: "9", funding_pending: "10",
12
+ sender_cancelled_after_funded: "11", refund_in_progress: "12",
13
+ customer_status: "13"
14
+ }
15
+
16
+ # Webhook Params
17
+ # Parameter Optional? Description
18
+ # url no The url that shieldpay will call for webhooks
19
+ # events no The events that this webhook will monitor
20
+ # Options are:
21
+ # :initated, :add_fund, :accepted, :sender_complete,
22
+ # :receiver_complete, :funds_available,
23
+ # :receiver_decline_before_accept,
24
+ # :sender_cancelled_before_funded,
25
+ # :payment_generated, :funding_pending,
26
+ # :sender_cancelled_after_funded,
27
+ # :refund_in_progress, :customer_status
28
+ def self.add(input_params={})
29
+ stringify_keys!(input_params)
30
+ url = input_params["url"]
31
+ if url.nil? || url.size == 0
32
+ raise Errors::RequiredField.new("url is a required field")
33
+ end
34
+ events = input_params["events"]
35
+ if events.nil? || events.size == 0
36
+ raise Errors::RequiredField.new("events is a required field")
37
+ end
38
+ params = { "Url" => url }
39
+ params[:webhook_event_binding] = events.collect do |event|
40
+ event_code = EVENT_CODES[event.to_sym]
41
+ if event_code.nil?
42
+ raise Errors::RequiredField.new("#{event} is not a valid event")
43
+ end
44
+ {
45
+ "EventId" => event_code
46
+ }
47
+ end
48
+ response = Request.new.post("/Webhook/Add", params)
49
+ response.dig("coreRes", "userMessage") == "Request successful"
50
+ end
51
+
52
+ # returns all the webhooks registered with ShieldPay
53
+ def self.all
54
+ response = Request.new.post("/Webhook/AllByOrgKey", {})
55
+ response["Data"].collect do |webhook|
56
+ new(webhook["WebhookId"],
57
+ webhook["URL"],
58
+ webhook["WebhookEventBinding"])
59
+ end
60
+ end
61
+
62
+ # takes in the webhook id to delete a webhook
63
+ def self.delete(id)
64
+ params = {
65
+ webhook_id: id
66
+ }
67
+ response = Request.new.post("/Webhook/WebhookDelete", params)
68
+ response["Data"] == "Success"
69
+ end
70
+
71
+ def initialize(id, url, events)
72
+ @id = id
73
+ @url = url
74
+ @events = parse_events(events)
75
+ end
76
+
77
+ private
78
+
79
+ def parse_events(events)
80
+ @events = events.collect do |hsh|
81
+ event_name = hsh["EventName"]
82
+ # remove spaces
83
+ event_name = event_name.tr(" ", "-")
84
+ underscore(event_name).to_sym
85
+ end
86
+ end
87
+
88
+ def underscore(string)
89
+ string.gsub(/::/, '/').
90
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
91
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
92
+ tr("-", "_").
93
+ downcase
94
+ end
95
+
96
+ end
97
+ end
data/shieldpay.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shieldpay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shieldpay"
8
+ spec.version = ShieldPay::VERSION
9
+ spec.authors = ["Chris O'Sullivan"]
10
+ spec.email = ["thechrisoshow@gmail.com"]
11
+ spec.homepage = "https://www.shieldpay.com/"
12
+
13
+ spec.summary = %q{Ruby gem for accessing the ShieldPay API}
14
+ spec.license = "MIT"
15
+
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 "httparty", "~> 0.15"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "byebug"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "webmock", "~> 1.24"
29
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shieldpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris O'Sullivan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.24'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.24'
97
+ description:
98
+ email:
99
+ - thechrisoshow@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/shieldpay.rb
114
+ - lib/shieldpay/bank_detail.rb
115
+ - lib/shieldpay/company.rb
116
+ - lib/shieldpay/configuration.rb
117
+ - lib/shieldpay/customer.rb
118
+ - lib/shieldpay/errors.rb
119
+ - lib/shieldpay/helpers.rb
120
+ - lib/shieldpay/payment_request.rb
121
+ - lib/shieldpay/request.rb
122
+ - lib/shieldpay/version.rb
123
+ - lib/shieldpay/webhook.rb
124
+ - shieldpay.gemspec
125
+ homepage: https://www.shieldpay.com/
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Ruby gem for accessing the ShieldPay API
149
+ test_files: []