root_insurance 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +1,74 @@
1
- module RootInsurance::Api
2
- module Payment
1
+ module RootInsurance
2
+ module Api
3
+ module Payment
3
4
 
4
- # Create a payment method
5
- #
6
- # @param [String] policyholder_id The unique identifier of the policy holder.
7
- # @param [String] type The payment method type. Curently only +'debit_order'+ is supported. If omitted, defaults to +'debit_order'+ (optional)
8
- # @param [Hash] bank_details Bank details to use for the debit order. See below for details.
9
- # @param [String] policy_ids The date on the which the incident occured. (optional)
10
- # @return [Hash]
11
- #
12
- ## == Bank details
13
- # [account_holder (string)] Name of account holder.
14
- # [bank (string)] Bank name - one of [+absa+, +capitec+, +fnb+, +investec+, +nedbank+, +postbank+, +standard_bank+]
15
- # [branch_code (string)] Branch code for bank account
16
- # [account_number (string)] Bank account number
17
- #
18
- # @example
19
- # bank_details = {
20
- # first_name: "Erlich",
21
- # last_name: "Bachman",
22
- # bank: "absa",
23
- # branch_code: "12345",
24
- # account_number: "123456789"
25
- # }
26
- # client.create_payment_method(
27
- # policyholder_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
28
- # bank_details: bank_details)
29
- #
30
- def create_payment_method(policyholder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil)
31
- validate_bank_details(bank_details)
5
+ # Create a payment method
6
+ #
7
+ # @param [String] policyholder_id The unique identifier of the policy holder.
8
+ # @param [String] type The payment method type. Curently only +'debit_order'+ is supported. If omitted, defaults to +'debit_order'+ (optional)
9
+ # @param [Hash] bank_details Bank details to use for the debit order. See below for details.
10
+ # @param [String] policy_ids The date on the which the incident occured. (optional)
11
+ # @return [Hash]
12
+ #
13
+ ## == Bank details
14
+ # [account_holder (string)] Name of account holder.
15
+ # [bank (string)] Bank name - one of [+absa+, +capitec+, +fnb+, +investec+, +nedbank+, +postbank+, +standard_bank+]
16
+ # [branch_code (string)] Branch code for bank account
17
+ # [account_number (string)] Bank account number
18
+ #
19
+ # @example
20
+ # bank_details = {
21
+ # first_name: "Erlich",
22
+ # last_name: "Bachman",
23
+ # bank: "absa",
24
+ # branch_code: "12345",
25
+ # account_number: "123456789"
26
+ # }
27
+ # client.create_payment_method(
28
+ # policyholder_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
29
+ # bank_details: bank_details)
30
+ #
31
+ def create_payment_method(policyholder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil)
32
+ validate_bank_details(bank_details)
32
33
 
33
- data = {
34
- type: type,
35
- bank_details: bank_details
36
- }
34
+ data = {
35
+ type: type,
36
+ bank_details: bank_details
37
+ }
37
38
 
38
- if policy_ids && policy_ids.is_a?(Array)
39
- data.merge!(policy_ids: policy_ids)
40
- elsif policy_ids && policy_ids.is_a?(String)
41
- data.merge!(policy_ids: [policy_ids])
42
- end
39
+ if policy_ids && policy_ids.is_a?(Array)
40
+ data.merge!(policy_ids: policy_ids)
41
+ elsif policy_ids && policy_ids.is_a?(String)
42
+ data.merge!(policy_ids: [policy_ids])
43
+ end
43
44
 
44
- post("policyholders/#{policyholder_id}/payment-methods", data)
45
- end
45
+ post("policyholders/#{policyholder_id}/payment-methods", data)
46
+ end
46
47
 
47
- # Link a payment method to a policy
48
- #
49
- # @param [String] policy_id The unique identifier of the policy.
50
- # @param [String] payment_method_id The unique identifier of the payment method.
51
- #
52
- # @example
53
- # client.link_payment_method(
54
- # policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
55
- # payment_method_id: "e0b7b222-772f-47ac-b08d-c7ba38aa1b25")
56
- #
57
- def link_payment_method(policy_id:, payment_method_id:)
58
- data = {payment_method_id: payment_method_id}
48
+ # Link a payment method to a policy
49
+ #
50
+ # @param [String] policy_id The unique identifier of the policy.
51
+ # @param [String] payment_method_id The unique identifier of the payment method.
52
+ #
53
+ # @example
54
+ # client.link_payment_method(
55
+ # policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
56
+ # payment_method_id: "e0b7b222-772f-47ac-b08d-c7ba38aa1b25")
57
+ #
58
+ def link_payment_method(policy_id:, payment_method_id:)
59
+ data = {payment_method_id: payment_method_id}
59
60
 
60
- put("policies/#{policy_id}/payment-method", data)
61
- end
61
+ put("policies/#{policy_id}/payment-method", data)
62
+ end
62
63
 
63
- private
64
- def validate_bank_details(bank_details)
65
- [:first_name, :last_name, :bank, :branch_code, :account_number].each do |key|
66
- if !(bank_details[key] || bank_details[key.to_sym])
67
- raise ArgumentError.new("Bank details need to include #{key}")
64
+ private
65
+ def validate_bank_details(bank_details)
66
+ [:first_name, :last_name, :bank, :branch_code, :account_number].each do |key|
67
+ if !(bank_details[key] || bank_details[key.to_sym])
68
+ raise ArgumentError.new("Bank details need to include #{key}")
69
+ end
68
70
  end
69
71
  end
70
72
  end
71
73
  end
72
- end
74
+ end
@@ -1,163 +1,165 @@
1
- module RootInsurance::Api
2
- module Policy
3
-
4
- # Issue a policy
5
- #
6
- # @param [String] application_id The unique identifier of the application.
7
- # @param [Hash, nil] app_data An object containing additional custom data for the policy.
8
- # @return [Hash]
9
- #
10
- # @example
11
- # client.issue_policy(
12
- # application_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
13
- # app_data: {gadget_colour: "Space Grey"})
14
- #
15
- def issue_policy(application_id:, app_data: nil)
16
- data = {
17
- application_id: application_id,
18
- }
19
-
20
- data.merge!(app_data: app_data) if app_data
21
-
22
- post(:policies, data)
23
- end
24
-
25
- # Add a benificiary to a policy
26
- #
27
- # @param [String] policy_id The unique identifier of the policy.
28
- # @param [String] first_name The beneficiary's first name
29
- # @param [String] last_name The beneficiary's last name
30
- # @param [Hash] id An hash containing the beneficiary's identification number, type and country. See below.
31
- # @param [Integer] percentage An integer representing the percentage of a claim payout that the beneficiary should receive.
32
- # @param [String] cellphone Hash containing beneficiary's cellphone number and country. See below for details. (optional)
33
- # @return [Hash]
34
- #
35
- ## == ID
36
- # [type (string or symbol)] Either +:id+ or +:passport+
37
- # [number (string)] The id or passport number
38
- # [country (string)] The ISO Alpha-2 country code of the country of the id/passport number.
39
- #
40
- ## == Cellphone
41
- # [number (string)] The cellphone number
42
- # [country (string)] The ISO Alpha-2 country code of the country of the cellphone number.
43
- #
44
- # @example
45
- # client.add_policy_beneficiary(
46
- # policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
47
- # first_name: "Jared"
48
- # last_name: "Dunn",
49
- # id: {type: :id, number: "8704094800082", country: "ZA"},
50
- # percentage: 100)
51
- #
52
- def add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:, cellphone: nil)
53
- raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash
54
-
55
- data = {
56
- id: id,
57
- first_name: first_name,
58
- last_name: last_name,
59
- percentage: percentage,
60
- cellphone: cellphone
61
- }.reject { |k, v| v.nil? }
62
-
63
- put("policies/#{policy_id}/beneficiaries", data)
64
- end
65
-
66
- # List policies
67
- #
68
- # @param [String] id_number The National ID Number of the policyholder (optional)
69
- # @return [Array<Hash>]
70
- #
71
- # @example
72
- # client.list_policies(id_number: "8704094800082")
73
- #
74
- def list_policies(id_number: nil)
75
- query = id_number ? {id_number: id_number} : nil
76
-
77
- get(:policies, query)
78
- end
79
-
80
- # Get a policy
81
- #
82
- # @param [String] id The unique identifier of the policy
83
- # @return [Hash]
84
- #
85
- # @example
86
- # client.get_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
87
- #
88
- def get_policy(id:)
89
- get("policies/#{id}")
90
- end
91
-
92
- # Cancel a policy
93
- #
94
- # @param [String] id The unique identifier of the policy
95
- # @param [String] reason A reason for why this policy is being cancelled.
96
- # @return [Hash]
97
- #
98
- # @example
99
- # client.cancel_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", reason: "Not needed anymore")
100
- #
101
- def cancel_policy(id:, reason:)
102
- data = {reason: reason}
103
-
104
- post("policies/#{id}/cancel", data)
105
- end
106
-
107
- # Update a policy.
108
- # Currently, only updating the app_data object is supported
109
- #
110
- # @param [String] id The unique identifier of the policy
111
- # @param [Hash] app_data An object containing additional custom data for the policy.
112
- # @return [Hash]
113
- #
114
- # @example
115
- # app_data = {gadget_color: "Space Grey", has_screen_cover: true}
116
- # client.update_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", app_data: app_data)
117
- #
118
- def update_policy(id:, app_data:)
119
- data = {app_data: app_data}
120
-
121
- patch("policies/#{id}", data)
122
- end
123
-
124
- # Update a policy's billing amount.
125
- #
126
- # @param [String] id The unique identifier of the policy
127
- # @param [Integer] billing_amount The billing amount to be set on the policy in cents.
128
- # @return [Hash]
129
- #
130
- # @example
131
- # client.update_policy_billing_amount(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", billing_amount: 45000)
132
- #
133
- def update_policy_billing_amount(id:, billing_amount:)
134
- data = {billing_amount: billing_amount}
135
-
136
- post("policies/#{id}/billing_amount", data)
137
- end
138
-
139
- # List a policy's bebeficiaries
140
- #
141
- # @param [String] id The unique identifier of the policy
142
- # @return [Array<Hash>]
143
- #
144
- # @example
145
- # client.list_policy_beneficiaries(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
146
- #
147
- def list_policy_beneficiaries(id:)
148
- get("policies/#{id}/beneficiaries")
149
- end
150
-
151
- # List all the events which are applicable to this policy.
152
- #
153
- # @param [String] id The unique identifier of the policy
154
- # @return [Array<Hash>]
155
- #
156
- # @example
157
- # client.list_policy_events(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
158
- #
159
- def list_policy_events(id:)
160
- get("policies/#{id}/events")
1
+ module RootInsurance
2
+ module Api
3
+ module Policy
4
+
5
+ # Issue a policy
6
+ #
7
+ # @param [String] application_id The unique identifier of the application.
8
+ # @param [Hash, nil] app_data An object containing additional custom data for the policy.
9
+ # @return [Hash]
10
+ #
11
+ # @example
12
+ # client.issue_policy(
13
+ # application_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
14
+ # app_data: {gadget_colour: "Space Grey"})
15
+ #
16
+ def issue_policy(application_id:, app_data: nil)
17
+ data = {
18
+ application_id: application_id,
19
+ }
20
+
21
+ data.merge!(app_data: app_data) if app_data
22
+
23
+ post(:policies, data)
24
+ end
25
+
26
+ # Add a benificiary to a policy
27
+ #
28
+ # @param [String] policy_id The unique identifier of the policy.
29
+ # @param [String] first_name The beneficiary's first name
30
+ # @param [String] last_name The beneficiary's last name
31
+ # @param [Hash] id An hash containing the beneficiary's identification number, type and country. See below.
32
+ # @param [Integer] percentage An integer representing the percentage of a claim payout that the beneficiary should receive.
33
+ # @param [String] cellphone Hash containing beneficiary's cellphone number and country. See below for details. (optional)
34
+ # @return [Hash]
35
+ #
36
+ ## == ID
37
+ # [type (string or symbol)] Either +:id+ or +:passport+
38
+ # [number (string)] The id or passport number
39
+ # [country (string)] The ISO Alpha-2 country code of the country of the id/passport number.
40
+ #
41
+ ## == Cellphone
42
+ # [number (string)] The cellphone number
43
+ # [country (string)] The ISO Alpha-2 country code of the country of the cellphone number.
44
+ #
45
+ # @example
46
+ # client.add_policy_beneficiary(
47
+ # policy_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
48
+ # first_name: "Jared"
49
+ # last_name: "Dunn",
50
+ # id: {type: :id, number: "8704094800082", country: "ZA"},
51
+ # percentage: 100)
52
+ #
53
+ def add_policy_beneficiary(policy_id:, id:, first_name:, last_name:, percentage:, cellphone: nil)
54
+ raise ArgumentError.new('id needs to be a hash') unless id.is_a? Hash
55
+
56
+ data = {
57
+ id: id,
58
+ first_name: first_name,
59
+ last_name: last_name,
60
+ percentage: percentage,
61
+ cellphone: cellphone
62
+ }.reject { |k, v| v.nil? }
63
+
64
+ put("policies/#{policy_id}/beneficiaries", data)
65
+ end
66
+
67
+ # List policies
68
+ #
69
+ # @param [String] id_number The National ID Number of the policyholder (optional)
70
+ # @return [Array<Hash>]
71
+ #
72
+ # @example
73
+ # client.list_policies(id_number: "8704094800082")
74
+ #
75
+ def list_policies(id_number: nil)
76
+ query = id_number ? {id_number: id_number} : nil
77
+
78
+ get(:policies, query)
79
+ end
80
+
81
+ # Get a policy
82
+ #
83
+ # @param [String] id The unique identifier of the policy
84
+ # @return [Hash]
85
+ #
86
+ # @example
87
+ # client.get_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
88
+ #
89
+ def get_policy(id:)
90
+ get("policies/#{id}")
91
+ end
92
+
93
+ # Cancel a policy
94
+ #
95
+ # @param [String] id The unique identifier of the policy
96
+ # @param [String] reason A reason for why this policy is being cancelled.
97
+ # @return [Hash]
98
+ #
99
+ # @example
100
+ # client.cancel_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", reason: "Not needed anymore")
101
+ #
102
+ def cancel_policy(id:, reason:)
103
+ data = {reason: reason}
104
+
105
+ post("policies/#{id}/cancel", data)
106
+ end
107
+
108
+ # Update a policy.
109
+ # Currently, only updating the app_data object is supported
110
+ #
111
+ # @param [String] id The unique identifier of the policy
112
+ # @param [Hash] app_data An object containing additional custom data for the policy.
113
+ # @return [Hash]
114
+ #
115
+ # @example
116
+ # app_data = {gadget_color: "Space Grey", has_screen_cover: true}
117
+ # client.update_policy(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", app_data: app_data)
118
+ #
119
+ def update_policy(id:, app_data:)
120
+ data = {app_data: app_data}
121
+
122
+ patch("policies/#{id}", data)
123
+ end
124
+
125
+ # Update a policy's billing amount.
126
+ #
127
+ # @param [String] id The unique identifier of the policy
128
+ # @param [Integer] billing_amount The billing amount to be set on the policy in cents.
129
+ # @return [Hash]
130
+ #
131
+ # @example
132
+ # client.update_policy_billing_amount(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e", billing_amount: 45000)
133
+ #
134
+ def update_policy_billing_amount(id:, billing_amount:)
135
+ data = {billing_amount: billing_amount}
136
+
137
+ post("policies/#{id}/billing_amount", data)
138
+ end
139
+
140
+ # List a policy's bebeficiaries
141
+ #
142
+ # @param [String] id The unique identifier of the policy
143
+ # @return [Array<Hash>]
144
+ #
145
+ # @example
146
+ # client.list_policy_beneficiaries(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
147
+ #
148
+ def list_policy_beneficiaries(id:)
149
+ get("policies/#{id}/beneficiaries")
150
+ end
151
+
152
+ # List all the events which are applicable to this policy.
153
+ #
154
+ # @param [String] id The unique identifier of the policy
155
+ # @return [Array<Hash>]
156
+ #
157
+ # @example
158
+ # client.list_policy_events(id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e")
159
+ #
160
+ def list_policy_events(id:)
161
+ get("policies/#{id}/events")
162
+ end
161
163
  end
162
164
  end
163
- end
165
+ end