=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==') # API Operation cancelVa = Nicepay::Api::CancelVa.new(Nicepay.requestParam) # Set Request Parameter for Virtual Account # Merchant Id Nicepay.setRequestParam('iMid', Nicepay.iMid) # Bank Transfer -> payMethod = 02 Nicepay.setRequestParam('payMethod', '02') # Total amount Nicepay.setRequestParam('amt', 3000) # Transaction id (tXid) Nicepay.setRequestParam('tXid', 'VACCTCLOSE02201606071356095243') # Cancelation type -> set 1 Nicepay.setRequestParam('cancelType', 1) # Cancelation message Nicepay.setRequestParam('cancelMsg', 'Order canceled, release VA number') # 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 = cancelVa.response # Inspect response # puts response.inspect # If success, show VA information to customer if response["resultCd"].to_s == "0000" puts "\n" puts "----------------------------------------------------------------------" puts "Transaction have been canceled\n\n" puts "----------------------------------------------------------------------" puts "Description : " + response["description"].to_s puts "Amount : " + response["amount"].to_s puts "Reference No : " + response["referenceNo"].to_s puts "Transaction ID : " + response["tXid"].to_s puts "----------------------------------------------------------------------" elsif response["resultCd"].to_s == "9315" puts "\n" puts "----------------------------------------------------------------------" puts "Transaction have been canceled\n\n" puts "----------------------------------------------------------------------" puts "Result Code : " + response["resultCd"] puts "Result Message : " + response["resultMsg"] puts "----------------------------------------------------------------------" else # If error, you can redirect back to checkout page # In this sample, we only puts error message puts "\nOops! Virtual Account can't be canceled. \nPlease try again later.\n\n" puts "Result Code : " + response["resultCd"] puts "Result Message : " + response["resultMsg"] end # Flush request parameter Nicepay.flushParam