Class: SaasPlatform::PaymentService

Inherits:
Object
  • Object
show all
Defined in:
app/services/saas_platform/payment_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(account) ⇒ PaymentService

Returns a new instance of PaymentService.



3
4
5
6
# File 'app/services/saas_platform/payment_service.rb', line 3

def initialize()
  @account = 
  @wallet = .wallet || .create_wallet(currency: 'USD')
end

Instance Method Details

#process_order_payment(order, stripe_payment_intent_id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/saas_platform/payment_service.rb', line 8

def process_order_payment(order, stripe_payment_intent_id)
  # In a real app, verify with Stripe
  # stripe_payload = Stripe::PaymentIntent.retrieve(stripe_payment_intent_id)
  
  Order.transaction do
    order.pay!
    @wallet.credit!(order.total, category: 'sale', reference: order)
    
    # Log audit trail
    @account.notifications.create(
      message: "Payment of #{order.total.format} received for Order ##{order.id}",
      category: 'payment'
    )
  end
end

#withdraw_funds(amount) ⇒ Object



24
25
26
27
28
29
30
# File 'app/services/saas_platform/payment_service.rb', line 24

def withdraw_funds(amount)
  raise "Insufficient balance" if @wallet.balance < amount
  
  @wallet.debit!(amount, category: 'withdrawal', status: 'pending')
  # Trigger background job for payout
  # PayoutJob.perform_later(@account.id, amount.cents)
end