Class: CartsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CartsController
- Defined in:
- lib/generators/payfast/templates/controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #failure ⇒ Object
- #index ⇒ Object
- #make_payment ⇒ Object
- #new ⇒ Object
- #success ⇒ Object
Instance Method Details
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/payfast/templates/controller.rb', line 11 def create payload = { email_address: cart_params[:email_address], amount: cart_params[:amount], item_name: cart_params[:item_name], } payment_identifier = Payfast::OnsitePayments.requestPayment(payload) @cart = Cart.new(cart_params) @cart.payment_uuid = payment_identifier["uuid"] if @cart.save redirect_to make_payment_cart_path(@cart) else render :new, status: :unprocessable_entity end end |
#failure ⇒ Object
40 41 42 |
# File 'lib/generators/payfast/templates/controller.rb', line 40 def failure redirect_to carts_path, notice: "Transcation Canceled" end |
#index ⇒ Object
4 5 |
# File 'lib/generators/payfast/templates/controller.rb', line 4 def index end |
#make_payment ⇒ Object
30 31 32 |
# File 'lib/generators/payfast/templates/controller.rb', line 30 def make_payment @cart = Cart.find(params[:id]) end |
#new ⇒ Object
7 8 9 |
# File 'lib/generators/payfast/templates/controller.rb', line 7 def new @cart = Cart.new end |
#success ⇒ Object
34 35 36 37 38 |
# File 'lib/generators/payfast/templates/controller.rb', line 34 def success @cart = Cart.find(params[:id]) @cart.is_paid = true redirect_to carts_path, notice: "Transcation Successful" end |