Class: ActiveMerchant::Billing::MigsGateway
- Includes:
- MigsCodes
- Defined in:
- lib/active_merchant/billing/gateways/migs.rb
Constant Summary collapse
- API_VERSION =
1
Constants included from MigsCodes
ActiveMerchant::Billing::MigsCodes::CARD_TYPES, ActiveMerchant::Billing::MigsCodes::ISSUER_RESPONSE_CODES, ActiveMerchant::Billing::MigsCodes::TXN_RESPONSE_CODES, ActiveMerchant::Billing::MigsCodes::VERIFIED_3D_CODES
Constants inherited from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS
Instance Attribute Summary
Attributes inherited from Gateway
Instance Method Summary collapse
-
#capture(money, authorization, options = {}) ⇒ Object
Options.
- #credit(money, authorization, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MigsGateway
constructor
Creates a new MigsGateway The advanced_login/advanced_password fields are needed for advanced methods such as the capture, refund and status methods.
-
#purchase(money, creditcard, options = {}) ⇒ Object
(also: #authorize)
Options.
-
#purchase_offsite_response(data) ⇒ Object
Parses a response from purchase_offsite_url once user is redirected back.
-
#purchase_offsite_url(money, options = {}) ⇒ Object
Generates a URL to redirect user to MiGS to process payment Once user is finished MiGS will redirect back to specified URL With a response hash which can be turned into a Response object with purchase_offsite_response.
-
#refund(money, authorization, options = {}) ⇒ Object
Options.
-
#status(unique_id) ⇒ Object
Checks the status of a previous transaction This can be useful when a response is not received due to network issues.
- #test? ⇒ Boolean
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?
Methods included from CreditCardFormatting
Constructor Details
#initialize(options = {}) ⇒ MigsGateway
Creates a new MigsGateway The advanced_login/advanced_password fields are needed for advanced methods such as the capture, refund and status methods
Options
-
:login
– The MiGS Merchant ID (REQUIRED) -
:password
– The MiGS Access Code (REQUIRED) -
:secure_hash
– The MiGS Secure Hash
(Required for Server Hosted payments)
-
:advanced_login
– The MiGS AMA User -
:advanced_password
– The MiGS AMA User’s password
47 48 49 50 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 47 def initialize( = {}) requires!(, :login, :password) super end |
Instance Method Details
#capture(money, authorization, options = {}) ⇒ Object
Options
-
:unique_id
– A unique id for this request (Max 40 chars).
If not supplied one will be generated.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 77 def capture(money, , = {}) requires!(@options, :advanced_login, :advanced_password) post = .merge(:TransNo => ) post[:Amount] = amount(money) add_advanced_user(post) add_standard_parameters('capture', post, [:unique_id]) commit(post) end |
#credit(money, authorization, options = {}) ⇒ Object
103 104 105 106 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 103 def credit(money, , = {}) deprecated CREDIT_DEPRECATION_MESSAGE refund(money, , ) end |
#purchase(money, creditcard, options = {}) ⇒ Object Also known as:
Options
-
:order_id
– A reference for tracking the order (REQUIRED) -
:unique_id
– A unique id for this request (Max 40 chars).
If not supplied one will be generated.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 57 def purchase(money, creditcard, = {}) requires!(, :order_id) post = {} post[:Amount] = amount(money) add_invoice(post, ) add_creditcard(post, creditcard) add_standard_parameters('pay', post, [:unique_id]) commit(post) end |
#purchase_offsite_response(data) ⇒ Object
Parses a response from purchase_offsite_url once user is redirected back
Parameters
-
data
– All params when offsite payment returns
e.g. returns to company.com/return?a=1&b=2, then input “a=1&b=2”
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 168 def purchase_offsite_response(data) requires!(@options, :secure_hash) response_hash = parse(data) expected_secure_hash = calculate_secure_hash(response_hash.reject{|k, v| k == :SecureHash}, @options[:secure_hash]) unless response_hash[:SecureHash] == expected_secure_hash raise SecurityError, "Secure Hash mismatch, response may be tampered with" end response_object(response_hash) end |
#purchase_offsite_url(money, options = {}) ⇒ Object
Generates a URL to redirect user to MiGS to process payment Once user is finished MiGS will redirect back to specified URL With a response hash which can be turned into a Response object with purchase_offsite_response
Options
-
:order_id
– A reference for tracking the order (REQUIRED) -
:locale
– Change the language of the redirected page Values are 2 digit locale, e.g. en, es -
:return_url
– the URL to return to once the payment is complete -
:card_type
– Providing this skips the card type step. Values are ActiveMerchant formats: e.g. master, visa, american_express, diners_club -
:unique_id
– Unique id of transaction to find. If not supplied one will be generated.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 141 def purchase_offsite_url(money, = {}) requires!(, :order_id, :return_url) requires!(@options, :secure_hash) post = {} post[:Amount] = amount(money) add_invoice(post, ) add_creditcard_type(post, [:card_type]) if [:card_type] post.merge!( :Locale => [:locale] || 'en', :ReturnURL => [:return_url] ) add_standard_parameters('pay', post, [:unique_id]) add_secure_hash(post) self.server_hosted_url + '?' + post_data(post) end |
#refund(money, authorization, options = {}) ⇒ Object
Options
-
:unique_id
– A unique id for this request (Max 40 chars).
If not supplied one will be generated.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 92 def refund(money, , = {}) requires!(@options, :advanced_login, :advanced_password) post = .merge(:TransNo => ) post[:Amount] = amount(money) add_advanced_user(post) add_standard_parameters('refund', post, [:unique_id]) commit(post) end |
#status(unique_id) ⇒ Object
Checks the status of a previous transaction This can be useful when a response is not received due to network issues
Parameters
-
unique_id
– Unique id of transaction to find. This is the value of the option supplied in other methods or if not supplied is returned with key :MerchTxnRef
116 117 118 119 120 121 122 123 124 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 116 def status(unique_id) requires!(@options, :advanced_login, :advanced_password) post = {} add_advanced_user(post) add_standard_parameters('queryDR', post, unique_id) commit(post) end |
#test? ⇒ Boolean
181 182 183 |
# File 'lib/active_merchant/billing/gateways/migs.rb', line 181 def test? @options[:login].start_with?('TEST') end |