Class: ActiveMerchant::Billing::OmiseGateway
- Defined in:
- lib/active_merchant/billing/gateways/omise.rb
Constant Summary collapse
- 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
Instance Method Summary collapse
-
#authorize(money, payment_method, options = {}) ⇒ Object
Authorize a charge.
-
#capture(money, charge_id, options = {}) ⇒ Object
Capture an authorized charge.
-
#initialize(options = {}) ⇒ OmiseGateway
constructor
Creates a new OmiseGateway.
-
#purchase(money, payment_method, options = {}) ⇒ Object
Perform a purchase (with auto capture).
-
#refund(money, charge_id, options = {}) ⇒ Object
Refund a charge.
-
#scrub(transcript) ⇒ Object
Scrub sensitive information out of HTTP transcripts.
-
#store(payment_method, options = {}) ⇒ Object
Store a card details as customer.
-
#supports_scrubbing? ⇒ Boolean
Enable scrubbling sensitive information.
-
#unstore(customer_id, options = {}) ⇒ Object
Delete a customer and all associated credit cards.
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
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(={}) requires!(, :public_key, :secret_key) @public_key = [:public_key] @secret_key = [: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 (money, payment_method, ={}) [:capture] = 'false' create_charge(money, payment_method, ) 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, ={}) post = {} add_amount(post, money, ) commit(:post, "charges/#{CGI.escape(charge_id)}/capture", post, ) 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, ={}) create_charge(money, payment_method, ) 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, ={}) [:amount] = money if money commit(:post, "charges/#{CGI.escape(charge_id)}/refunds", ) 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, ={}) post, card_params = {}, {} add_customer_data(post, ) add_token(card_params, payment_method, ) commit(:post, 'customers', post.merge(card_params), ) 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, ={}) commit(:delete, "customers/#{CGI.escape(customer_id)}") end |