shieldpay 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fe82161ac48419d43efafb27812d300e4878108abcb32d6fdf9ba086a3c1227
4
- data.tar.gz: '08f25acb87847ae5fba863d74d7314af39f89c2905490048923b5007e9ce749f'
3
+ metadata.gz: f185dcd40cc56cdd032995190d58019c1e09d6b609a18a26dbe2840e8e3da328
4
+ data.tar.gz: 00e5e9aaea53dee2e7c868722720d10d3f6a482dbabaea9dc2ac74463729bbd8
5
5
  SHA512:
6
- metadata.gz: 80aaa070ea5e71266e95d6a03e8dc12f27bf8a0f8f7a90ba5ba741a1232703014196c5cd72cde0e0d361ddc655261757c4806244e53fa367262d3cdd1ab5a3a2
7
- data.tar.gz: 4ec5b19267b505b7ca16235368868f303b0550020734039f8bb313a0684ae2c9e7c834a96b61f01a232e8e7e940d2b12af69783b39653e35858c36976a92a5a2
6
+ metadata.gz: 67b9c0121cd55d315294825f9a6a69cc8d25540dd9914eeced9c570d8e6ab49448c08e611acff6dff58468e7f928184b1284a9c9c3478a03097868299b5e9aa8
7
+ data.tar.gz: 643e35bba559bd275b8e6b1f285ad64096de89010f08c394adf36871ace6b379ddb7faff867affb293e6473bd3e3d5516657f8efbdd1a305b7aacb266c469ca3
data/README.md CHANGED
@@ -31,7 +31,7 @@ org_key|This is the organization key you need to use the ShieldPay api|No
31
31
  country_code|2 character country code that is the default for your payments|Yes
32
32
  debug|Turn debug mode on to see extra messages in your api calls|Yes
33
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
34
+ uat|Whether you want to access the uat version of the shieldpay api. Defaults to false|Yes
35
35
 
36
36
  #### Sample configuration
37
37
  ```Ruby
@@ -121,6 +121,7 @@ Here's a list of the events you can add webhooks for:
121
121
  receiver_decline_before_accept
122
122
  sender_cancelled_before_funded
123
123
  payment_generated
124
+ payment_completed
124
125
  funding_pending
125
126
  sender_cancelled_after_funded
126
127
  refund_in_progress
data/lib/shieldpay.rb CHANGED
@@ -8,6 +8,7 @@ require "shieldpay/bank_detail"
8
8
  require "shieldpay/company"
9
9
  require "shieldpay/customer"
10
10
  require "shieldpay/payment_request"
11
+ require "shieldpay/transaction"
11
12
  require "shieldpay/webhook"
12
13
 
13
14
  module ShieldPay
@@ -3,15 +3,31 @@ module ShieldPay
3
3
  attr_accessor :country_code
4
4
  attr_accessor :debug
5
5
  attr_accessor :default_currency
6
- attr_accessor :endpoint_url
7
6
  attr_accessor :org_key
7
+ attr_accessor :uat
8
8
 
9
9
  def initialize
10
10
  @org_key = nil
11
11
  @country_code = nil
12
12
  @debug = nil
13
13
  @default_currency = nil
14
- @endpoint_url = "https://apiuat.shieldpay.com"
14
+ @uat = false
15
+ end
16
+
17
+ def api_endpoint_url
18
+ if @uat
19
+ "https://apiuat.shieldpay.com"
20
+ else
21
+ "https://api.shieldpay.com"
22
+ end
23
+ end
24
+
25
+ def endpoint_url
26
+ if @uat
27
+ "https://uat.shieldpay.com"
28
+ else
29
+ "https://www.shieldpay.com"
30
+ end
15
31
  end
16
32
  end
17
33
  end
@@ -2,7 +2,8 @@ module ShieldPay
2
2
  class Customer
3
3
  extend Helpers
4
4
 
5
- attr_accessor :customer_key, :kyc_verified
5
+ attr_accessor :customer_key, :kyc_verified, :display_name, :email,
6
+ :mobile_no
6
7
 
7
8
  # Contact Params
8
9
  # Parameter Optional? Description
@@ -18,6 +19,9 @@ module ShieldPay
18
19
  new.tap do |c|
19
20
  c.customer_key = customer_key
20
21
  c.kyc_verified = kyc_verified
22
+ c.display_name = params["display_name"]
23
+ c.email = params["email"]
24
+ c.mobile_no = params["mobile_no"]
21
25
  end
22
26
  end
23
27
 
@@ -34,7 +38,7 @@ module ShieldPay
34
38
  # street
35
39
  # state
36
40
  # town
37
- # post_code
41
+ # postcode
38
42
  # country
39
43
  # customer_key
40
44
  def self.kyc_verify(params={})
@@ -42,8 +46,8 @@ module ShieldPay
42
46
  if params["customer_key"].strip.empty?
43
47
  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
48
  end
45
- params["postcode"] = params.delete("post_code")
46
- params["gender"] = params.delete("gender").upcase
49
+ params["gender"] = params.delete("gender").to_s.upcase
50
+ params["date_of_birth"] = Date.parse(params["date_of_birth"].to_s).to_s
47
51
  response = Request.new.post("/Customer/KYCVerification", params)
48
52
  kyc_verified = response["Data"].dig("AddressVerified")
49
53
  new.tap do |c|
@@ -1,6 +1,8 @@
1
1
  module ShieldPay
2
2
  module Errors
3
3
 
4
+ class OtherShieldPayError < StandardError; end
5
+
4
6
  # standard errors
5
7
  class InvalidOrganizationKey < StandardError; end
6
8
  class OrganizationKeyDoesntExist < StandardError; end
@@ -14,20 +16,22 @@ module ShieldPay
14
16
  class AddressNotVerified < StandardError; end
15
17
  class CustomerEmailExists < StandardError; end
16
18
  class CustomerDoesntExist < StandardError; end
19
+ class CustomerMobileExists < StandardError; end
17
20
 
18
21
  ERROR_MATCHING = {
19
22
  "Invalid Organization key." => InvalidOrganizationKey,
20
23
  "OrganizationKey is not valid." => InvalidOrganizationKey,
21
24
  "OrganizationKey is not exists." => OrganizationKeyDoesntExist,
22
25
 
23
- "Company identifier already exist. " \
24
- "Please contact your system administrator" => CompanyAlreadyExists,
26
+ "Company identifier already exists." => CompanyAlreadyExists,
25
27
  "Company identifier could not be validated" => InvalidCompanyIdentifier,
26
28
 
27
29
  "Email already exists." => CustomerEmailExists,
28
30
  "Customer does not exist" => CustomerDoesntExist,
29
31
  "Address not verified." => AddressNotVerified,
30
32
  "Address not varified, Exception in Request" => AddressNotVerified,
33
+
34
+ "This mobile number is already registered." => CustomerMobileExists
31
35
  }
32
36
 
33
37
  def check_for_error(response_body)
@@ -42,7 +46,7 @@ module ShieldPay
42
46
  end
43
47
 
44
48
  def raise_error(user_message)
45
- error_klass = ERROR_MATCHING[user_message] || StandardError
49
+ error_klass = ERROR_MATCHING[user_message] || OtherShieldPayError
46
50
 
47
51
  raise error_klass.new(user_message)
48
52
  end
@@ -6,9 +6,11 @@ module ShieldPay
6
6
 
7
7
  def self.create_with_email(params={})
8
8
  stringify_keys!(params)
9
- params["batch_reference"] = 0
9
+ params["batch_reference"] = "0"
10
10
  params["currency_code"] ||= ShieldPay.configuration.default_currency
11
11
  params["target_currency_code"] ||= ShieldPay.configuration.default_currency
12
+ params["amount"] = params["amount"].to_s # must be a string for some reason
13
+ params["fee_receiver_amount"] = params["fee_receiver_amount"].to_s # must be a string for some reason
12
14
 
13
15
  response = Request.new.post("/Transaction/PaymentRequestByEmailId",
14
16
  params)
@@ -11,7 +11,7 @@ module ShieldPay
11
11
  UPPERCASE_KEYS = ["iban"]
12
12
 
13
13
  def post(path, params)
14
- url = ShieldPay.configuration.endpoint_url + path
14
+ url = ShieldPay.configuration.api_endpoint_url + path
15
15
  params = add_auth_key(params)
16
16
  attrs = {
17
17
  body: processed_params(params),
@@ -67,12 +67,7 @@ module ShieldPay
67
67
  end
68
68
 
69
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
70
+ processed_keys(params).to_json
76
71
  end
77
72
 
78
73
  def underscore_to_camel_case(string)
@@ -0,0 +1,33 @@
1
+ module ShieldPay
2
+ class Transaction
3
+ extend Helpers
4
+
5
+ attr_accessor :status_id
6
+
7
+
8
+ # Webhook Params
9
+ # Parameter Optional? Description
10
+ # customer_id no The customer id of either the sender or the
11
+ # receiver of this transaction
12
+ # transaction_id no The transaction id to look up
13
+ def self.get_status(input_params={})
14
+ stringify_keys!(input_params)
15
+ response = Request.new.post("/Transaction/GetPaymentStatus", input_params)
16
+ response.dig("Data", "StatusId")
17
+ end
18
+
19
+ # Webhook Params
20
+ # Parameter Optional? Description
21
+ # customer_id no The customer id of either the sender or the
22
+ # receiver of this transaction
23
+ # transaction_id no The transaction id to change status
24
+ # status_id no The status to change to
25
+ def self.change_status(input_params)
26
+ stringify_keys!(input_params)
27
+ input_params["transaction_status_id"] = input_params.delete("status_id")
28
+ response = Request.new.post("/Transaction/ChangePaymentStatus",
29
+ input_params)
30
+ response.dig("coreRes", "status") == 1
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module ShieldPay
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -5,24 +5,26 @@ module ShieldPay
5
5
  attr_accessor :events, :id, :url
6
6
 
7
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"
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', payment_completed: '10', funding_pending: '11',
12
+ sender_cancelled_after_funded: '12', refund_in_progress: '13',
13
+ customer_status: '14'
14
14
  }
15
15
 
16
16
  # Webhook Params
17
17
  # Parameter Optional? Description
18
18
  # url no The url that shieldpay will call for webhooks
19
19
  # events no The events that this webhook will monitor
20
+ # (defaults to all events)
20
21
  # Options are:
21
22
  # :initated, :add_fund, :accepted, :sender_complete,
22
23
  # :receiver_complete, :funds_available,
23
24
  # :receiver_decline_before_accept,
24
25
  # :sender_cancelled_before_funded,
25
- # :payment_generated, :funding_pending,
26
+ # :payment_generated, :payment_completed,
27
+ # :funding_pending,
26
28
  # :sender_cancelled_after_funded,
27
29
  # :refund_in_progress, :customer_status
28
30
  def self.add(input_params={})
@@ -31,20 +33,25 @@ module ShieldPay
31
33
  if url.nil? || url.size == 0
32
34
  raise Errors::RequiredField.new("url is a required field")
33
35
  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
36
  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")
37
+ events = input_params["events"]
38
+ event_codes = if events.nil? || events.size == 0
39
+ EVENT_CODES.values
40
+ else
41
+ events.collect do |event|
42
+ event_code = EVENT_CODES[event.to_sym]
43
+ if event_code.nil?
44
+ raise Errors::RequiredField.new("#{event} is not a valid event")
45
+ end
46
+ event_code
43
47
  end
44
- {
45
- "EventId" => event_code
46
- }
47
48
  end
49
+
50
+
51
+ params[:webhook_event_binding] = event_codes.collect do |event_code|
52
+ { "EventId" => event_code }
53
+ end
54
+
48
55
  response = Request.new.post("/Webhook/Add", params)
49
56
  response.dig("coreRes", "userMessage") == "Request successful"
50
57
  end
@@ -68,6 +75,10 @@ module ShieldPay
68
75
  response["Data"] == "Success"
69
76
  end
70
77
 
78
+ def self.event_name_from_id(event_id)
79
+ EVENT_CODES.key(event_id.to_s)
80
+ end
81
+
71
82
  def initialize(id, url, events)
72
83
  @id = id
73
84
  @url = url
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shieldpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris O'Sullivan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-16 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -119,6 +119,7 @@ files:
119
119
  - lib/shieldpay/helpers.rb
120
120
  - lib/shieldpay/payment_request.rb
121
121
  - lib/shieldpay/request.rb
122
+ - lib/shieldpay/transaction.rb
122
123
  - lib/shieldpay/version.rb
123
124
  - lib/shieldpay/webhook.rb
124
125
  - shieldpay.gemspec