lib/mp_api/payment.rb in mp_api-1.2.1 vs lib/mp_api/payment.rb in mp_api-1.2.2
- old
+ new
@@ -1,9 +1,9 @@
module MpApi
class Payment
attr_reader :status_detail, :three_ds_info_creq, :three_ds_info_external_resource_url, :three_d_secure_mode, :id, :description, :date_approved, :date_created, :money_release_date, :payer_email, :payer_identification_type, :payer_identification_number, :payment_method, :last_four_digits, :payment_type, :qr_code, :qr_code_base_64, :transaction_id, :ticket_url, :status, :amount, :token, :issuer_id, :installments, :statement_descriptor, :items, :error, :internal_error, :capture, :date_of_expiration, :saved_card, :customer_id
- def initialize(payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, last_four_digits: nil, amount:, 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, payment_type: nil, qr_code: nil, qr_code_base_64: nil, transaction_id: nil, ticket_url: nil, status: nil, token: nil, issuer_id: nil, installments: nil, items: nil, statement_descriptor: nil, error: nil, internal_error: nil, capture: nil, date_of_expiration: nil, saved_card: false, customer_id: nil)
+ def initialize(payer_email:, payer_identification_type:, payer_identification_number:, payment_method:, amount:, last_four_digits: nil, 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, payment_type: nil, qr_code: nil, qr_code_base_64: nil, transaction_id: nil, ticket_url: nil, status: nil, token: nil, issuer_id: nil, installments: nil, items: nil, statement_descriptor: nil, error: nil, internal_error: nil, capture: nil, date_of_expiration: nil, saved_card: false, customer_id: nil)
@id = id
@description = description
@date_approved = date_approved
@date_created = date_created
@money_release_date = money_release_date
@@ -94,15 +94,24 @@
def create
response = Client.new.create_payment(JSON.dump(build_json))
self.class.new(**self.class.build_hash(response.json))
end
+ def pix_paid? external_value = nil
+ external_value = @amount if external_value.nil?
+ @status == "approved" && external_value.to_d == @amount.to_d
+ end
+
def update attributes
attributes.each do |key, value|
- instance_variable_set("@#{key}", value)
+ instance_variable_set(:"@#{key}", value)
end
Client.new.update_payment(id, JSON.dump(build_update_json))
self.class.find_by_id(id)
+ end
+
+ def invalidate_pix!
+ update(status: "cancelled")
end
def self.find_by_id(payment_id)
response = Client.new.get_payment(payment_id)
new(**build_hash(response.json))