Method to activate the credit card when added by user.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 62 def activate_credit_card @credit_card = @user.credit_cards.find(params[:id]) @credit_card.active = true if @credit_card.save render json: {status: 200, :success => "Card successfully activated."} else render json: {status: 401, error: "Invalid card details."} end end
Method to add credit card details for the current user.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 51 def add_credit_card @credit_card = @user.credit_cards.build(credit_card_params) @credit_card.active = true if @credit_card.save render json: {status: 200, success: "Successfully created card."} else render json: {status: 401, error: "Invalid card details."} end end
Method to add course to tutor account.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 111 def add_courses tutor = Tutor.where(auth_token: params[:auth_token]) if !tutor.nil? && !tutor[0].nil? subject_tutored = SubjectsTutor.where(:subject_id => params[:subject_id], :tutor_id => tutor[0].id) if(!subject_tutored.nil? && !subject_tutored[0].nil?) else st = SubjectsTutor.new(:subject_id => params[:subject_id], :tutor_id => tutor[0].id) st.save end if params[:selected_course_ids].kind_of?(Array) params[:selected_course_ids].each do |course_id| begin course = Course.find course_id rescue => e render json: {status: 400, error: "Course with id #{course_id} not found."} return end if course Tutor.find(tutor[0].id).courses << course unless Tutor.find(tutor[0].id).courses.include?(course) else render json: {status: 400, error: "Course with id #{course_id} not found."} return end end render json: {status: 200} else render json: {status: 400, error: "Array of course ids not found in parameters, please check course id array and try again."} return end else render json: {status: 400, error: "Tutor with auth_token #{params[:auth_token]} not found."} end end
Method to get credit card details of the current user.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 41 def get_credit_cards credit_card_details = @user.credit_cards if credit_card_details render json: { status: 200, credit_card_details: credit_card_details.map{|c| c.attributes.except('uri', 'created_at', 'updated_at', 'university_id')}} else render json: { status: 401, error: "Credit card for user #{@user.name} not found." } end end
Method to find all courses of subjects with subject Id.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 100 def get_courses_for_subject subject = Subject.find(params[:subject_id]) if !subject.nil? courses = subject.courses render json: {status: 200, :courses => courses, :total_courses => courses.length} else render json: {status: 400, error: "Subject with subject_id #{params[:subject_id]} not found."} end end
Method to remove the credit card from user account.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 73 def remove_credit_card @credit_card = @user.credit_cards.find(params[:id]) if @credit_card.destroy render json: {status: 200, :success => "Successfully destroyed card."} else render json: {status: 401, error: "Can't destroy card."} end end
Method to signup manually from mobile app i.e. create new user account with its mail Id.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 5 def sign_up params[:user].permit! user = User.new params[:user], as: :creator if user.save user.generate_auth_token render json: { status: 200, is_valid_user: user.valid?, user_info: user, auth_token: user.auth_token } else render json: { status: 400, error: "Sign up process failed.", is_valid_user: user.valid?, error_details: user.errors.full_messages } end end
Method to upadate and create bank account for current user.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 83 def update_bank_details if Payment.create_new_bank params[:payment], @user render json: {status: 200, :success => "Successfully created bank account."} else render json: {status: 400, error: "Invalid bank details."} end end
Method to activate the user signup manually through clicking its email link.
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 17 def update_billing_shipping_details result = User.update_all( { :billing_address_1 => params[:billing_address_1], :billing_address_2 => params[:billing_address_2], :billing_city => params[:billing_city], :billing_state => params[:billing_state], :billing_zipcode => params[:billing_zipcode], :shipping_address_1 => params[:shipping_address_1], :shipping_address_2 => params[:shipping_address_2], :shipping_city => params[:shipping_city], :shipping_state => params[:shipping_state], :shipping_zipcode => params[:shipping_zipcode] }, {:id => user[0].id} ) if result == 1 render json: { status: 200 } else render json: { status: 400, error: "Update failed." } end end
To update user profile
# File app/controllers/mobile_app_api/v1/registration_controller.rb, line 146 def update_profile if @user.type == "Tutor" if user[0].update_attributes params[user[0].type_to_symbol], as: :creator render json: { status: 200 } else render json: { status: 400, error: "Update failed." } end else if user[0].update_attributes params[user[0].type_to_symbol], as: :creator render json: { status: 200 } else render json: { status: 400, error: "Update failed." } end end end