class WirecardSepa::Gateway
Usage: config = WirecardSepa::Config.new(...)
gateway = WirecardSepa::Gateway.new(config)
gateway.debit({ requested_amount: 12.12, .. })
> response¶ ↑
gateway.recurring_init
> response¶ ↑
Attributes
config[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 14 def initialize(config) @config = config end
Public Instance Methods
debit(params)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 18 def debit(params) request_params = add_auth_params_and_custom_fields(params) request_xml = DirectDebit::Request.new(request_params).to_xml DirectDebit::Response.for_request post(request_xml) end
recurring_init(params)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 24 def recurring_init(params) request_params = add_auth_params_and_custom_fields(params) request_xml = Recurring::FirstRequest.new(request_params).to_xml Recurring::FirstResponse.for_request post(request_xml) end
recurring_process(params)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 30 def recurring_process(params) request_params = params.merge({ merchant_account_id: config.merchant_account_id, request_id: request_id, }) request_xml = Recurring::RecurringRequest.new(request_params).to_xml Recurring::RecurringResponse.for_request post(request_xml) end
Private Instance Methods
add_auth_params_and_custom_fields(params)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 60 def add_auth_params_and_custom_fields(params) { custom_fields: {} }.merge(params).merge({ merchant_account_id: config.merchant_account_id, creditor_id: config.creditor_id, request_id: request_id }) end
http_auth_credentials()
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 79 def http_auth_credentials [config.http_auth_username, config.http_auth_password].join(':') end
post(request_xml)
click to toggle source
Wirecard API returns correct charset (UTF-8), but the resulting body is encoded in (ASCII-8BIT), so we enforce it.
# File lib/wirecard_sepa/gateway.rb, line 43 def post(request_xml) response = typhoeus_response(request_xml) if content_type = response.headers['Content-Type'] response.body.force_encoding content_type[/charset=(.*)/, 1] end response end
request_id()
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 68 def request_id # From the Wirecard processing spec: # Type: Alphanumeric, Length: 150 # This is the identification number of the request on the merchants side. # It must be unique for each request. # Sample Request-ID: 048b27e0-9c31-4cab-9eab-3b72b1b4d498 # SecureRandom.uuid # SecureRandom.uuid SecureRandom.uuid end
typhoeus_response(request_xml)
click to toggle source
# File lib/wirecard_sepa/gateway.rb, line 51 def typhoeus_response(request_xml) Typhoeus.post( config.api_url, body: request_xml, userpwd: http_auth_credentials, headers: { 'Content-Type' => 'application/xml' } ) end