Build Status Test Coverage Maintainability

The Offsite Payments implement for NewebPay(藍新金流)


Add this line to your application's Gemfile:

gem 'newebpay'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install newebpay


Configure Newebpay

# config/initializes/newebpay.rb

# Set to test mode if under development
OffsitePayments.mode = :test

Newebpay::Config.config do |c|
  c.hash_key = ''
  c.hash_iv = ''

Temporary switch config

config = do |c|
  c.hash_key = 'A' * 32
  c.hash_iv = 'B' * 16

Newebpay.use(config) do
  Newebpay::Config.current == config # => true

Create payment button

In your controller

options = {
  amount: 40, # TWD
  description: 'My Product',
  return_url: newebpay_return_url,
  notify_url: newebpay_notify_url

@helper = Newebpay.helper(order_id, merchant_id, options)

The Newebpay.helper is an alias to

In your view

<!-- payment.erb -->

<form action="<%= OffsitePayments.integration('newebpay').service_url %>" method="POST">
  <% @helper.form_fields.each do |key, value| %>
    <input type="hidden" name="<%= key %>" value="<%= value %>" />
    <% end %>
  <button type="submit">Process</button>

Above example is tested under Sinatra but you can use form helper in Rails to improve it.

Process Return Data

In your controller

@return = Newebpay.return(
@return.trade_info # The decrypted TradeInfo from NewebPay

Please notice the request.body may cause Rails params not work due to we didn't rewind it

Process Notification Data

In you controller

@notification = Newebpay.notification(
@notification.trade_info # The decrypted TradeInfo from NewebPay


  • [x] MPG Support
  • [x] Allow switch config
  • [ ] Refund API
  • [ ] Unauthorized API
  • [ ] Order Status API
  • [ ] Rails Support
    • [ ] Form Object
    • [ ] Form Helper


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


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Code of Conduct

Everyone interacting in the Newebpay project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.