Class: MpApi::Payment
- Inherits:
-
Object
- Object
- MpApi::Payment
- Defined in:
- lib/mp_api/payment.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#date_approved ⇒ Object
readonly
Returns the value of attribute date_approved.
-
#date_created ⇒ Object
readonly
Returns the value of attribute date_created.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#installments ⇒ Object
readonly
Returns the value of attribute installments.
-
#issuer_id ⇒ Object
readonly
Returns the value of attribute issuer_id.
-
#money_release_date ⇒ Object
readonly
Returns the value of attribute money_release_date.
-
#payer_email ⇒ Object
readonly
Returns the value of attribute payer_email.
-
#payer_identification_number ⇒ Object
readonly
Returns the value of attribute payer_identification_number.
-
#payer_identification_type ⇒ Object
readonly
Returns the value of attribute payer_identification_type.
-
#payment_method ⇒ Object
readonly
Returns the value of attribute payment_method.
-
#payment_type ⇒ Object
readonly
Returns the value of attribute payment_type.
-
#qr_code ⇒ Object
readonly
Returns the value of attribute qr_code.
-
#qr_code_base_64 ⇒ Object
readonly
Returns the value of attribute qr_code_base_64.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_detail ⇒ Object
readonly
Returns the value of attribute status_detail.
-
#three_d_secure_mode ⇒ Object
readonly
Returns the value of attribute three_d_secure_mode.
-
#three_ds_info_creq ⇒ Object
readonly
Returns the value of attribute three_ds_info_creq.
-
#three_ds_info_external_resource_url ⇒ Object
readonly
Returns the value of attribute three_ds_info_external_resource_url.
-
#ticket_url ⇒ Object
readonly
Returns the value of attribute ticket_url.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #build_json ⇒ Object
- #build_json_credit_card ⇒ Object
- #build_json_pix ⇒ Object
- #create ⇒ Object
-
#initialize(status_detail: nil, three_ds_info_creq: nil, three_ds_info_external_resource_url: nil, three_d_secure_mode: nil, id: nil, description: nil, date_approved: nil, date_created: nil, money_release_date: nil, payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, payment_type: nil, qr_code: nil, qr_code_base_64: nil, transaction_id: nil, ticket_url: nil, status: nil, amount:, token: nil, issuer_id: nil, installments: nil) ⇒ Payment
constructor
A new instance of Payment.
Constructor Details
#initialize(status_detail: nil, three_ds_info_creq: nil, three_ds_info_external_resource_url: nil, three_d_secure_mode: nil, id: nil, description: nil, date_approved: nil, date_created: nil, money_release_date: nil, payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, payment_type: nil, qr_code: nil, qr_code_base_64: nil, transaction_id: nil, ticket_url: nil, status: nil, amount:, token: nil, issuer_id: nil, installments: nil) ⇒ Payment
Returns a new instance of Payment.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mp_api/payment.rb', line 14 def initialize(status_detail:nil, three_ds_info_creq:nil, three_ds_info_external_resource_url:nil, three_d_secure_mode:nil, id:nil, description:nil, date_approved:nil, date_created:nil, money_release_date:nil, payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, payment_type:nil, qr_code:nil, qr_code_base_64:nil, transaction_id:nil, ticket_url:nil, status:nil, amount:, token:nil, issuer_id:nil, installments:nil) @id = id @description = description @date_approved = date_approved @date_created = date_created @money_release_date = money_release_date @payer_email = payer_email @payer_identification_type = payer_identification_type @payer_identification_number = payer_identification_number @payment_method = payment_method @payment_type = payment_type @qr_code = qr_code @qr_code_base_64 = qr_code_base_64 @transaction_id = transaction_id @ticket_url = ticket_url @status = status @amount = amount @token = token @issuer_id = issuer_id @installments = installments @three_d_secure_mode = three_d_secure_mode @three_ds_info_external_resource_url = three_ds_info_external_resource_url @three_ds_info_creq = three_ds_info_creq @status_detail = status_detail end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def amount @amount end |
#date_approved ⇒ Object (readonly)
Returns the value of attribute date_approved.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def date_approved @date_approved end |
#date_created ⇒ Object (readonly)
Returns the value of attribute date_created.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def date_created @date_created end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def id @id end |
#installments ⇒ Object (readonly)
Returns the value of attribute installments.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def installments @installments end |
#issuer_id ⇒ Object (readonly)
Returns the value of attribute issuer_id.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def issuer_id @issuer_id end |
#money_release_date ⇒ Object (readonly)
Returns the value of attribute money_release_date.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def money_release_date @money_release_date end |
#payer_email ⇒ Object (readonly)
Returns the value of attribute payer_email.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def payer_email @payer_email end |
#payer_identification_number ⇒ Object (readonly)
Returns the value of attribute payer_identification_number.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def payer_identification_number @payer_identification_number end |
#payer_identification_type ⇒ Object (readonly)
Returns the value of attribute payer_identification_type.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def payer_identification_type @payer_identification_type end |
#payment_method ⇒ Object (readonly)
Returns the value of attribute payment_method.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def payment_method @payment_method end |
#payment_type ⇒ Object (readonly)
Returns the value of attribute payment_type.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def payment_type @payment_type end |
#qr_code ⇒ Object (readonly)
Returns the value of attribute qr_code.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def qr_code @qr_code end |
#qr_code_base_64 ⇒ Object (readonly)
Returns the value of attribute qr_code_base_64.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def qr_code_base_64 @qr_code_base_64 end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def status @status end |
#status_detail ⇒ Object (readonly)
Returns the value of attribute status_detail.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def status_detail @status_detail end |
#three_d_secure_mode ⇒ Object (readonly)
Returns the value of attribute three_d_secure_mode.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def three_d_secure_mode @three_d_secure_mode end |
#three_ds_info_creq ⇒ Object (readonly)
Returns the value of attribute three_ds_info_creq.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def three_ds_info_creq @three_ds_info_creq end |
#three_ds_info_external_resource_url ⇒ Object (readonly)
Returns the value of attribute three_ds_info_external_resource_url.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def three_ds_info_external_resource_url @three_ds_info_external_resource_url end |
#ticket_url ⇒ Object (readonly)
Returns the value of attribute ticket_url.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def ticket_url @ticket_url end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def token @token end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
13 14 15 |
# File 'lib/mp_api/payment.rb', line 13 def transaction_id @transaction_id end |
Class Method Details
.build_hash(json_response) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mp_api/payment.rb', line 77 def self.build_hash json_response { id: json_response.dig('id'), description: json_response.dig('description'), date_approved: json_response.dig('date_approved'), date_created: json_response.dig('date_created'), money_release_date: json_response.dig('money_release_date'), payer_email: json_response.dig('payer', 'email'), payer_identification_type: json_response.dig('payer', 'identification', 'type'), payer_identification_number: json_response.dig('payer', 'identification', 'number'), payment_method: json_response.dig('payment_method_id'), payment_type: json_response.dig('payment_type_id'), qr_code: json_response.dig('point_of_interaction', 'transaction_data', 'qr_code'), qr_code_base_64: json_response.dig('point_of_interaction', 'transaction_data', 'qr_code_base64'), three_ds_info_external_resource_url: json_response.dig('three_ds_info', 'external_resource_url'), three_ds_info_creq: json_response.dig('three_ds_info', 'creq'), transaction_id: json_response.dig('point_of_interaction', 'transaction_data', 'transaction_id'), ticket_url: json_response.dig('point_of_interaction', 'transaction_data', 'ticket_url'), status: json_response.dig('status'), status_detail: json_response.dig('status_detail'), amount: json_response.dig('transaction_amount') } end |
.find_by_id(payment_id) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/mp_api/payment.rb', line 4 def self.find_by_id(payment_id) begin response = Client.new.get_payment(payment_id) rescue RuntimeError => e e. == 'Too many retries' ? raise(TooManyRequestsError) : raise(e) end new(**build_hash(response)) end |
Instance Method Details
#build_json ⇒ Object
40 41 42 |
# File 'lib/mp_api/payment.rb', line 40 def build_json send("build_json_#{payment_method == 'pix' ? 'pix' : 'credit_card'}").except(:description) end |
#build_json_credit_card ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/mp_api/payment.rb', line 59 def build_json_credit_card build_json_pix.merge({ token: token, issuer_id: issuer_id, installments: installments, three_d_secure_mode: three_d_secure_mode ? 'optional' : 'not_supported' }) end |
#build_json_pix ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mp_api/payment.rb', line 44 def build_json_pix { transaction_amount: amount, description: description, payment_method_id: payment_method, payer: { email: payer_email, identification: { type: payer_identification_type, number: payer_identification_number } } } end |
#create ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/mp_api/payment.rb', line 68 def create begin response = Client.new.create_payment(JSON.dump(build_json)) rescue RuntimeError => e e. == 'Too many retries' ? raise(TooManyRequestsError) : raise(e) end self.class.new(**self.class.build_hash(response)) end |