Class: Kaui::InvoicePayment
- Inherits:
-
KillBillClient::Model::InvoicePayment
- Object
- KillBillClient::Model::InvoicePayment
- Kaui::InvoicePayment
- Includes:
- PaymentState
- Defined in:
- app/models/kaui/invoice_payment.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#build_transactions_next_retry_date! ⇒ Object
For each payment transaction, compute next_retry date by joining with payment attempts.
Methods included from PaymentState
#amount_capturable, #amount_refundable, #capturable?, #chargebackable?, #fully_refunded?, #paid_amount_to_money, #refundable?, #returned_amount_to_money, #total_authed_amount_to_money, #voidable?
Class Method Details
.build_from_raw_payment(raw_payment) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/kaui/invoice_payment.rb', line 16 def build_from_raw_payment(raw_payment) return nil if raw_payment.nil? result = Kaui::InvoicePayment.new KillBillClient::Model::InvoicePaymentAttributes.instance_variable_get('@json_attributes').each do |attr| result.send("#{attr}=", raw_payment.send(attr)) end # Use Kaui::Transaction to benefit from additional fields (e.g next_retry_date) original_transactions = (result.transactions || []) result.transactions = [] original_transactions.each do |transaction| new_transaction = Kaui::Transaction.new KillBillClient::Model::PaymentTransactionAttributes.instance_variable_get('@json_attributes').each do |attr| new_transaction.send("#{attr}=", transaction.send(attr)) end result.transactions << new_transaction end result.build_transactions_next_retry_date! result end |
.find_safely_by_id(id, options = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/models/kaui/invoice_payment.rb', line 8 def find_safely_by_id(id, = {}) Kaui::InvoicePayment.find_by_id(id, true, true, ) rescue StandardError => e # Maybe the plugin is not registered or the plugin threw an exception Rails.logger.warn(e) Kaui::InvoicePayment.find_by_id(id, false, true, ) end |
Instance Method Details
#build_transactions_next_retry_date! ⇒ Object
For each payment transaction, compute next_retry date by joining with payment attempts
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/kaui/invoice_payment.rb', line 45 def build_transactions_next_retry_date! # Filter scheduled attempts: We could have several in parallel when multiple independent transactions occur at the same time # (They would have different transaction_external_key) scheduled_attempts = (payment_attempts || []).select do |a| a.state_name == 'SCHEDULED' end # Look for latest transaction associated with each such scheduled attempt and set retry date accordingly scheduled_attempts.each do |a| last_transaction_for_attempt = (transactions || []).select do |t| t.transaction_external_key == a.transaction_external_key end.max_by(&:effective_date) last_transaction_for_attempt.next_retry_date = a.effective_date if last_transaction_for_attempt end end |