Skip to content

Instantly share code, notes, and snippets.

@ashhadsheikh
Created February 4, 2026 10:05
Show Gist options
  • Select an option

  • Save ashhadsheikh/d1821e175bab9346919cfbcb74eedb6e to your computer and use it in GitHub Desktop.

Select an option

Save ashhadsheikh/d1821e175bab9346919cfbcb74eedb6e to your computer and use it in GitHub Desktop.
Investigation: Digital Cash Exchange 500 Error

Investigation: Digital Cash Exchange 500 Error

Request Details

Field Value
Request ID 6413c676-e547-45be-948e-ab491b4060d1
Endpoint POST /api/v1/digital_cash/exchange
Time 2026-02-04 09:53:12 UTC
User Basit Masood (Customer)
User ID 958a4910-a20f-4a06-81d6-d458dcc3bf57
Status 500 Internal Server Error

Request Payload

  • Amount: 36.00 USDC
  • Custom Rate: 280.00 PKR
  • Local Currency: PKR
  • Ad ID: null (quick exchange, no ad)

Error

NoMethodError - undefined method `business_name' for nil

Stack trace:

/rails/app/services/digital_cash/exchange_note/create/service.rb:76 in `ad_snapshot`
/rails/app/services/digital_cash/exchange_note/create/service.rb:95 in `deposit_callback_arguments`
/rails/app/services/digital_cash/create/service.rb:213 in `build_commitment_callbacks`

Root Cause

In backend/app/services/digital_cash/exchange_note/create/service.rb:76:

def ad_snapshot
  @ad_snapshot ||= {
    'rate' => (custom_rate || ad&.rate)&.to_f,
    'currency' => local_currency || ad&.currency,
    'merchant_name' => user.merchant_onboarding_submission.business_name  # ← BUG
  }.compact
end

The code assumes all users have a merchant_onboarding_submission record, but this user (a Customer type) does not have one. The association returns nil, causing the NoMethodError.

Fix

Change line 76 from:

'merchant_name' => user.merchant_onboarding_submission.business_name

To:

'merchant_name' => user.merchant_onboarding_submission&.business_name

This allows .compact to remove the merchant_name key when nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment