Class: Providers::VendorPayment
- Inherits:
-
Object
- Object
- Providers::VendorPayment
- Includes:
- DefaultErrorContainer
- Defined in:
- app/my_lib/payment/providers/vendor_payment.rb
Overview
The Providers::VendorPayment class is responsible for handling vendor payment processing.
Instance Method Summary collapse
-
#charge(amount) ⇒ Boolean
Processes a charge for the given amount.
-
#initialize(ticket_transaction, options = {}) ⇒ VendorPayment
constructor
Initializes a new VendorPayment instance.
-
#valid? ⇒ Boolean
Checks if the payment instance is valid.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
#initialize(ticket_transaction, options = {}) ⇒ VendorPayment
Initializes a new VendorPayment instance.
20 21 22 23 |
# File 'app/my_lib/payment/providers/vendor_payment.rb', line 20 def initialize(ticket_transaction, = {}) @ticket_transaction = ticket_transaction @options = end |
Instance Method Details
#charge(amount) ⇒ Boolean
Processes a charge for the given amount.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/my_lib/payment/providers/vendor_payment.rb', line 29 def charge(amount) omise_source = create_omise_source if omise_source.blank? errors.add(:base, 'Failed to create new vendor payment omise source') return false end vendor_payment_attributes = create_vendor_payment_params(omise_source.id, amount).permit! VendorTicketTransactionPayment.create_payment!(vendor_payment_attributes.to_h) charge_record = ticket_transaction.charges.build(charge_attributes(omise_source.id, amount)) charge_record.present? rescue StandardError => e error.add :base, e. false end |
#valid? ⇒ Boolean
Checks if the payment instance is valid.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/my_lib/payment/providers/vendor_payment.rb', line 50 def valid? required_fields = [:transaction_id, :status, :paid_at, :vendor_id] missing_fields = required_fields.select { |field| [field].blank? } if missing_fields.any? errors.add(:base, "Missing required fields: #{missing_fields.join(', ')}") return false end true end |