Class: MpApi::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/mp_api/card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, customer_id: nil, external_id: nil, cardholder_name: nil, expiration_month: nil, expiration_year: nil, first_six_digits: nil, last_four_digits: nil, issuer_id: nil, mp_payment_method_id: nil, error: nil, error_detail: nil) ⇒ Card

Returns a new instance of Card.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mp_api/card.rb', line 5

def initialize(token: nil, customer_id: nil, external_id: nil, cardholder_name: nil, expiration_month: nil, expiration_year: nil, first_six_digits: nil, last_four_digits: nil, issuer_id: nil, mp_payment_method_id: nil, error: nil, error_detail: nil)
  @token = token
  @customer_id = customer_id
  @external_id = external_id
  @cardholder_name = cardholder_name
  @expiration_month = expiration_month
  @expiration_year = expiration_year
  @first_six_digits = first_six_digits
  @last_four_digits = last_four_digits
  @issuer_id = issuer_id
  @mp_payment_method_id = mp_payment_method_id
  @error = error
  @error_detail = error_detail
end

Instance Attribute Details

#cardholder_nameObject (readonly)

Returns the value of attribute cardholder_name.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def cardholder_name
  @cardholder_name
end

#customer_idObject (readonly)

Returns the value of attribute customer_id.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def customer_id
  @customer_id
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def error
  @error
end

#error_detailObject (readonly)

Returns the value of attribute error_detail.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def error_detail
  @error_detail
end

#expiration_monthObject (readonly)

Returns the value of attribute expiration_month.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def expiration_month
  @expiration_month
end

#expiration_yearObject (readonly)

Returns the value of attribute expiration_year.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def expiration_year
  @expiration_year
end

#external_idObject (readonly)

Returns the value of attribute external_id.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def external_id
  @external_id
end

#first_six_digitsObject (readonly)

Returns the value of attribute first_six_digits.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def first_six_digits
  @first_six_digits
end

#issuer_idObject (readonly)

Returns the value of attribute issuer_id.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def issuer_id
  @issuer_id
end

#last_four_digitsObject (readonly)

Returns the value of attribute last_four_digits.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def last_four_digits
  @last_four_digits
end

#mp_payment_method_idObject (readonly)

Returns the value of attribute mp_payment_method_id.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def mp_payment_method_id
  @mp_payment_method_id
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/mp_api/card.rb', line 3

def token
  @token
end

Class Method Details

.build_hash(response) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mp_api/card.rb', line 31

def self.build_hash(response)
  {
    external_id: response.dig("id"),
    cardholder_name: response.dig("cardholder", "name"),
    expiration_month: response.dig("expiration_month"),
    expiration_year: response.dig("expiration_year"),
    first_six_digits: response.dig("first_six_digits"),
    last_four_digits: response.dig("last_four_digits"),
    issuer_id: response.dig("issuer", "id"),
    mp_payment_method_id: response.dig("payment_method", "id"),
    error: response.dig("message"),
    error_detail: response.dig("cause")
  }
end

Instance Method Details

#build_jsonObject



20
21
22
23
24
# File 'lib/mp_api/card.rb', line 20

def build_json
  {
    token: token
  }
end

#createObject



26
27
28
29
# File 'lib/mp_api/card.rb', line 26

def create
  response = Client.new.create_card(customer_id, JSON.dump(build_json))
  self.class.new(**self.class.build_hash(response.json))
end