Last active
October 4, 2017 16:01
-
-
Save lcx/ab3de9d769fce1118a3bde116565875d to your computer and use it in GitHub Desktop.
Holvi API, see https://medium.com/@lcx_at/using-the-holvi-api-with-ruby-4838f2499714 for details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
class Shop | |
SHOP_CONFIG = YAML.load_file("#{Rails.root}/config/holvi_config.yml")[Rails.env] | |
def self.get_shop_url | |
holvi_request = {} | |
holvi_request["pool"] = SHOP_CONFIG["pool"] | |
holvi_request["purchases"] = [{"product"=>holvi_product_id}] | |
holvi_request["firstname"] = firstname | |
holvi_request["lastname"] = lastname | |
holvi_request["email"] = email | |
holvi_request["cancel_url"] = SHOP_CONFIG["cancel_url"] | |
holvi_request["success_url"] = SHOP_CONFIG["success_url"] | |
holvi_request["failure_url"] = SHOP_CONFIG["failure_url"] | |
holvi_request["country"] = "Österreich" | |
uri = URI.parse("** API URL **") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request["Content-Type"] = "application/json" | |
request["Authorization"] = "Token #{SHOP_CONFIG["token"]}" | |
request.body = holvi_request.to_json | |
response = http.request(request) | |
return false unless response.code=="201" | |
JSON.parse(response.body) | |
end | |
def self.check_details(details_url) | |
uri = URI.parse(details_url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request["Content-Type"] = "application/json" | |
request["Authorization"] = "Token #{SHOP_CONFIG["token"]}" | |
response = http.request(request) | |
return false if response.code!="200" | |
JSON.parse(response.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this still working?! Holvi Support told me currently they don't have any API implemented?! Is there any reference-contact at holvi.com to ask for it?
Anyone knows a PHP/Composer implementation for this?