NICEPay Ruby Bindings

NICEPAY  Ruby

Payment Flow

Credit Card

Card Flow

Virtual Account

VA Flow

Nicepay Ruby SDK Installation

Install Nicepay Ruby Gem

gem install nicepay -v 0.0.1

Add Nicepay Gem into GEMFILE

add following line

gem 'nicepay', '~> 0.1.3'

Nicepay API Operation

Generate Virtual Account

Sample Code sample/test-va.rb

=begin
    Nicepay Ruby Bindings
    Virtual Account Sample Code
    Have a Nicepay!
=end
require 'nicepay'
# require 'nicepay'
# Configuration

# MID
Nicepay.iMid=('VACCTCLOSE')
# Merchant Key
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
# Webhook/Notification Handler URL
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
Nicepay.callBackUrl=('http://www.example.com/')

# API Operation
requestVa   = Nicepay::Api::RequestVa.new(Nicepay.requestParam)

# Set Request Parameter for Virtual Account

# Merchant Id
Nicepay.setRequestParam('iMid', Nicepay.iMid)

# Bank Transfer -> payMethod = 02
Nicepay.setRequestParam('payMethod', '02')

# Set Bank
# BCA -> CENA
# BNI -> BNIN
# Mandiri -> BMRI
# Hana Bank -> HNBN
# Maybank -> IBBK
# Permata -> BBBA
Nicepay.setRequestParam('bankCd', 'CENA')

# Reference Number / Order Number / Invoice Number, generated by merchant
Nicepay.setRequestParam('referenceNo','Invoice-7834')

# Transaction Description
Nicepay.setRequestParam('description','Payment of ' + Nicepay.param('referenceNo')) # Description
Nicepay.setRequestParam('goodsNm', Nicepay.param('description')) # goodsNm = Description

# Add cart information mandatory at least one cart data
# Nicepay.addCart('image_location','product_name','product_description', 'sub_total_amount')
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 3', 1000)
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 1', 2000)

# Set cartData as request parameter
Nicepay.setRequestParam('cartData', Nicepay.cartData)

# Amount -> auto count from cartData
Nicepay.setRequestParam('amt', Nicepay.autoCountTotal)

# Currency -> Indonesian Rupiah
Nicepay.setRequestParam('currency', 'IDR')

# Set customer information
Nicepay.setRequestParam('billingNm', 'John Doe')
Nicepay.setRequestParam('billingPhone', '02112341234')
Nicepay.setRequestParam('billingEmail', 'john.doe@example.com')
Nicepay.setRequestParam('billingAddr', 'Jl. Jend Sudirman')
Nicepay.setRequestParam('billingCity', 'Jakarta Pusat')
Nicepay.setRequestParam('billingState', 'DKI Jakarta')
Nicepay.setRequestParam('billingPostCd', '10210')
Nicepay.setRequestParam('billingCountry', 'Indonesia')

Nicepay.setRequestParam('deliveryNm', 'John Doe')
Nicepay.setRequestParam('deliveryPhone', '02112341234')
Nicepay.setRequestParam('deliveryEmail', 'john.doe@example.com')
Nicepay.setRequestParam('deliveryAddr', 'Jl. Jend Sudirman')
Nicepay.setRequestParam('deliveryCity', 'Jakarta Pusat')
Nicepay.setRequestParam('deliveryState', 'DKI Jakarta')
Nicepay.setRequestParam('deliveryPostCd', '10210')
Nicepay.setRequestParam('deliveryCountry', 'Indonesia')

# Set User Customer IP
Nicepay.setRequestParam('userIP', Nicepay.userIp)

# Set dbProcessUrl (Notification Handler / Web Hook URL)
Nicepay.setRequestParam('dbProcessUrl', Nicepay.dbProcessUrl)

# Set callbackUrl (Redirection page after payment URL)
Nicepay.setRequestParam('callBackUrl', Nicepay.callBackUrl)

# Set vat, fee & noTaxAmt -> reserved for future feature, only set 0 for now
Nicepay.setRequestParam('vat', 0)
Nicepay.setRequestParam('fee', 0)
Nicepay.setRequestParam('notaxAmt', 0)

# Set VA expiry date -> 2 days from now
Nicepay.setRequestParam('vacctValidDt', Nicepay.vaExpiryDate(2)) # format: %Y%m%d
# You can also set like this
# Nicepay.setRequestParam('vacctValidDt', '20160608') # format: %Y%m%d

# Set VA expiry time -> time as now
Nicepay.setRequestParam('vacctValidTm', Nicepay.vaExpiryTime) # format: %H%M%S
# You can also set like this
# Nicepay.setRequestParam('vacctValidTm', '095519') # format: %H%M%S

# Merchant Token
Nicepay.setRequestParam('merchantToken', Nicepay.merchantToken)

# If you want to dump POST parameters and review it
# puts Nicepay.dumpParameters
# abort("Exit")

# Inspect Response
# puts requestVa.response.inspect

response = requestVa.response

# Inspect response
# puts response.inspect

# If success, show and email VA information including customer journey to customer

if response["resultCd"].to_s == "0000"
    puts "\n"
    puts "----------------------------------------------------------------------"
    puts "Virtual Account Number : " + response["bankVacctNo"].to_s
    puts "Description            : " + response["description"].to_s
    puts "Reference No           : " + response["referenceNo"].to_s
    puts "Transaction ID         : " + response["tXid"].to_s # Save tXid in your database
    puts "----------------------------------------------------------------------"

else response["resultCd"].to_s
# If error, you can redirect back to checkout page
# In this sample, we only puts error message
    puts "\nOops! Virtual Account failed to generate! We have recorded the event. \nPlease try again later.\n\n"
    puts "Result Code    : " + response["resultCd"]
    puts "Result Message : " + response["resultMsg"]
end


# Flush request parameter
Nicepay.flushParam

Run sample/test-va.rb

$ ruby sample/test-va.rb
----------------------------------------------------------------------
Virtual Account Number : 7001400000000631
Description            : Payment of Invoice-7834
Reference No           : Invoice-7834
Transaction ID         : VACCTCLOSE02201606061649584906
----------------------------------------------------------------------

Card Checkout

Sample Code sample/test-card.rb

=begin
    Nicepay Ruby Bindings
    Virtual Account Sample Code
    Have a Nicepay!
=end
require 'nicepay'

# Configuration

Nicepay.iMid=('IONPAYTEST')
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
Nicepay.callBackUrl=('http://www.example.com/')

# API Operation
chargeCard  = Nicepay::Api::ChargeCard.new(Nicepay.requestParam)

# Set Request Parameter for Card Payment

# Merchant Id
Nicepay.setRequestParam('iMid', Nicepay.iMid)

# Card -> payMethod = 01
Nicepay.setRequestParam('payMethod', '01')

# No Installment - Do not use installment feature before get rights from bank
Nicepay.setRequestParam('instmntMon', '1')
Nicepay.setRequestParam('instmntType', '1')

# Reference Number / Order Number / Invoice Number, generated by merchant
Nicepay.setRequestParam('referenceNo','Invoice-7833')

# Transaction Description
Nicepay.setRequestParam('description','Payment of ' + Nicepay.param('referenceNo')) # Description
Nicepay.setRequestParam('goodsNm', Nicepay.param('description')) # goodsNm = Description

# Add cart information mandatory at least one cart data
# Nicepay.addCart('image_location','product_name','product_description', 'sub_total_amount')
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 3', 1000)
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 1', 2000)
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Discount', 'Jumlah: 50%', -1500)
# Set cartData as request parameter
Nicepay.setRequestParam('cartData', Nicepay.cartData)
# Total Amount -> auto count from cartData
Nicepay.setRequestParam('amt', Nicepay.autoCountTotal)

# Currency -> Indonesian Rupiah
Nicepay.setRequestParam('currency', 'IDR')

# Set customer information
Nicepay.setRequestParam('billingNm', 'John Doe')
Nicepay.setRequestParam('billingPhone', '02112341234')
Nicepay.setRequestParam('billingEmail', 'john.doe@example.com')
Nicepay.setRequestParam('billingAddr', 'Jl. Jend Sudirman')
Nicepay.setRequestParam('billingCity', 'Jakarta Pusat')
Nicepay.setRequestParam('billingState', 'DKI Jakarta')
Nicepay.setRequestParam('billingPostCd', '10210')
Nicepay.setRequestParam('billingCountry', 'Indonesia')

Nicepay.setRequestParam('deliveryNm', 'John Doe')
Nicepay.setRequestParam('deliveryPhone', '02112341234')
Nicepay.setRequestParam('deliveryEmail', 'john.doe@example.com')
Nicepay.setRequestParam('deliveryAddr', 'Jl. Jend Sudirman')
Nicepay.setRequestParam('deliveryCity', 'Jakarta Pusat')
Nicepay.setRequestParam('deliveryState', 'DKI Jakarta')
Nicepay.setRequestParam('deliveryPostCd', '10210')
Nicepay.setRequestParam('deliveryCountry', 'Indonesia')

# Set User Customer IP
Nicepay.setRequestParam('userIP', Nicepay.userIp)

# Set dbProcessUrl (Notification Handler / Web Hook URL)
Nicepay.setRequestParam('dbProcessUrl', Nicepay.dbProcessUrl)

# Set callbackUrl (Redirection page after payment URL)
Nicepay.setRequestParam('callBackUrl', Nicepay.callBackUrl)

# Set vat, fee & noTaxAmt -> reserved for future feature, only set 0 for now
Nicepay.setRequestParam('vat', 0)
Nicepay.setRequestParam('fee', 0)
Nicepay.setRequestParam('notaxAmt', 0)

# Merchant Token
Nicepay.setRequestParam('merchantToken', Nicepay.merchantToken)

# If you want to dump POST parameters and review it
# puts Nicepay.dumpParameters
# abort("Exit")

# Inspect Response
# puts chargeCard.response.inspect

response = chargeCard.response

# Inspect response
# puts response

# If success, redirect to payment page
if response["resultCd"].to_s == "0000"
    puts "\n"
    puts "-----------------------------------------------------------------------------------------------------"
    puts "Redirect Customer to   : " + response["requestURL"].to_s + "?tXid=" + response["tXid"].to_s
    puts "tXid                   : " + response["tXid"].to_s # Save tXid in your database
    puts "-----------------------------------------------------------------------------------------------------"

else
# If error, you can redirect back to checkout page
# In this sample, we only puts error message
    puts "\nOops! Payment Page failed to generate! We have recorded the event. \nPlease try again later.\n\n"
    puts "Result Code    : " + response["resultCd"]
    puts "Result Message : " + response["resultMsg"]
end


# Flush request parameter
Nicepay.flushParam

Run sample/test-card.rb

$ ruby sample/test-card.rb
-----------------------------------------------------------------------------------------------------
Redirect Customer to   : https://www.nicepay.co.id/nicepay/api/orderInquiry.do?tXid=IONPAYTEST01201606061651114907
tXid                   : IONPAYTEST01201606061651114907
-----------------------------------------------------------------------------------------------------

Check Transaction Status

Sample Code sample/test-status.rb

=begin
    Nicepay Ruby Bindings
    Virtual Account Sample Code
    Have a Nicepay!
=end
require 'nicepay'

# Configuration

# MID
Nicepay.iMid=('VACCTCLOSE')
# Merchant Key
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
# Webhook/Notification Handler URL
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
# Redirection URL after customer made payment in Nicepay Payment Page
Nicepay.callBackUrl=('http://www.example.com/')

# API Operation
checkStatus = Nicepay::Api::CheckStatus.new(Nicepay.requestParam)

# Set Request Parameter for Check Status

# Merchant Id
Nicepay.setRequestParam('iMid', Nicepay.iMid)

# Reference Number / Order Number / Invoice Number, generated by merchant
Nicepay.setRequestParam('referenceNo','Invoice-7834')

# Total Amount
Nicepay.setRequestParam('amt', '3000')

# Set VA expiry date -> 2 days from now
Nicepay.setRequestParam('tXid', 'VACCTCLOSE02201606061354204825')
# You can also set like this

# Merchant Token
Nicepay.setRequestParam('merchantToken', Nicepay.merchantTokenC)

# If you want to dump POST parameters and review it
# puts Nicepay.dumpParameters
# abort("Exit")

# Inspect Response
# puts requestVa.response.inspect

response = checkStatus.response

# Inspect response
# puts response.inspect

=begin
     **=========================================================================================================
     ** Credit Card
     **=========================================================================================================
     ** $paymentStatus->status == 0 // Success
     ** $paymentStatus->status == 1 // Failed
     ** $paymentStatus->status == 2 // Void or Refund
     ** $paymentStatus->status == 9 // Initialization or Unpaid
     **=========================================================================================================
     *
     **=========================================================================================================
     ** Virtual Account
     **=========================================================================================================
     ** $paymentStatus->status == 0 // Paid
     ** $paymentStatus->status == 3 // Unpaid
     ** $paymentStatus->status == 4 // Expired
     **=========================================================================================================
=end
# If success, show VA information to customer
if response["resultCd"].to_s == "0000"
    puts "\n"
    puts "----------------------------------------------------------------------"
    puts "Transaction Status     : " + response["status"].to_s
    puts "Amount                 : " + response["amt"].to_s
    puts "Reference No           : " + response["referenceNo"].to_s
    puts "Transaction ID         : " + response["tXid"].to_s
    puts "----------------------------------------------------------------------"

else
# If error, you can redirect back to checkout page
# In this sample, we only puts error message
    puts "\nOops! Check Status failed to generate! We have recorded the event. \nPlease try again later.\n\n"
    puts "Result Code    : " + response["resultCd"]
    puts "Result Message : " + response["resultMsg"]
end


# Flush request parameter
Nicepay.flushParam

Run sample/test-status.rb

$ ruby sample/test-status.rb
----------------------------------------------------------------------
Transaction Status     : 3
Amount                 : 3000
Reference No           : Invoice-7834
Transaction ID         : VACCTCLOSE02201606061354204825
----------------------------------------------------------------------

Ruby on Rails

Coming soon...