Class: ActiveMerchant::Billing::OmiseGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/omise.rb

Constant Summary

API_VERSION =
'1.0'
API_URL =
'https://api.omise.co/'
VAULT_URL =
'https://vault.omise.co/'
STANDARD_ERROR_CODE_MAPPING =
{
  'invalid_security_code' => STANDARD_ERROR_CODE[:invalid_cvc],
  'failed_capture'        => STANDARD_ERROR_CODE[:card_declined]
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

card_brand, #card_brand, #generate_unique_id, inherited, non_fractional_currency?, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ OmiseGateway

Creates a new OmiseGateway.

Omise requires public_key for token creation. And it requires secret_key for other transactions. These keys can be found in dashboard.omise.co/test/api-keys

Options

  • :public_key – Omise's public key (REQUIRED).

  • :secret_key – Omise's secret key (REQUIRED).



46
47
48
49
50
51
# File 'lib/active_merchant/billing/gateways/omise.rb', line 46

def initialize(options={})
  requires!(options, :public_key, :secret_key)
  @public_key = options[:public_key]
  @secret_key = options[:secret_key]
  super
end

Instance Method Details

#authorize(money, payment_method, options = {}) ⇒ Object

Authorize a charge.

Parameters

  • money – The purchasing amount in Thai Baht Satang

  • payment_method – The CreditCard object

  • options – An optional parameters, such as token or capture



90
91
92
93
# File 'lib/active_merchant/billing/gateways/omise.rb', line 90

def authorize(money, payment_method, options={})
  options[:capture] = 'false'
  create_charge(money, payment_method, options)
end

#capture(money, charge_id, options = {}) ⇒ Object

Capture an authorized charge.

Parameters

  • money – An amount in Thai Baht Satang

  • charge_id – The CreditCard object

  • options – An optional parameters, such as token or capture



103
104
105
106
107
# File 'lib/active_merchant/billing/gateways/omise.rb', line 103

def capture(money, charge_id, options={})
  post = {}
  add_amount(post, money, options)
  commit(:post, "charges/#{CGI.escape(charge_id)}/capture", post, options)
end

#purchase(money, payment_method, options = {}) ⇒ Object

Perform a purchase (with auto capture)

Parameters

  • money – The purchasing amount in Thai Baht Satang

  • payment_method – The CreditCard object

  • options – An optional parameters, such as token from Omise.js

Options

  • token_id – token id, use Omise.js library to retrieve a token id

if this is passed as an option, it will ignore tokenizing via Omisevaultgateway object

Example

To create a charge on a card

 purchase(money, Creditcard_object)

To create a charge on a token

 purchase(money, nil, { :token_id => token_id, ... })

To create a charge on a customer

 purchase(money, nil, { :customer_id => customer_id })


78
79
80
# File 'lib/active_merchant/billing/gateways/omise.rb', line 78

def purchase(money, payment_method, options={})
  create_charge(money, payment_method, options)
end

#refund(money, charge_id, options = {}) ⇒ Object

Refund a charge.

Parameters

  • money – An amount of money to charge in Satang.

  • charge_id – The CreditCard object

  • options – An optional parameters, such as token or capture



117
118
119
120
# File 'lib/active_merchant/billing/gateways/omise.rb', line 117

def refund(money, charge_id, options={})
  options[:amount] = money if money
  commit(:post, "charges/#{CGI.escape(charge_id)}/refunds", options)
end

#scrub(transcript) ⇒ Object

Scrub sensitive information out of HTTP transcripts

Parameters

  • transcript – The HTTP transcripts



159
160
161
162
163
164
# File 'lib/active_merchant/billing/gateways/omise.rb', line 159

def scrub(transcript)
  transcript.
    gsub(/(Authorization: Basic )\w+/i, '\1[FILTERED]').
    gsub(/(\\"number\\":)\\"\d+\\"/, '\1[FILTERED]').
    gsub(/(\\"security_code\\":)\\"\d+\\"/,'\1[FILTERED]')
end

#store(payment_method, options = {}) ⇒ Object

Store a card details as customer

Parameters

  • payment_method – The CreditCard.

  • options – Optional Customer information:

    'email'       (A customer email)
    'description' (A customer description)
    


131
132
133
134
135
136
# File 'lib/active_merchant/billing/gateways/omise.rb', line 131

def store(payment_method, options={})
  post, card_params = {}, {}
  add_customer_data(post, options)
  add_token(card_params, payment_method, options)
  commit(:post, 'customers', post.merge(card_params), options)
end

#supports_scrubbing?Boolean

Enable scrubbling sensitive information



149
150
151
# File 'lib/active_merchant/billing/gateways/omise.rb', line 149

def supports_scrubbing?
  true
end

#unstore(customer_id, options = {}) ⇒ Object

Delete a customer and all associated credit cards.

Parameters

  • customer_id – The Customer identifier (REQUIRED).



144
145
146
# File 'lib/active_merchant/billing/gateways/omise.rb', line 144

def unstore(customer_id, options={})
  commit(:delete, "customers/#{CGI.escape(customer_id)}")
end