Skip to content

Commit 1f8f4c9

Browse files
committed
fix: ensure ProPay customer exists before proxying wallet deposit
Users without a Customer record in ProPay received a 404 on deposit. Now a find-or-create call registers the customer transparently using the current user's full_name and email before the deposit is proxied.
1 parent 49630b9 commit 1f8f4c9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

app/controllers/api/v1/wallet_controller.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def transactions
4141
#
4242
# @return [JSON] Proxied response from ProPay
4343
def deposit
44+
ensure_propay_customer!
4445
proxy_to_propay(
4546
:post,
4647
'/v1/wallet/deposit',
@@ -79,6 +80,30 @@ def payout_status
7980

8081
private
8182

83+
# Registers the current user as a ProPay customer (find-or-create).
84+
# Called before any action that requires a Customer record in ProPay.
85+
# Errors are logged but not raised — the downstream call surfaces them.
86+
#
87+
# @return [void]
88+
def ensure_propay_customer!
89+
propay_url = ENV.fetch('PROPAY_URL', 'http://propay:5555')
90+
uri = URI("#{propay_url}/v1/customers")
91+
92+
http = Net::HTTP.new(uri.host, uri.port)
93+
http.open_timeout = 5
94+
http.read_timeout = 10
95+
96+
headers = {
97+
'Content-Type' => 'application/json',
98+
'Authorization' => request.headers['Authorization']
99+
}
100+
req = Net::HTTP::Post.new(uri.request_uri, headers)
101+
req.body = { full_name: current_user.full_name, email: current_user.email }.to_json
102+
http.request(req)
103+
rescue StandardError => e
104+
Rails.logger.warn("[WALLET] ensure_propay_customer! failed: #{e.message}")
105+
end
106+
82107
# Forwards the request to ProPay and renders the response verbatim.
83108
#
84109
# @param method [Symbol] HTTP method (:get or :post)

0 commit comments

Comments
 (0)