Class: ActiveMerchant::Billing::Integrations::Sermepa::Helper
- Inherits:
-
Helper
- Object
- Helper
- ActiveMerchant::Billing::Integrations::Sermepa::Helper
- Includes:
- PostsData
- Defined in:
- lib/active_merchant/billing/integrations/sermepa/helper.rb
Overview
Sermepa/Servired Spanish Virtual POS Gateway
Support for the Spanish payment gateway provided by Sermepa, part of Servired, one of the main providers in Spain to Banks and Cajas.
Requires the :terminal_id, :commercial_id, and :secret_key to be set in the credentials before the helper can be used. Credentials may be overwriten when instantiating the helper if required or instead of the global variable. Optionally, the :key_type can also be set to either ‘sha1_complete’ or ‘sha1_extended’, where the later is the default case. This is a configurable option in the Sermepa admin which you may or may not be able to access. If nothing seems to work, try changing this.
Ensure the gateway is configured correctly. Synchronization should be set to Asynchronous and the parameters in URL option (Parámetros en las URLs) should be set to true unless the notify_url is provided. During development on localhost ensuring this option is set is especially important as there is no other way to confirm a successful purchase.
Your view for a payment form might look something like the following:
<%= payment_service_for @transaction.id, 'Company name', :amount => @transaction.amount, :currency => 'EUR', :service => :sermepa do |service| %>
<% service.description @sale.description %>
<% service.customer_name @sale.client.name %>
<% service.notify_url notify_sale_url(@sale) %>
<% service.success_url win_sale_url(@sale) %>
<% service.failure_url fail_sale_url(@sale) %>
<%= submit_tag "PAY!" %>
<% end %>
Class Attribute Summary collapse
-
.credentials ⇒ Object
Credentials should be set as a hash containing the fields: :terminal_id, :commercial_id, :secret_key, :key_type (optional).
Instance Method Summary collapse
- #amount=(money) ⇒ Object
-
#credentials ⇒ Object
Allow credentials to be overwritten if needed.
- #credentials=(creds) ⇒ Object
- #currency=(value) ⇒ Object
- #form_fields ⇒ Object
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
ammount should always be provided in cents!.
- #language=(lang) ⇒ Object
- #order=(order_id) ⇒ Object
-
#send_transaction ⇒ Object
Send a manual request for the currently prepared transaction.
- #transaction_type=(type) ⇒ Object
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
ammount should always be provided in cents!
70 71 72 73 74 75 76 77 78 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 70 def initialize(order, account, = {}) self.credentials = .delete(:credentials) if [:credentials] super(order, account, ) add_field 'Ds_Merchant_MerchantCode', credentials[:commercial_id] add_field 'Ds_Merchant_Terminal', credentials[:terminal_id] #add_field mappings[:transaction_type], '0' # Default Transaction Type self.transaction_type = :authorization end |
Class Attribute Details
.credentials ⇒ Object
Credentials should be set as a hash containing the fields:
:terminal_id, :commercial_id, :secret_key, :key_type (optional)
43 44 45 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 43 def credentials @credentials end |
Instance Method Details
#amount=(money) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 88 def amount=(money) cents = money.respond_to?(:cents) ? money.cents : money if money.is_a?(String) || cents.to_i <= 0 raise ArgumentError, 'money amount must be either a Money object or a positive integer in cents.' end add_field mappings[:amount], cents.to_i end |
#credentials ⇒ Object
Allow credentials to be overwritten if needed
81 82 83 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 81 def credentials @credentials || self.class.credentials end |
#credentials=(creds) ⇒ Object
84 85 86 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 84 def credentials=(creds) @credentials = (self.class.credentials || {}).dup.merge(creds) end |
#currency=(value) ⇒ Object
106 107 108 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 106 def currency=( value ) add_field mappings[:currency], Sermepa.currency_code(value) end |
#form_fields ⇒ Object
118 119 120 121 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 118 def form_fields add_field mappings[:signature], sign_request @fields end |
#language=(lang) ⇒ Object
110 111 112 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 110 def language=(lang) add_field mappings[:language], Sermepa.language_code(lang) end |
#order=(order_id) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 96 def order=(order_id) order_id = order_id.to_s if order_id !~ /^[0-9]{4}/ && order_id.length <= 8 order_id = ('0' * 4) + order_id end regexp = /^[0-9]{4}[0-9a-zA-Z]{0,8}$/ raise "Invalid order number format! First 4 digits must be numbers" if order_id !~ regexp add_field mappings[:order], order_id end |
#send_transaction ⇒ Object
Send a manual request for the currently prepared transaction. This is an alternative to the normal view helper and is useful for special types of transaction.
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 127 def send_transaction body = build_xml_request headers = { } headers['Content-Length'] = body.size.to_s headers['User-Agent'] = "Active Merchant -- http://activemerchant.org" headers['Content-Type'] = 'application/x-www-form-urlencoded' # Return the raw response data ssl_post(Sermepa.operations_url, "entrada="+CGI.escape(body), headers) end |
#transaction_type=(type) ⇒ Object
114 115 116 |
# File 'lib/active_merchant/billing/integrations/sermepa/helper.rb', line 114 def transaction_type=(type) add_field mappings[:transaction_type], Sermepa.transaction_code(type) end |