New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support secure tran 認証後決済実行 #45
Conversation
We want to transform the response to a hash. Example: `"ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" }`. `Rack::Utils.parse_nested_query` works in most case. But when there is a `+` in the response body, it converts `+` to empty string. Fix: First split string by "&" then by "=".
# Transform the body to Hash | ||
# "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" } | ||
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten | ||
response = Hash[*key_values] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rack::Utils.parse_nested_query
works in most case. But when
there is a +
in the response body, it converts +
to empty string (which is wrong).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about this case?
[16] pry(main)> Rack::Utils.parse_nested_query("a=1+3")
=> {"a"=>"1 3"}
In this case, I think URL decoding is necessary.
Also, URL decoding is not possible with this implementation.
[19] pry(main)> { a: "1+3" }.to_query.split('&').map { |str| str.split('=', 2) }.flatten
=> ["a", "1%2B3"]
If you get this kind of response, it may be a problem on the GMO server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiikko Let me describe this with more details.
The issue I encounter is:
result = gmo.exec_tran(**args)
# gmo response.body = "ACS=1&PaReq=eJxV+Ff"
result
# { "ACS" => "1", "PaReq" => "eJxV Ff" } <= actual result, wrong
# expected result { "ACS" => "1", "PaReq" => "eJxV+Ff" }
The problem caused by
[147] pry(main)> Rack::Utils.parse_nested_query("ACS=1&PaReq=eJxV+Ff")
=> {"ACS"=>"1", "PaReq"=>"eJxV Ff"} # Rack::Utils.parse_nested_query convert "+" to " " (empty string)
So I fix the way to parse the response.
Does here need URL decoding? It's a response, not a query from a URL.
I applied this change to our product and it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation!!! 🙇
I understood perfectly.
@jiikko Have time to take a look? 🙏 |
@darren987469 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I'm late.
It almost looks good.
I've commented on the URL decoding part.
Please check.
# Transform the body to Hash | ||
# "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" } | ||
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten | ||
response = Hash[*key_values] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about this case?
[16] pry(main)> Rack::Utils.parse_nested_query("a=1+3")
=> {"a"=>"1 3"}
In this case, I think URL decoding is necessary.
Also, URL decoding is not possible with this implementation.
[19] pry(main)> { a: "1+3" }.to_query.split('&').map { |str| str.split('=', 2) }.flatten
=> ["a", "1%2B3"]
If you get this kind of response, it may be a problem on the GMO server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!
# Transform the body to Hash | ||
# "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" } | ||
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten | ||
response = Hash[*key_values] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation!!! 🙇
I understood perfectly.
The PR main to support secure tran (認証後決済実行).
Also fix the code to parse the response and transform it to a hash.