Class: PaymentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PaymentsController
- Defined in:
- lib/generators/templates/payments_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creating example payment.
- #new ⇒ Object
-
#receive_webhook ⇒ Object
Processing HTTP Notification from Veritrans POST request with JSON-encoded body If you using Veritrans::Events then you don’t need this.
Instance Method Details
#create ⇒ Object
Creating example payment
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/templates/payments_controller.rb', line 9 def create @payment = make_payment if params[:type] == "vtweb" @result = Veritrans.charge( payment_type: "VTWEB", transaction_details: { order_id: @payment.order_id, gross_amount: @payment.amount } ) redirect_to @result.redirect_url return end @result = Veritrans.charge( payment_type: "credit_card", credit_card: { token_id: params[:payment][:token_id] }, transaction_details: { order_id: @payment.order_id, gross_amount: params[:payment][:amount].presence || @payment.amount } ) end |
#new ⇒ Object
4 5 6 |
# File 'lib/generators/templates/payments_controller.rb', line 4 def new @payment = make_payment end |
#receive_webhook ⇒ Object
Processing HTTP Notification from Veritrans POST request with JSON-encoded body If you using Veritrans::Events then you don’t need this
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/templates/payments_controller.rb', line 37 def receive_webhook post_body = request.body.read Veritrans.file_logger.info("Callback for order: " + "#{params[:order_id]} #{params[:transaction_status]}\n" + post_body + "\n" ) verified_data = Veritrans.status(params["transaction_id"]) if verified_data.status_code != 404 puts "--- Transaction callback ---" puts "Payment: #{verified_data.data[:order_id]}" puts "Payment type: #{verified_data.data[:payment_type]}" puts "Payment status: #{verified_data.data[:transaction_status]}" puts "Fraud status: #{verified_data.data[:fraud_status]}" if verified_data.data[:fraud_status] puts "Payment amount: #{verified_data.data[:gross_amount]}" puts "--- Transaction callback ---" render text: "ok" else Veritrans.file_logger.info("Callback verification failed for order: " + "#{params[:order_id]} #{params[:transaction_status]}}\n" + verified_data.body + "\n" ) render text: "ok", :status => :not_found end end |