class Sofort::Client
Public Class Methods
new()
click to toggle source
# File lib/sofort/client.rb, line 11 def initialize @options = {} @options[:basic_auth] = { username: Sofort.user_id, password: Sofort.api_key } @options[:headers] = { 'Accept' => 'application/xml', 'Content-Type' => 'application/xml' } end
Public Instance Methods
details(token)
click to toggle source
# File lib/sofort/client.rb, line 30 def details(token) xml = details_xml(token) results = self.class.post(Sofort.base_url, @options.merge(body: xml)) transactions = results['transactions'] if transactions && transactions['transaction_details'] transactions['transaction_details'] else results end end
details_xml(token)
click to toggle source
# File lib/sofort/client.rb, line 41 def details_xml(token) <<-eos <transaction_request version="2"> <transaction>#{token}</transaction> </transaction_request> eos end
pay(amount, name, *args)
click to toggle source
# File lib/sofort/client.rb, line 23 def pay(amount, name, *args) opts = args.extract_options!.symbolize_keys! xml = pay_xml(amount, name, opts) results = self.class.post(Sofort.base_url, @options.merge(body: xml)) results['new_transaction'].present? ? results['new_transaction'] : results end
pay_xml(amount, name, opts)
click to toggle source
# File lib/sofort/client.rb, line 49 def pay_xml(amount, name, opts) reason = opts[:reason] || Sofort.reason currency_code = opts[:currency_code] || Sofort.currency_code country_code = opts[:country_code] || Sofort.country_code success_url = opts[:success_url] || Sofort.success_url abort_url = opts[:abort_url] || Sofort.abort_url email_customer = opts[:email_customer] || Sofort.email_customer language_code = opts[:language_code] || Sofort.language_code notification_email = opts[:notification_email] || Sofort.notification_email notification_url = opts[:notification_url] || Sofort.notification_url user_variable = opts[:user_variable] || Sofort.user_variable project_id = opts[:project_id] || Sofort.project_id { amount: amount, currency_code: currency_code, language_code: language_code, reasons: { reason: reason }, sender: { holder: name, country_code: country_code }, email_customer: email_customer, user_variables: { user_variable: user_variable }, notification_emails: { notification_email: notification_email }, notification_urls: { notification_url: notification_url }, success_url: success_url, abort_url: abort_url, su: '', project_id: project_id }.to_xml(root: 'multipay', skip_types: true, dasherize: false) end