Skip to content
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

Merged
merged 2 commits into from Apr 19, 2021

Conversation

darren987469
Copy link

The PR main to support secure tran (認証後決済実行).

Also fix the code to parse the response and transform it to a hash.

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 "=".
Comment on lines +40 to +43
# 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]
Copy link
Author

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).

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator

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.

@darren987469
Copy link
Author

@jiikko Have time to take a look? 🙏

@jiikko
Copy link
Collaborator

jiikko commented Mar 4, 2021

@darren987469
Thank you for the PR.
I will review later!

Copy link
Collaborator

@jiikko jiikko left a 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.

Comment on lines +40 to +43
# 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]
Copy link
Collaborator

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.

Copy link
Collaborator

@jiikko jiikko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!

Comment on lines +40 to +43
# 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]
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants