Class: MpApi::Card
- Inherits:
-
Object
- Object
- MpApi::Card
- Defined in:
- lib/mp_api/card.rb
Instance Attribute Summary collapse
-
#cardholder_name ⇒ Object
readonly
Returns the value of attribute cardholder_name.
-
#customer_id ⇒ Object
readonly
Returns the value of attribute customer_id.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_detail ⇒ Object
readonly
Returns the value of attribute error_detail.
-
#expiration_month ⇒ Object
readonly
Returns the value of attribute expiration_month.
-
#expiration_year ⇒ Object
readonly
Returns the value of attribute expiration_year.
-
#external_id ⇒ Object
readonly
Returns the value of attribute external_id.
-
#first_six_digits ⇒ Object
readonly
Returns the value of attribute first_six_digits.
-
#issuer_id ⇒ Object
readonly
Returns the value of attribute issuer_id.
-
#last_four_digits ⇒ Object
readonly
Returns the value of attribute last_four_digits.
-
#mp_payment_method_id ⇒ Object
readonly
Returns the value of attribute mp_payment_method_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #build_json ⇒ Object
- #create ⇒ Object
-
#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
constructor
A new instance of Card.
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_name ⇒ Object (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_id ⇒ Object (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 |
#error ⇒ Object (readonly)
Returns the value of attribute error.
3 4 5 |
# File 'lib/mp_api/card.rb', line 3 def error @error end |
#error_detail ⇒ Object (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_month ⇒ Object (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_year ⇒ Object (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_id ⇒ Object (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_digits ⇒ Object (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_id ⇒ Object (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_digits ⇒ Object (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_id ⇒ Object (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 |
#token ⇒ Object (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_json ⇒ Object
20 21 22 23 24 |
# File 'lib/mp_api/card.rb', line 20 def build_json { token: token } end |
#create ⇒ Object
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 |