No release in over a year
Ruby Wrapper for Midtrans Payment API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 1.10
>= 0
~> 10.0
>= 0

Runtime

 Project Readme

midtrans_api_ruby

Midtrans API client library for Ruby

Installation

Add this line to your application's Gemfile:

gem 'mekari-midtrans-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mekari-midtrans-api

Usage

Build client

require 'midtrans_api'

midtrans = MidtransApi::Client.new(
  client_key: 'YOUR-CLIENT-KEY',
  server_key: 'YOUR-SERVER-KEY',
  sandbox: true|false
  notification_url: 'https://example.com/callback'
)

# or

midtrans = MidtransApi::Client.new do |client|
  client.client_key = 'YOUR-CLIENT-KEY'
  client.server_key = 'YOUR-SERVER-KEY'
  client.sandbox_mode = true|false
  client.notification_url = 'https://example.com/callback'
end

Basic usage

Credit Card Online Installment Charge

# get credit card token
credit_card_params = {
  currency: 'IDR',
  gross_amount: 12500,
  card_number: 5573381072196900,
  card_exp_month: 02,
  card_exp_year: 2025,
  card_cvv: 123
}

credit_card_token = midtrans.credit_card_token.get(credit_card_params)
#=> credit_card_token returns MidtransApi::Model::CreditCard::Token instance

charge_params = {
  "payment_type": 'credit_card',
  "transaction_details": {
    "order_id": 'order-with-credit_card_installment',
    "gross_amount": 12500
  },
  "credit_card": {
    "token_id": credit_card_token.token_id,
    "authentication": true,
    "installment_term": 3,
    "bank": 'mandiri',
    "bins": [
      'mandiri'
    ]
  },
  "customer_details": {
    "first_name": 'Budi',
    "last_name": 'Utomo',
    "email": 'test@midtrans.com',
    "phone": '081111333344'
  },
  "item_details": [
    {
      "id": 'invoice-1',
      "price": 12500,
      "quantity": 1,
      "name": 'Invoice #1'
    }
  ]
}

credit_card_charge = midtrans.credit_card_charge.post(charge_params)
#=> credit_card_charge returns MidtransApiMidtransApi::Model::CreditCard::Charge instance

Gopay Charge

charge_params = {
  "payment_type": "gopay",
  "transaction_details": {
      "order_id": "order-with-gopay",
      "gross_amount": 12500
  },
  "item_details": [
      {
          "id": "bluedio-turbine",
          "price": 12500,
          "quantity": 1,
          "name": "Bluedio H+ Turbine Headphone with Bluetooth 4.1 -"
      }
  ],
  "customer_details": {
      "first_name": "Budi",
      "last_name": "Utomo",
      "email": "budi.utomo@midtrans.com",
      "phone": "081223323423"
  },
  "gopay": {
      "enable_callback": true,
      "callback_url": "someapps://callback"
  }
}

gopay_charge = midtrans.gopay_charge.post(charge_params)
#=> gopay_charge returns MidtransApiMidtransApi::Model::Gopay::Charge instance

BCA Virtual Account Charge

charge_params = {
  "payment_type": "bank_transfer",
  "transaction_details": {
      "order_id": "order-with-bca-virtua-account",
      "gross_amount": 12500
  },
  "item_details": [
      {
          "id": "bluedio-turbine",
          "price": 12500,
          "quantity": 1,
          "name": "Bluedio H+ Turbine Headphone with Bluetooth 4.1 -"
      }
  ],
  "customer_details": {
      "first_name": "Budi",
      "last_name": "Utomo",
      "email": "budi.utomo@midtrans.com",
      "phone": "081223323423"
  },
  "bank_transfer": {
    "bank": "bca",
    "va_number": "11111111",
    "free_text": {
      "inquiry": [
        {
          "id": "Free Text Inquiry ID",
          "en": "Free Text Inquiry EN"
        }
      ],
      "payment": [
        {
          "id": "Free Text Payment ID",
          "en": "Free Text Payment EN"
        }
      ]
    }
  },
  "bca": {
      "sub_company_code": "000"
    }
}

bca_virtual_account_charge = midtrans.bca_virtual_account_charge.post(charge_params)
#=> bca_virtual_account_charge returns MidtransApiMidtransApi::Model::BcaVirtualAccount::Charge instance

Check Status Payment

dummy_order_id = "order-with-gopay"
check_status = midtrans.status.get(order_id: dummy_order_id)
#=> check_status returns MidtransApi::Model::Check::Status

About official documentation api of Midtrans API, see API doc

Errors (Sample)

MidtransApi can raise conditional Errors explained from Midtrans Documentation. About available Status Code, see Midtrans API doc

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mekari-engineering/midtrans_api_ruby.

License

The gem is available as open source under the terms of the MIT License.