=begin Nicepay Ruby Bindings Virtual Account Sample Code Have a Nicepay! =end require_relative 'lib/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', 'IRD') # 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