ActiveMerchant::Epsilon

Gem Build Status

Epsilon integration for ActiveMerchant.

Installation

Add this line to your application's Gemfile:

gem 'active_merchant-epsilon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_merchant-epsilon

Usage

Settings

An example Rails initializer would look something like this:

ActiveMerchant::Billing::Base.mode = :production
ActiveMerchant::Billing::EpsilonGateway.contract_code = '12345678'
ActiveMerchant::Billing::EpsilonGateway.proxy_port = 8080
ActiveMerchant::Billing::EpsilonGateway.proxy_address = 'myproxy.dev'

CreditCard Payment

require 'active_merchant'

ActiveMerchant::Billing::Base.mode = :test

ActiveMerchant::Billing::EpsilonGateway.contract_code = 'YOUR_CONTRACT_CODE'

gateway = ActiveMerchant::Billing::EpsilonGateway.new

amount = 10000

ActiveMerchant::Billing::CreditCard.require_verification_value = true

credit_card = ActiveMerchant::Billing::CreditCard.new(
  first_name:         'TARO',
  last_name:          'YAMADA',
  number:             '4242424242424242',
  month:              '10',
  year:               Time.now.year + 1,
  verification_value: '000', # security code
)

purchase_detail = {
  user_id:      'YOUR_APP_USER_IDENTIFIER',
  user_name:    '山田 太郎',
  user_email:   '[email protected]',
  item_code:    'ITEM001',
  item_name:    'Greate Product',
  order_number: 'UNIQUE ORDER NUMBER',
  memo1:        'memo1',
  memo2:        'memo2',
}

if credit_card.validate.empty?
  # Capture 10000 yen from the credit card
  response = gateway.purchase(amount, credit_card, purchase_detail)

  if response.success?
    puts "Successfully charged #{amount} yen to the credit card #{credit_card.display_number}"
  else
    raise StandardError, response.message
  end
end

CreditCard Payment with 3D secure

amount = 10000

ActiveMerchant::Billing::CreditCard.require_verification_value = true

credit_card = ActiveMerchant::Billing::CreditCard.new(
  first_name:         'TARO',
  last_name:          'YAMADA',
  number:             '4242424242424242',
  month:              '10',
  year:               Time.now.year + 1,
  verification_value: '000', # security code
)

purchase_detail = {
  user_id:                   'YOUR_APP_USER_IDENTIFIER',
  user_name:                 '山田 太郎',
  user_email:                '[email protected]',
  item_code:                 'ITEM001',
  item_name:                 'Greate Product',
  order_number:              'UNIQUE ORDER NUMBER',
  three_d_secure_check_code: 1,
  memo1:                     'memo1',
  memo2:                     'memo2',
}

if credit_card.validate.empty?
  response = gateway.purchase(amount, credit_card, purchase_detail)

  raise StandardError, response.message unless response.success?

  if response.params['three_d_secure']
    puts response.params['acs_url']
    puts response.params['pareq']
  else
    # NOT 3D SECURE
    puts "Successfully charged #{amount} yen to the credit card #{credit_card.display_number}"
  end
end

# (The card holder identifies himself on credit card's page and comes back here)

# AND SECOND REQUEST

response = gateway.authenticate(
  order_number:         'ORDER NUMBER',
  three_d_secure_pares: 'PAYMENT AUTHENTICATION RESPONSE',
)

if response.success?
  puts "Successfully charged to the credit card"
else
  raise StandardError, response.message
end

CreditCard Installment Payment

# (snip)

purchase_detail = {
  user_id:      'YOUR_APP_USER_IDENTIFIER',
  user_name:    '山田 太郎',
  user_email:   '[email protected]',
  item_code:    'ITEM001',
  item_name:    'Greate Product',
  order_number: 'UNIQUE ORDER NUMBER',
  credit_type:  ActiveMerchant::Billing::EpsilonGateway::CreditType::INSTALLMENT,
  payment_time: 3, # 3, 5, 6, 10, 12, 15, 18, 20, 24
  memo1:        'memo1',
  memo2:        'memo2',
}

# (snip)

CreditCard Revolving Payment

# (snip)

purchase_detail = {
  user_id:      'YOUR_APP_USER_IDENTIFIER',
  user_name:    '山田 太郎',
  user_email:   '[email protected]',
  item_code:    'ITEM001',
  item_name:    'Greate Product',
  order_number: 'UNIQUE ORDER NUMBER',
  credit_type:  ActiveMerchant::Billing::EpsilonGateway::CreditType::REVOLVING,
  memo1:        'memo1',
  memo2:        'memo2',
}

# (snip)

Convenience Store Payment

ActiveMerchant::Billing::EpsilonConvenienceStoreGateway.contract_code = 'YOUR_CONTRACT_CODE'

gateway = ActiveMerchant::Billing::EpsilonConvenienceStoreGateway.new

convenience_store = ActiveMerchant::Billing::ConvenienceStore.new(
  code:           ActiveMerchant::Billing::ConvenienceStore::Code::LAWSON,
  full_name_kana: 'ヤマダ タロウ',
  phone_number:   '0312345678'
)

purchase_detail = {
  user_id:      'YOUR_APP_USER_IDENTIFIER',
  user_name:    '山田 太郎',
  user_email:   '[email protected]',
  item_code:    'ITEM001',
  item_name:    'Greate Product',
  order_number: 'UNIQUE ORDER NUMBER',
  memo1:        'memo1',
  memo2:        'memo2',
}

if credit_card.validate.empty?
  # 10000 yen as convenience store paymet
  response = gateway.purchase(amount, convenience_store, purchase_detail)

  if response.success?
    puts "Successfully charged #{amount} yen as convenience store payment"
    puts "Receipt number is #{response.params['receipt_number']}"
    puts "Payment limit date is #{response.params['convenience_store_limit_date']}"
  else
    raise StandardError, response.message
  end
end

Recurring Billing (Monthly subscriptions)

purchase_detail[:mission_code] = ActiveMerchant::Billing::EpsilonGateway::MissionCode::RECURRING_6

gateway.recurring(amount, creadit_card, purchase_detail)

Cancel recurring billing

gateway.cancel_recurring(user_id: 'user_id', item_code: 'item_code')

Void Transaction

gateway.void('order_number')

Verify Credit Card

gateway.verify(credit_card, user_id: 'user_id', user_email: '[email protected]')

GMO ID Settlement

ActiveMerchant::Billing::EpsilonGmoIdGateway.contract_code = 'YOUR_CONTRACT_CODE'

gateway = ActiveMerchant::Billing::EpsilonGmoIdGateway.new

amount = 10000

purchase_detail = {
  user_id:      'YOUR_APP_USER_IDENTIFIER',
  user_email:   '[email protected]',
  user_name:    'YAMADA TARO',
  item_code:    'ITEM001',
  item_name:    'Golden Product',
  order_number: 'UNIQUE ORDER NUMBER',
  gmo_id:       'Your member id of GMO ID',
  gmo_card_id:  'Your sequential card number of GMO ID',
}

gateway.purchase(amount, purchase_detail)

GMO ID Settlement Void Transaction

gateway.void('order_number')

Error handling

If epsilon server returns status excepted 200, #purchase method raise ActiveMerchant::ResponseError.

When your request parameters are wrong(e.g. contract_code), the method returns failure response.

  • #success? returns false
  • #params has error detail
response = gateway.purchase(10000, creadit_card, invalid_detail)

response.success? # => false
response.params   # => Hash included error detail

Contributing

  1. Create your feature branch (git checkout -b my-new-feature)
  2. Commit your changes (git commit -am 'Add some feature')
  3. Push to the branch (git push origin my-new-feature)
  4. Create a new Pull Request