Class: ActiveMerchant::Billing::OmiseGateway

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

Constant Summary collapse

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::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, 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).

  • :api_version – Omise’s API Version (OPTIONAL), default version is ‘2014-07-27’

    See version at page https://dashboard.omise.co/api-version/edit
    


49
50
51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/omise.rb', line 49

def initialize(options={})
  requires!(options, :public_key, :secret_key)
  @public_key  = options[:public_key]
  @secret_key  = options[:secret_key]
  @api_version = options[:api_version]
  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



94
95
96
97
# File 'lib/active_merchant/billing/gateways/omise.rb', line 94

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



107
108
109
110
111
# File 'lib/active_merchant/billing/gateways/omise.rb', line 107

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 })


82
83
84
# File 'lib/active_merchant/billing/gateways/omise.rb', line 82

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



121
122
123
124
# File 'lib/active_merchant/billing/gateways/omise.rb', line 121

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



163
164
165
166
167
168
# File 'lib/active_merchant/billing/gateways/omise.rb', line 163

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)
    


135
136
137
138
139
140
# File 'lib/active_merchant/billing/gateways/omise.rb', line 135

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 scrubbing sensitive information

Returns:

  • (Boolean)


153
154
155
# File 'lib/active_merchant/billing/gateways/omise.rb', line 153

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).



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

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