Skip to content

Instantly share code, notes, and snippets.

@sharmaparesh
Created June 12, 2018 09:49
Show Gist options
  • Save sharmaparesh/7e38f27d7a746dc77a709e2796ec38f2 to your computer and use it in GitHub Desktop.
Save sharmaparesh/7e38f27d7a746dc77a709e2796ec38f2 to your computer and use it in GitHub Desktop.
GMO Payment Gateway

Home: https://www.gmo-pg.com/en/

Contents:

  1. Register your company
  2. Install gem
  3. Generate token
  4. Managed accounts
  5. Make transactions

1 Register your company

To start accepting payments in test environment, you will need to register your company with GMO.

If the information given in the form is correct, then you will receive an email to confirm the registration.

After confirmation, you will get another email with urls, usernames and passwords for Site and Shop management screens.

Sample url for Site Management Screen - https://kt01.mul-pay.jp/mulpayconsole/site/tsite00025073/

On successful login, you will need to reset both the passwords.

Under Site management -> Site information, you will find the Site ID and Password.

site:
  id: tsite00025074
  password: 3hmhabb8

For Shop details, you can go to Site management -> Shop information and search for the shop you entered while registering on GMO.

Then clicking on the search result, you can access Shop ID and Password under Shop management -> Shop information.

shop:
  id: tshop00027679
  password: xrcg4vro

3 Generate token

Include the javascript based on your environnemt.

test: 'https://pt01.mul-pay.jp/ext/js/token.js'
production: 'https://p01.mul-pay.jp/ext/js/token.js'

Use Shop ID generated above to initialize the javascript library.

Multipayment.init(shop_id);
Multipayment.getToken({
  holdername: 'Abby Yarbro',
  cardno: '4111111111111111',           // card number without spaces
  expire: '201905',                     // expiry in format 'YYYYMM'
  securitycode: '123'
}, 'gmoResponseHandler');               // callback function should be a string only

function gmoResponseHandler(response) {
  if(repsonse.resultCode != '000') {
    // show error message
  } else {
    token = response.tokenObject.token;
    // use this token instead of card details to create transactions
  }
}

4 Managed accounts

This feature is available on a PR.

gmo = GMO::Payment::RemittanceAPI.new(shop_id: <Shop ID>,
                                      shop_pass: <Shop PASS>,
                                      host: 'test-remittance.gmopg.jp')

4.1 Create account

options = { bank_id: 'bank00001',
            bank_code: '0001',
            branch_code: '813',
            account_type: :normal,
            account_name: 'An Yutzy',
            account_number: '0012345' }

gmo.create_account(options)               # => {"Bank_ID"=>"bank00001", "Method"=>"1"}

You can get the correct combinations of Bank Code and Branch Code from below links:

account_type can be set to any one of the below:

  • :normal
  • :current
  • :savings

Additional options that you can pass to create_account method are:

  • free Use it to store some metadata on the API
  • branch_code_jp e.g. MHCBJPJT
  • account_number_jp e.g. 01234567

4.2 Retrieve account

response = gmo.search_account(bank_id: 'bank12345')     # => {"Bank_ID"=>"bank12345", "Bank_Name"=>"みずほ銀行",
                                                        #     "Bank_Code"=>"0001", "Branch_Name"=>"札幌支店",
                                                        #     "Branch_Code"=>"813", "Account_Type"=>"1",
                                                        #     "Account_Number"=>"0012345", "Account_Name"=>"An Yutzy",
                                                        #     "Free"=>"", "Branch_Code_Jpbank"=>"", "Account_Number_Jpbank"=>""}

4.3 Update account

options = { bank_id: 'bank00001',
            bank_code: '0001',
            branch_code: '813',
            account_type: :normal,
            account_name: 'An Yutzy',
            account_number: '0012345' }

gmo.update_account(options)               # => {"Bank_ID"=>"bank00001", "Method"=>"2"}

4.4 Delete account

options = { bank_id: 'bank00001' }
gmo.delete_account(options)               # => {"Bank_ID"=>"bank00001", "Method"=>"3"}

4.5 Create deposit

options = { bank_id: 'bank00000',
            deposit_id: 'dep00000',
            amount: '1000' }

gmo.create_deposit(options)             # => {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank00000",
                                        #     "Method"=>"1", "Amount"=>"1000", "Bank_Fee"=>"27"}

4.6 Retrieve deposit

gmo.search_deposit(deposit_id: 'dep00000')     # => {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank163144",
                                               #     "Bank_Name"=>"みずほ銀行", "Bank_Code"=>"0001", "Branch_Name"=>"札幌支店",
                                               #     "Branch_Code"=>"813", "Account_Type"=>"1", "Account_Number"=>"0012345",
                                               #     "Account_Name"=>"An Yutzy", "Free"=>"", "Amount"=>"181035",
                                               #     "Bank_Fee"=>"270", "Result"=>"0", "Branch_Code_Jpbank"=>"",
                                               #     "Account_Number_Jpbank"=>"", "Deposit_Date"=>"", "Result_Detail"=>""}

4.7 Cancel deposit

options = { bank_id: 'bank00000', deposit_id: 'dep00000' }
gmo.cancel_deposit(options)                     # => {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank00000", "Method"=>"2"}

4.8 Search balance

gmo.search_balance            # => {"Shop_ID"=>"rshop00000071", "Balance"=>"9818965", "Balance_Forecast"=>"9818965"}

4.9 Create mail deposit

options = { deposit_id: 'dep00001',
            deposit_email: '[email protected]',
            amount: 1000,
            deposit_account_name: 'An Yutzy',
            expire: 5,
            deposit_shop_email: '[email protected]' }

gmo.create_mail_deposit(options)         # => {"Deposit_ID"=>"dep00001", "Method"=>"1", "Amount"=>"1000", "Expire"=>"20170503"}

options[:expire] represents number of days in advance to allow registration, from 1 to 30.

4.10 Retrieve mail deposit

gmo.search_mail_deposit(deposit_id: 'dep00001')     # => {"Deposit_ID"=>"dep00001", "Mail_Address"=>"[email protected]",
                                                    #     "Shop_Mail_Address"=>"[email protected]", "Account_Name"=>"An Yutzy",
                                                    #     "Amount"=>"1000", "Expire"=>"20170503", "Status"=>"0"} 

4.11 Cancel mail deposit

options = { deposit_id: 'dep00001' }
gmo.cancel_mail_deposit(options)         # => {"Deposit_ID"=>"dep00001", "Method"=>"2"}

Back to Top

2 Install gem

We are using gem gmo to access the GMO Payment Gateway API.

# Gemfile
gem 'gmo', github: 't-k/gmo-payment-ruby', ref: 'bc1238116c9dbb3b35722d8c8eaf9fc79e44c218'

Run bundle install.

Back to File

Back to Top

5 Make transactions

Contents:

  1. Install gem
  2. ShopAndSiteAPI
  3. SiteAPI
  4. ShopAPI

5.1 Install gem

# Gemfile
gem 'gmo', github: 'JagdeepSingh/gmo-payment-ruby', branch: 'add-brandtoken-methods'

Run bundle install.

Back to File

Back to Top

5.2 ShopAndSiteAPI

Build an instance of GMO::Payment::ShopAndSiteAPI.

gmo_shop_site = GMO::Payment::ShopAndSiteAPI.new(host: 'p01.mul-pay.jp',
                                                 site_id: SITE_ID,
                                                 site_pass: SITE_PASSWORD,
                                                 shop_id: SHOP_ID,
                                                 shop_pass: SHOP_PASSWORD)
=> #<GMO::Payment::ShopAndSiteAPI:0x007f8a67976488 @shop_id=SHOP_ID, @shop_pass=SHOP_PASSWORD, @site_id=SITE_ID, @site_pass=SITE_PASSWORD, @host="p01.mul-pay.jp">

For test environment, use host kt01.mul-pay.jp.

5.2.1 ExecTranBrandtoken.idPass

gmo_shop_site.exec_tran_brandtoken(order_id: 'ord10001',
                                   access_id: '139f8ec33a07c55f406937c52ce4473d',
                                   access_pass: '2689b204d2c17192fa35f9269fa7e744',
                                   token_type: :apple_pay,
                                   token: <Base64 encoded payment data>,
                                   member_id: 'mem10001')
=> {"Status"=>"CAPTURE", "OrderID"=>"ord10001", "Forward"=>"2a99663", "Approve"=>"5487394", "TranID"=>"1707281634111111111111771216", "TranDate"=>"20170728163453", "ClientField1"=>"", "ClientField2"=>"", "ClientField3"=>""}

Maximum allowed length of order_id is 27 characters.

5.2.2 TradedBrandtoken.idPass

gmo_shop_site.trade_brandtoken(member_id: 'mem10001', order_id: 'ord10001')
=> {"TokenSeq"=>"0", "CardNoToken"=>"*************111", "Forward"=>"2a99663"}

Back to File

Back to Top

5.3 SiteAPI

Build instance of GMO::Payment::SiteAPI.

gmo_site = GMO::Payment::SiteAPI.new(host: 'p01.mul-pay.jp', site_id: SITE_ID, site_pass: SITE_PASSWORD)
=> #<GMO::Payment::SiteAPI:0x007f8a6af80448 @site_id=SITE_ID, @site_pass=SITE_PASS, @host="p01.mul-pay.jp">

For test environment, use host kt01.mul-pay.jp.

5.3.1 SaveMember.idPass

gmo_site.save_member(member_id: 'mem10001')
=> {"MemberID"=>"mem10001"}

5.3.2 SearchBrandtoken.idPass

gmo_site.search_brandtoken(member_id: '598066176120b2235300020b', seq_mode: 0)
=> {"TokenSeq"=>"0", "DefaultFlag"=>"0", "CardName"=>"", "CardNoToken"=>"*************111", "Expire"=>"2212", "HolderName"=>"", "DeleteFlag"=>"0"}

5.3.3 DeleteBrandtoken.idPass

gmo_site.delete_brandtoken(member_id: '598066176120b2235300020b', seq_mode: 0, token_seq: 0)
=> {"TokenSeq"=>"0"}

Back to File

Back to Top

5.4 ShopAPI

Build instance of GMO::Payment::ShopAPI.

gmo_shop = GMO::Payment::ShopAPI.new(host: 'p01.mul-pay.jp', shop_id: SHOP_ID, shop_pass: SHOP_PASSWORD)
=> #<GMO::Payment::ShopAPI:0x007fef42e2e350 @shop_id=SHOP_ID, @shop_pass=SHOP_PASSWORD, @host="p01.mul-pay.jp"> 

For test environment, use host kt01.mul-pay.jp.

5.4.1 EntryTranBrandtoken.idPass

entry_tran_response = gmo_shop.entry_tran_brandtoken(order_id: 'ord12345',
                                                     job_cd: 'AUTH',
                                                     item_code: '1000001',
                                                     tax: '0001001',
                                                     amount: 100)
=> {"AccessID"=>"139f8ec33a07c55f406937c52ce4473d", "AccessPass"=>"2689b204d2c17192fa35f9269fa7e744"}

5.4.2 ExecTranBrandtoken.idPass

gmo_shop.exec_tran_brandtoken(order_id: 'ord10001',
                              access_id: entry_tran_response['AccessID'],
                              access_pass: entry_tran_response['AccessPass'],
                              token_type: :apple_pay,
                              token: <Base64 encoded payment data>,
                              seq_mode: '1',
                              token_seq: 1001,
                              client_field_1: 'Custom field value 1',
                              client_field_2: 'Custom field value 2',
                              client_field_3: 'Custom field value 3')
=> {"Status"=>"AUTH", "OrderID"=>"ord10001", "Forward"=>"2a99663", "Approve"=>"5487394", "TranID"=>"1707281634111111111111771216", "TranDate"=>"20170728163453", "ClientField1"=>"Custom field value 1", "ClientField2"=>"Custom field value 2", "ClientField3"=>"Custom field value 3"}

5.4.3 SalesTranBrandtoken.idPass

gmo_shop.sales_tran_brandtoken(access_id: entry_tran_response['AccessID'],
                               access_pass: entry_tran_response['AccessPass'],
                               order_id: 'ord10001',
                               amount: 1000,
                               tax: '0001001')
=> {"AccessID"=>"139f8ec33a07c55f406937c52ce4473d", "AccessPass"=>"2689b204d2c17192fa35f9269fa7e744", "Status"=>"SALES", "Forward"=>"2a99663", "Approve"=>"5537883", "TranID"=>"1707311620111111111111771220", "TranDate"=>"20170731162256"}

5.4.4 ChangeTranBrandtoken.idPass

gmo_shop.change_tran_brandtoken(access_id: entry_tran_response['AccessID'],
                                access_pass: entry_tran_response['AccessPass'],
                                order_id: 'ord10001',
                                job_cd: 'CAPTURE',
                                amount: 2000)
=> {"AccessID"=>"21170701482c86c3b88ff72b83bfd363", "AccessPass"=>"51f36feba120de1e6e29532e5a3a5e3e", "Status"=>"CAPTURE", "Forward"=>"2a99663", "Approve"=>"5538477", "TranID"=>"1707311633111111111111771224", "TranDate"=>"20170731163343"}

5.4.5 VoidTranBrandtoken.idPass

gmo_shop.void_tran_brandtoken(access_id: entry_tran_response['AccessID'],
                              access_pass: entry_tran_response['AccessPass'],
                              order_id: 'ord10001')
=> {"AccessID"=>"139f8ec33a07c55f406937c52ce4473d", "AccessPass"=>"2689b204d2c17192fa35f9269fa7e744", "Status"=>"VOID", "Forward"=>"2a99663", "Approve"=>"5537590", "TranID"=>"1707311610111111111111771219", "TranDate"=>"20170731161007"}

5.4.6 RefundTranBrandtoken.idPass

gmo_shop.refund_tran_brandtoken(access_id: entry_tran_response['AccessID'],
                                access_pass: entry_tran_response['AccessPass'],
                                order_id: 'ord10001',
                                amount: 1000,
                                tax: '0001001')
=> {"AccessID"=>"139f8ec33a07c55f406937c52ce4473d", "AccessPass"=>"2689b204d2c17192fa35f9269fa7e744", "Status"=>"RETURN", "Forward"=>"2a99663", "Approve"=>"5537883", "TranID"=>"1707311620111111111111771220", "TranDate"=>"20170731162256"}

5.4.7 SearchTradeMulti.idPass

gmo_shop.search_trade_multi(order_id: '598066176120b2235300020b', pay_type: 27)
=> {"OrderID"=>"598066176120b2235300020b", "Status"=>"CAPTURE", "ProcessDate"=>"20170801202929", "JobCd"=>"CAPTURE", "AccessID"=>"228fc5bc02da46943300c12706d325a2", "AccessPass"=>"090a50ec2f77d92184a18018f07906e5", "ItemCode"=>"0000990", "Amount"=>"557", "Tax"=>"0", "SiteID"=>"", "MemberID"=>"", "CardNoToken"=>"************1111", "Expire"=>"2212", "Method"=>"1", "PayTimes"=>"", "Forward"=>"2a99663", "TranID"=>"1708012029111111111111771228", "Approve"=>"5689128", "ClientField1"=>"", "ClientField2"=>"", "ClientField3"=>"", "PayType"=>"27"}

Back to File

Back to Top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment