Class: MpApi::Token
- Inherits:
-
Object
- Object
- MpApi::Token
- Defined in:
- lib/mp_api/token.rb
Instance Attribute Summary collapse
-
#card_number ⇒ Object
readonly
Returns the value of attribute card_number.
-
#cardholder_name ⇒ Object
readonly
Returns the value of attribute cardholder_name.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#expiration_month ⇒ Object
readonly
Returns the value of attribute expiration_month.
-
#expiration_year ⇒ Object
readonly
Returns the value of attribute expiration_year.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#security_code ⇒ Object
readonly
Returns the value of attribute security_code.
Class Method Summary collapse
Instance Method Summary collapse
- #build_json ⇒ Object
- #create ⇒ Object
-
#initialize(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:, id: nil, errors: nil) ⇒ Token
constructor
A new instance of Token.
Constructor Details
#initialize(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:, id: nil, errors: nil) ⇒ Token
Returns a new instance of Token.
4 5 6 7 8 9 10 11 12 |
# File 'lib/mp_api/token.rb', line 4 def initialize(card_number:, expiration_year:, expiration_month:, security_code:, cardholder_name:, id: nil, errors: nil) @card_number = card_number @expiration_year = expiration_year @expiration_month = expiration_month @security_code = security_code @cardholder_name = cardholder_name @id = id @errors = errors end |
Instance Attribute Details
#card_number ⇒ Object (readonly)
Returns the value of attribute card_number.
3 4 5 |
# File 'lib/mp_api/token.rb', line 3 def card_number @card_number end |
#cardholder_name ⇒ Object (readonly)
Returns the value of attribute cardholder_name.
3 4 5 |
# File 'lib/mp_api/token.rb', line 3 def cardholder_name @cardholder_name end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/mp_api/token.rb', line 3 def errors @errors end |
#expiration_month ⇒ Object (readonly)
Returns the value of attribute expiration_month.
3 4 5 |
# File 'lib/mp_api/token.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/token.rb', line 3 def expiration_year @expiration_year end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/mp_api/token.rb', line 3 def id @id end |
#security_code ⇒ Object (readonly)
Returns the value of attribute security_code.
3 4 5 |
# File 'lib/mp_api/token.rb', line 3 def security_code @security_code end |
Class Method Details
.build_hash(response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mp_api/token.rb', line 31 def self.build_hash(response) { id: response["id"], expiration_year: response["expiration_year"], expiration_month: response["expiration_month"], cardholder_name: response.dig("cardholder", "name"), card_number: response["card_number"], security_code: response["security_code"], errors: response["error"] } end |
Instance Method Details
#build_json ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mp_api/token.rb', line 14 def build_json { card_number: card_number, expiration_year: expiration_year, expiration_month: expiration_month, security_code: security_code, cardholder: { name: cardholder_name } } end |
#create ⇒ Object
26 27 28 29 |
# File 'lib/mp_api/token.rb', line 26 def create response = Client.new.create_token(JSON.dump(build_json)) self.class.new(**self.class.build_hash(response.json)) end |