Class: SynapsePayRest::BaseDocument

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BaseDocument

Note:

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_cityObject

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_codeObject

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_codeObject

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_streetObject

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_subdivisionObject

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

#akaObject

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

#aliasObject

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_dayObject

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_monthObject

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_yearObject

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

#emailObject

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_scopeObject

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_typeObject

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

#idObject (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

#ipObject

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

#nameObject

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_scopeString (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_numberObject

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_documentsObject

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_resultsObject

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_documentsObject

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
  @social_documents
end

#userSynapsePayRest::User

Returns the user to whom the transaction belongs.

Returns:



9
10
11
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 9

def user
  @user
end

#virtual_documentsObject

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.

Parameters:

  • user (SynapsePayRest::User)

    the user to whom the base document belongs

  • email (String)
  • phone_number (String)
  • ip (String)
  • name (String)
  • aka (String)

    corresponds to ‘alias’ in docs, use name if no alias

  • entity_type (String)

    consult your organization’s CIP for valid options

  • entity_scope (String)

    consult your organization’s CIP for valid options

  • birth_day (Integer)
  • birth_month (Integer)
  • birth_year (Integer)
  • address_street (String)
  • address_city (String)
  • address_subdivision (String)
  • address_postal_code (String)
  • address_country_code (String)
  • physical_documents (Array<SynapsePayRest::PhysicalDocument>) (defaults to: [])

    (optional)

  • social_documents (Array<SynapsePayRest::SocialDocument>) (defaults to: [])

    (optional)

  • virtual_documents (Array<SynapsePayRest::VirtualDocument>) (defaults to: [])

    (optional)

Returns:

Raises:

See Also:



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, social_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 social_documents.empty? || social_documents.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"=>social_documents,
    "virtual_documents"=>virtual_documents
  })
  base_document.submit
end

.from_response(user, response) ⇒ Object

Note:

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
    social_docs = 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"=>social_docs,
      "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, social_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.

Parameters:

Returns:

Raises:



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.

Parameters:

Returns:

Raises:



277
278
279
280
281
282
283
# File 'lib/synapse_pay_rest/models/user/base_document.rb', line 277

def add_social_documents(*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.

Parameters:

Returns:

Raises:



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

#submitSynapsePayRest::BaseDocument

Note:

It should not be necessary to call this method directly.

Submits the base document to the API.

Returns:

Raises:



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

TODO:

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

Parameters:

  • email (String)

    (optional)

  • phone_number (String)

    (optional)

  • ip (String)

    (optional)

  • name (String)

    (optional)

  • aka (String)

    (optional) corresponds to ‘alias’ in docs, use name if no alias

  • entity_type (String)

    (optional) consult your organization’s CIP for valid options

  • entity_scope (String)

    (optional) consult your organization’s CIP for valid options

  • birth_day (Integer)

    (optional)

  • birth_month (Integer)

    (optional)

  • birth_year (Integer)

    (optional)

  • address_street (String)

    (optional)

  • address_city (String)

    (optional)

  • address_subdivision (String)

    (optional)

  • address_postal_code (String)

    (optional)

  • address_country_code (String)

    (optional)

  • physical_documents (Array<SynapsePayRest::PhysicalDocument>)

    (optional)

  • social_documents (Array<SynapsePayRest::SocialDocument>)

    (optional)

  • virtual_documents (Array<SynapsePayRest::VirtualDocument>)

    (optional)

Returns:

Raises:

See Also:



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