Skip to content

Instantly share code, notes, and snippets.

@thbar
Last active July 13, 2017 08:57
Show Gist options
  • Select an option

  • Save thbar/283d43759e44ae2f8f23988f87a79499 to your computer and use it in GitHub Desktop.

Select an option

Save thbar/283d43759e44ae2f8f23988f87a79499 to your computer and use it in GitHub Desktop.
def recurly_tax_info(request)
# dump from https://api.recurly.com/js/v1/tax?vat_number=&country=FR&currency=USD&version=3.0.10&key=my_key&callback=__jp1
country = request.uri.query_values['country']
currency = request.uri.query_values['currency']
vat_number = request.uri.query_values['vat_number']
expect(country).to eq('FR')
expect(currency).to eq('USD')
expect(vat_number).to eq('')
[{
"type" => "vat",
"region" => "FR",
"rate" => "0.2"
}]
end
stub_request(:get, %r{api.recurly.com:443/js/v1/tax\?}).to_return { |r| jsonp_callback!(r, recurly_tax_info(r)) }
@token_query = nil
stub = stub_request(:get, %r{api.recurly.com:443/js/v1/token\?}).to_return do |r|
# grab back the values for later comparison
# trying expectation here will fail silently
# and I couldn't get :query on stub_request to work either
@token_query = r.uri.query_values
jsonp_callback!(r, recurly_json_token)
end
def jsonp_callback!(request, response)
callback = request.uri.query_values['callback']
raise "Missing jsonp callback" if callback.blank?
{body: "#{callback}(#{response.to_json})"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment