Class: SynapsePayRest::BaseDocument
- Inherits:
-
Object
- Object
- SynapsePayRest::BaseDocument
- Defined in:
- lib/synapse_pay_rest/models/user/base_document.rb
Overview
Stores info on the base document portion (personal/business info) of the CIP document and also manages physical/social/virtual documents.
Instance Attribute Summary collapse
-
#address_city ⇒ Object
Returns the value of attribute address_city.
-
#address_country_code ⇒ Object
Returns the value of attribute address_country_code.
-
#address_postal_code ⇒ Object
Returns the value of attribute address_postal_code.
-
#address_street ⇒ Object
Returns the value of attribute address_street.
-
#address_subdivision ⇒ Object
Returns the value of attribute address_subdivision.
-
#aka ⇒ Object
Returns the value of attribute aka.
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#birth_day ⇒ Object
Returns the value of attribute birth_day.
-
#birth_month ⇒ Object
Returns the value of attribute birth_month.
-
#birth_year ⇒ Object
Returns the value of attribute birth_year.
-
#email ⇒ Object
Returns the value of attribute email.
-
#entity_scope ⇒ Object
Returns the value of attribute entity_scope.
-
#entity_type ⇒ Object
Returns the value of attribute entity_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#permission_scope ⇒ String
readonly
Https://docs.synapsepay.com/docs/user-resources#section-document-permission-scope.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
-
#physical_documents ⇒ Object
Returns the value of attribute physical_documents.
-
#screening_results ⇒ Object
Returns the value of attribute screening_results.
-
#social_documents ⇒ Object
Returns the value of attribute social_documents.
-
#user ⇒ SynapsePayRest::User
The user to whom the transaction belongs.
-
#virtual_documents ⇒ Object
Returns the value of attribute virtual_documents.
Class Method Summary collapse
-
.create(user:, email:, phone_number:, ip:, name:, aka:, entity_type:, entity_scope:, birth_day:, birth_month:, birth_year:, address_street:, address_city:, address_subdivision:, address_postal_code:, address_country_code:, physical_documents: [], social_documents: [], virtual_documents: []) ⇒ SynapsePayRest::BaseDocument
Creates a new base document in the API belonging to the provided user and returns a base document instance from the response data.
-
.from_response(user, response) ⇒ Object
Parses multiple base_documents from response.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks if two BaseDocument instances have same id (different instances of same record).
-
#add_physical_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more physical documents to the base document and submits them to the API using KYC 2.0 endpoints.
-
#add_social_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more social documents to the base document and submits them to the API using KYC 2.0 endpoints.
-
#add_virtual_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more virtual documents to the base document and submits them to the API using KYC 2.0 endpoints.
-
#initialize(args) ⇒ BaseDocument
constructor
A new instance of BaseDocument.
-
#submit ⇒ SynapsePayRest::BaseDocument
Submits the base document to the API.
-
#update(**changes) ⇒ SynapsePayRest::BaseDocument
Updates the supplied fields in the base document.
Constructor Details
#initialize(args) ⇒ BaseDocument
It should not be necessary to call this method directly.
Returns a new instance of BaseDocument.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 163 def initialize(args) @id = args["id"] @permission_scope = args["permission_scope"] @user = args["user"] @email = args["email"] @phone_number = args["phone_number"] @ip = args["ip"] @name = args["name"] @aka = args["aka"] @entity_type = args["entity_type"] @entity_scope = args["entity_scope"] @birth_day = args["birth_day"] @birth_month = args["birth_month"] @birth_year = args["birth_year"] @address_street = args["address_street"] @address_city = args["address_city"] @address_subdivision = args["address_subdivision"] @address_postal_code = args["address_postal_code"] @address_country_code = args["address_country_code"] @screening_results = args["screening_results"] @physical_documents = args["physical_documents"] @social_documents = args["social_documents"] @virtual_documents = args["virtual_documents"] end |
Instance Attribute Details
#address_city ⇒ Object
Returns the value of attribute address_city.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def address_city @address_city end |
#address_country_code ⇒ Object
Returns the value of attribute address_country_code.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def address_country_code @address_country_code end |
#address_postal_code ⇒ Object
Returns the value of attribute address_postal_code.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def address_postal_code @address_postal_code end |
#address_street ⇒ Object
Returns the value of attribute address_street.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def address_street @address_street end |
#address_subdivision ⇒ Object
Returns the value of attribute address_subdivision.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def address_subdivision @address_subdivision end |
#aka ⇒ Object
Returns the value of attribute aka.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def aka @aka end |
#alias ⇒ Object
Returns the value of attribute alias.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def alias @alias end |
#birth_day ⇒ Object
Returns the value of attribute birth_day.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def birth_day @birth_day end |
#birth_month ⇒ Object
Returns the value of attribute birth_month.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def birth_month @birth_month end |
#birth_year ⇒ Object
Returns the value of attribute birth_year.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def birth_year @birth_year end |
#email ⇒ Object
Returns the value of attribute email.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def email @email end |
#entity_scope ⇒ Object
Returns the value of attribute entity_scope.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def entity_scope @entity_scope end |
#entity_type ⇒ Object
Returns the value of attribute entity_type.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def entity_type @entity_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 15 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def name @name end |
#permission_scope ⇒ String (readonly)
9 10 11 12 13 14 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 attr_accessor :user, :email, :phone_number, :ip, :name, :aka, :entity_type, :entity_scope, :birth_day, :birth_month, :birth_year, :address_street, :address_city, :address_subdivision, :address_postal_code, :address_country_code, :physical_documents, :social_documents, :virtual_documents, :alias, :screening_results |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def phone_number @phone_number end |
#physical_documents ⇒ Object
Returns the value of attribute physical_documents.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def physical_documents @physical_documents end |
#screening_results ⇒ Object
Returns the value of attribute screening_results.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def screening_results @screening_results end |
#social_documents ⇒ Object
Returns the value of attribute social_documents.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def @social_documents end |
#user ⇒ SynapsePayRest::User
Returns the user to whom the transaction belongs.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def user @user end |
#virtual_documents ⇒ Object
Returns the value of attribute virtual_documents.
9 10 11 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9 def virtual_documents @virtual_documents end |
Class Method Details
.create(user:, email:, phone_number:, ip:, name:, aka:, entity_type:, entity_scope:, birth_day:, birth_month:, birth_year:, address_street:, address_city:, address_subdivision:, address_postal_code:, address_country_code:, physical_documents: [], social_documents: [], virtual_documents: []) ⇒ SynapsePayRest::BaseDocument
Creates a new base document in the API belonging to the provided user and returns a base document instance from the response data.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 46 def create(user:, email:, phone_number:, ip:, name:, aka:, entity_type:, entity_scope:, birth_day:, birth_month:, birth_year:, address_street:, address_city:, address_subdivision:, address_postal_code:, address_country_code:, physical_documents: [], social_documents: [], virtual_documents: []) raise ArgumentError, 'user must be a User object' unless user.is_a?(User) [email, phone_number, ip, name, aka, entity_type, entity_scope, address_street, address_city, address_subdivision, address_postal_code, address_country_code].each do |arg| raise ArgumentError, "#{arg} must be a String" unless arg.is_a?(String) end [physical_documents, , virtual_documents].each do |arg| raise ArgumentError, "#{arg} must be an Array" unless arg.is_a?(Array) end unless physical_documents.empty? || physical_documents.first.is_a?(PhysicalDocument) raise ArgumentError, 'physical_documents be empty or contain PhysicalDocument(s)' end unless .empty? || .first.is_a?(SocialDocument) raise ArgumentError, 'social_documents be empty or contain SocialDocument(s)' end unless virtual_documents.empty? || virtual_documents.first.is_a?(VirtualDocument) raise ArgumentError, 'virtual_documents be empty or contain VirtualDocument(s)' end base_document = BaseDocument.new({ "user"=>user, "email"=>email, "phone_number"=>phone_number, "ip"=>ip, "name"=>name, "aka"=>aka, "entity_type"=>entity_type, "entity_scope"=>entity_scope, "birth_day"=>birth_day, "birth_month"=>birth_month, "birth_year"=>birth_year, "address_street"=>address_street, "address_city"=>address_city, "address_subdivision"=>address_subdivision, "address_postal_code"=>address_postal_code, "address_country_code"=>address_country_code, "physical_documents"=>physical_documents, "social_documents"=>, "virtual_documents"=>virtual_documents }) base_document.submit end |
.from_response(user, response) ⇒ Object
Do not call directly (it’s automatic).
Parses multiple base_documents from response
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 96 def from_response(user, response) base_documents_data = response['documents'] base_documents_data.map do |base_document_data| physical_docs = base_document_data['physical_docs'].map do |data| doc = PhysicalDocument.from_response(data) doc.base_document = self doc end = base_document_data['social_docs'].map do |data| doc = SocialDocument.from_response(data) doc.base_document = self doc end virtual_docs = base_document_data['virtual_docs'].map do |data| doc = VirtualDocument.from_response(data) doc.base_document = self doc end args = { "user"=>user, "id"=>base_documents_data.first['id'], "name"=>base_documents_data.first['name'], "permission_scope"=>base_documents_data.first['permission_scope'], "address_city"=>base_documents_data.first['address_city'], "address_country_code"=>base_documents_data.first['address_country_code'], "address_postal_code"=>base_documents_data.first['address_postal_code'], "address_street"=>base_documents_data.first['address_street'], "address_subdivision"=>base_documents_data.first['address_subdivision'], "alias"=>base_documents_data.first['alias'], "birth_day"=>base_documents_data.first['day'], "email"=>base_documents_data.first['email'], "entity_scope"=>base_documents_data.first['entity_scope'], "entity_type"=>base_documents_data.first['entity_type'], "ip"=>base_documents_data.first['ip'], "birth_month"=>base_documents_data.first['month'], "phone_number"=>base_documents_data.first['phone_number'], "birth_year"=>base_documents_data.first['year'], "screening_results"=>base_documents_data.first['screening_results'], "physical_documents"=>physical_docs, "social_documents"=>, "virtual_documents"=>virtual_docs } other_keys = base_document_data.keys ["physical_docs", "social_docs", "virtual_docs"].each do |item| other_keys.delete_at(other_keys.index(item)) end for key in other_keys do if base_document_data.has_key?(key) args[key] = base_document_data[key] end end base_doc = self.new(args) [physical_docs, , virtual_docs].flatten.each do |doc| doc.base_document = base_doc end base_doc end end |
Instance Method Details
#==(other) ⇒ Object
Checks if two BaseDocument instances have same id (different instances of same record).
302 303 304 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 302 def ==(other) other.instance_of?(self.class) && !id.nil? && id == other.id end |
#add_physical_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more physical documents to the base document and submits them to the API using KYC 2.0 endpoints.
261 262 263 264 265 266 267 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 261 def add_physical_documents(*documents) unless documents.first.is_a?(PhysicalDocument) raise ArgumentError, 'must contain a PhysicalDocument' end update(physical_documents: documents) end |
#add_social_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more social documents to the base document and submits them to the API using KYC 2.0 endpoints.
277 278 279 280 281 282 283 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 277 def (*documents) unless documents.first.is_a?(SocialDocument) raise ArgumentError, 'must contain a SocialDocument' end update(social_documents: documents) end |
#add_virtual_documents(*documents) ⇒ SynapsePayRest::BaseDocument
Adds one or more virtual documents to the base document and submits them to the API using KYC 2.0 endpoints.
293 294 295 296 297 298 299 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 293 def add_virtual_documents(*documents) unless documents.first.is_a?(VirtualDocument) raise ArgumentError, 'must contain a VirtualDocument' end update(virtual_documents: documents) end |
#submit ⇒ SynapsePayRest::BaseDocument
It should not be necessary to call this method directly.
Submits the base document to the API.
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 194 def submit response = user.client.users.update(user_id: user.id, payload: payload_for_submit) @user = User.from_response(user.client, response) if id # return updated version of self user.base_documents.find { |doc| doc.id == id } else # first time submission, assume last doc is updated version of self user.base_documents.last end end |
#update(**changes) ⇒ SynapsePayRest::BaseDocument
validate changes are valid fields in base_document (or make other methods more like this)
Updates the supplied fields in the base document. See #create for valid
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 236 def update(**changes) if changes.empty? raise ArgumentError, 'must provide some key-value pairs to update' end payload = payload_for_update(changes) response = user.client.users.update(user_id: user.id, payload: payload) @user = User.from_response(user.client, response) if id # return updated version of self return user.base_documents.find { |doc| doc.id == id } else # first time submission, assume last doc is updated version of self return user.base_documents.last end end |