Class: ActiveMerchant::Billing::OmiseGateway
- 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
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 scrubbing sensitive information.
-
#unstore(customer_id, options = {}) ⇒ Object
Delete a customer and all associated credit cards.
Methods inherited from Gateway
#add_field_to_post_if_present, #add_fields_to_post_if_present, #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, #strftime_yyyymm
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( = {}) requires!(, :public_key, :secret_key) @public_key = [:public_key] @secret_key = [:secret_key] @api_version = [: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 (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
107 108 109 110 111 |
# File 'lib/active_merchant/billing/gateways/omise.rb', line 107 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 })
82 83 84 |
# File 'lib/active_merchant/billing/gateways/omise.rb', line 82 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
121 122 123 124 |
# File 'lib/active_merchant/billing/gateways/omise.rb', line 121 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
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, = {}) 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 scrubbing sensitive information
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, = {}) commit(:delete, "customers/#{CGI.escape(customer_id)}") end |