在 rails 应用程序中集成 Instamoji api
Integrate instamojo api in rails app
我正在 rails 学习支付网关集成。
我选择了 insta mojo 并且正在工作,但他们提供的文档非常不方便且难以理解..
https://github.com/AnkurGel/Instamojo-rb#usage
我不知道在哪里设置我的 API 键
require 'Instamojo-rb'
api = Instamojo::API.new do |app|
app.api_key = "api_key-you-received-from-api@instamojo.com"
app.auth_token = "auth_token-you-received-from-api@instamojo.com"
end`
我在初始值设定项中尝试了 instamojo.rb 并尝试 运行 控制台,但它给出了不存在这样的方法的错误。
- 您可以将 require 语句放在 application.rb 或其他任何地方,以便在加载应用程序时加载该文件。
- 您可以制作 'Payment' 模型,您可以在其中制作验证和获取详细信息等方法。
在这些方法内部,您将创建 API 对象并使用上面的代码。
class Payment < ActiveRecord::Base
def verify
client = get_intamojo_client
#Some code
end
def get_details
client = get_intamojo_client
#Some code
end
private
def get_instamojo_client
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"})
return api.client
end
end
要探索使用客户端对象可以做什么,只需使用 rails 控制台并在那里创建一个客户端对象,然后使用 client.public_methods
并开始探索。
编辑:
我认为您使用的是 gem 的旧版本,即 0.1,他们的文档适用于 > 1.0 的版本。要更新,请在 gem 文件中使用此 gem 'Instamojo-rb', '~> 1.1'
并使用捆绑更新。
所以对于版本 0.1,使用
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"})
对于 versino >= 1.0,使用
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"], ENV["INSTAMOJO_TOKEN"], "https://test.instamojo.com/api/1.1/")
我正在 rails 学习支付网关集成。 我选择了 insta mojo 并且正在工作,但他们提供的文档非常不方便且难以理解..
https://github.com/AnkurGel/Instamojo-rb#usage
我不知道在哪里设置我的 API 键
require 'Instamojo-rb'
api = Instamojo::API.new do |app|
app.api_key = "api_key-you-received-from-api@instamojo.com"
app.auth_token = "auth_token-you-received-from-api@instamojo.com"
end`
我在初始值设定项中尝试了 instamojo.rb 并尝试 运行 控制台,但它给出了不存在这样的方法的错误。
- 您可以将 require 语句放在 application.rb 或其他任何地方,以便在加载应用程序时加载该文件。
- 您可以制作 'Payment' 模型,您可以在其中制作验证和获取详细信息等方法。
在这些方法内部,您将创建 API 对象并使用上面的代码。
class Payment < ActiveRecord::Base def verify client = get_intamojo_client #Some code end def get_details client = get_intamojo_client #Some code end private def get_instamojo_client api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"}) return api.client end end
要探索使用客户端对象可以做什么,只需使用 rails 控制台并在那里创建一个客户端对象,然后使用 client.public_methods
并开始探索。
编辑:
我认为您使用的是 gem 的旧版本,即 0.1,他们的文档适用于 > 1.0 的版本。要更新,请在 gem 文件中使用此 gem 'Instamojo-rb', '~> 1.1'
并使用捆绑更新。
所以对于版本 0.1,使用
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"})
对于 versino >= 1.0,使用
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"], ENV["INSTAMOJO_TOKEN"], "https://test.instamojo.com/api/1.1/")