diff --git a/README.md b/README.md index 49b4c8a..cc0dddb 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,20 @@ Or install it yourself as: ## Usage -1. Initialization : `LemonWay::Client.new(api_params, client_config_options, &client_config_block)` - - `api_options` (Hash) : mandatory hash where are passed the api param you want to reapeat every client query + the `:wsdl` uri - - `client_config_options` (Hash) : optional hash passed to savon to build its [global options](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) used by the client on every query - - `client_config_block` (Block) : optional block to customize the savon client, takes a [savon global options](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) instance as param +1. Initialization : `LemonWay::Client.new(api_params, client_config_options, &client_config_block)` + - `api_options` (Hash) : mandatory hash where are passed the api param you want to reapeat every client query + the `:wsdl` uri + - `client_config_options` (Hash) : optional hash passed to savon to build its [global options](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) used by the client on every query + - `client_config_block` (Block) : optional block to customize the savon client, takes a [savon global options](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) instance as param ```ruby client = LemonWay::Client.new({wsdl: "https://ws.lemonway.fr/[...]/service.asmx?wsdl"}, {ssl_verify_mode: :none}) #is the same as client = LemonWay::Client.new wsdl: "https://ws.lemonway.fr/[...]/service.asmx?wsdl" do |opts| opts.ssl_verify_mode(:none) -end +end ``` - + 2. Query the API directly calling the method on the client instance : `client.api_method_name(params, client_config_override, &client_block_config_override)` - - `api_method_name` : Lemonway underscorized mehtod name (refer to the Lemonway doc or to `client.operations` to list them + - `api_method_name` : Lemonway underscorized mehtod name (refer to the Lemonway doc or to `client.operations` to list them - `params` (Hash) : params sent to the api, keys will be camelcased to comply with the SOAP convention used by Lemonway - `client_config_override` (Hash) : A hash of config transmitted to the savon client, which overrides the [savon global config](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) for the current api call only - `client_block_config_override` (Block) : A Block taking a [savon global options](https://github.com/savonrb/savon/blob/master/lib/savon/options.rb) instance as param, to override the client call configuration options @@ -44,36 +44,112 @@ end ```ruby # initialize the client -client = LemonWay::Client.new wsdl: "https://ws.lemonway.fr/mb/ioio/dev/directkit/service.asmx?wsdl", + # at the end of url the `?wsdl` is realy important +# config/initializers/lemonway.rb +CLIENT_LEMON = Lemonway::Client.new wsdl: "https://ws.lemonway.fr/mb/ioio/dev/directkit/service.asmx?wsdl", wl_login: "test", wl_pass: "test", language: "fr", - version: "1.1", - wallet_ip: "127.0.0.1" - -# list the available operations as follow : -resp = client.operations -=> [:register_wallet, - :update_wallet_details, - :update_wallet_status, - :register_iban, - :register_sdd_mandate, - :register_card, - ... - ] + version: "1.1" + +# list the available operations as follow : + CLIENT_LEMON.operations + => [:register_wallet, + :update_wallet_details, + :update_wallet_status, + :register_iban, + :register_sdd_mandate, + :register_card, + ... + ] + + # requests takes underscored names, and undescored (or camelcased) options, some hash with indifferent access are returned -resp = client.register_wallet, wallet: "123", - client_mail: "nico@las.com", - client_first_name: "nicolas", - client_last_name: "nicolas", - wallet_ip: "127.0.0.1" -=> {id: '123', lwid: "98098"} -resp[:id] == resp['id'] == '123' + +# You need to send the IP of your client, to have it available everywhere do : + # application_controller + + before_filter :get_request + + def get_request + $request = request + end + + +# models/user + after_create :create_lw_account + + private + def create_lw_account + resp = CLIENT_LEMON = client.register_wallet(wallet: "123", + clientMail: "nico@las.com", + clientFirstName: "nicolas", + clientLastName: "nicolas", + payerOrBeneficiary: 1, + wallet_ip: $request.remote_ip, + ) + => {id: '123', lwid: "98098"} + + # Save the lwid in database + resp[:id] == resp['id'] == '123' + user = self.update(lwid: resp[:id]) + ######################## + # Save the :id and not the :lwid, because it's this one that you need for the call after # + ########################## + end + + +``` + +```ruby +# Wallet option : + # Get wallet details + CLIENT_LEMON.get_wallet_details(wallet: 'id(string)', email:"email(string)") + ``` -Please refer to the Lemonway documentation for the complete list of methods and their parameters, or query https://ws.lemonway.fr/mb/[YOUR_LEMONWAY_NAME]/dev/directkitxml/service.asmx if Lemonway has provided you a development account +```ruby + # For crowdfunding + # Create like classic user, but add need option, exemple : Debtor, (value = 1 if debtor) (example for project) + + + def contribution + # First initialise the webkit + + fill_user_wallet = CLIENT_LEMON.money_in_web_init( + wallet: current_user.lwid, + amountTot: @contribution.amount.to_f, + wkToken: @contribution.id, + returnUrl: after_payment_url, + errorUrl: after_payment_url, + cancelUrl: after_payment_url, + autoCommission: 0, + wallet_ip: $request.remote_ip) + + # define in your routes.rb the root of after_payment + + # Then call the webkit : + + redirect_to(ENV['LW_WEBKIT'] + "?moneyInToken=#{fill_user_wallet[:moneyinweb][:token]}") + end + + # And after_payment : + + def after_payment + CLIENT_LEMON.get_money_in_trans_details(transactionMerchantToken: params[:response_wkToken], wallet_ip: $request.remote_ip) + + # redirect where you want + end + + +``` + + + + +Please refer to the Lemonway documentation for the complete list of methods and their parameters, or query https://ws.lemonway.fr/mb/[YOUR_LEMONWAY_NAME]/dev/directkitxml/service.asmx if Lemonway has provided you a development account ## Contributing diff --git a/lib/lemonway/client.rb b/lib/lemonway/client.rb index 329ab56..70edf37 100644 --- a/lib/lemonway/client.rb +++ b/lib/lemonway/client.rb @@ -5,15 +5,22 @@ module Lemonway class Client - class Error < StandardError; end + class Error < StandardError + attr_reader :code + + def initialize(code: nil, message:) + super(message) + @code = code + end + end attr_accessor :instance def initialize api_opts={}, client_opts={}, &block [api_opts, client_opts].each(&:symbolize_keys!) - @xml_mini_backend = client_opts.delete(:xml_mini_backend) || ActiveSupport::XmlMini_REXML - @entity_expansion_text_limit = client_opts.delete(:entity_expansion_text_limit) || 10**20 + @xml_mini_backend = client_opts.delete(:xml_mini_backend) || ActiveSupport::XmlMini_REXML + @entity_expansion_text_limit = client_opts.delete(:entity_expansion_text_limit) || 10**20 @instance = Savon.client client_opts.update(wsdl: api_opts.delete(:wsdl)), &block @@ -42,7 +49,7 @@ def client_call method_name, message_opts = {}, client_opts = {}, &block result = result.underscore_keys(true).with_indifferent_access if result.key?(:e) - raise Error, [result.fetch(:e).try(:fetch, :code), result.fetch(:e).try(:fetch, :msg)].join(' : ') + raise Error, code: result.fetch(:e).try(:fetch, :code), message: result.fetch(:e).try(:fetch, :msg) elsif result.key?(:trans) result[:trans].fetch(:hpay, result[:trans]) elsif result.key?(:wallet) @@ -53,7 +60,7 @@ def client_call method_name, message_opts = {}, client_opts = {}, &block rescue KeyError => e #todo improve this message - raise Error, "#{e.message}, expected `#{method_name}_response.#{method_name}_result` but got : #{resp.body.inspect}" + raise Error, message: "#{e.message}, expected `#{method_name}_response.#{method_name}_result` but got : #{resp.body.inspect}" end # work around for diff --git a/lib/lemonway/version.rb b/lib/lemonway/version.rb index 9cc407d..76b4499 100644 --- a/lib/lemonway/version.rb +++ b/lib/lemonway/version.rb @@ -1,4 +1,3 @@ module Lemonway - VERSION = "1.0.1" - + VERSION = "1.0.3" end