Question

I'm using Google Wallet and I need to send a response to Google's post request with the decoded order_id. Here is the tutorial I'm following: https://developers.google.com/commerce/wallet/digital/training/getting-started/handle-notif . Google checks (response.status == 200) && (response.content == orderId), from this documentation. How do I add a custom content method to the response object, return the orderId as a header, or something else? I've looked through the API docs and did not see anything that would help.

The order does not go through because I'm not sending back the order id. If I don't use a "postback url", the order goes through. Also, I have removed log in walls from the controller.

Here is my controller's create action:

def create
  @postback_jwt = JWT.decode(params[:jwt], ENV['GOOGLE_WALLET_SECRET'])
  order_id = @postback_jwt["response"]["orderId"]
  render :new
end
Was it helpful?

Solution 2

Thanks to EdSF for the guidance:

def create
  @postback_jwt = JWT.decode(params[:jwt], ENV['GOOGLE_WALLET_SECRET'])
  order_id = @postback_jwt["response"]["orderId"]
  render :new
  response.body = order_id
end

Another option:

def create
  @postback_jwt = JWT.decode(params[:jwt], ENV['GOOGLE_WALLET_SECRET'])
  order_id = @postback_jwt["response"]["orderId"]
  render text: order_id
end

The order of the response and render through me off. The response.body... line needs to go below the render... line. Otherwise the render will clear the body. And redirect doesn't work.

Neither work in development because you can't have a postback to localhost. So testing has to be done on a production/staging server.

OTHER TIPS

I'm not a ruby person (am WISA) so unsure if this will help:

In ASP (classic or .Net) you would write the orderId in the response body e.g.

Response.ContentType = "text/plain";
Response.Write(orderId); 

I think this SO post: does rails have a 'response.write' will be helpful.

Hth..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top