class Origami::PayparPaymentsController < BaseOrigamiController
	def create
		sale_id = params[:sale_id]
		@cashier_type   = params[:type]
		redeem_amount = params[:redeem_amount]
		membership_id = params[:membership_id]
		payment_method = "paypar"
		if(Sale.exists?(sale_id))
			saleObj = Sale.find(sale_id)
			shop_details =  Shop.first 
      
			# rounding adjustment
				if shop_details.is_rounding_adj
				new_total    = Sale.get_rounding_adjustment(saleObj.grand_total)
				rounding_adj = new_total-saleObj.grand_total
				saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)        
			end
			
      		sale_payment = SalePayment.new
      		status,msg =sale_payment.process_payment(saleObj, current_user, redeem_amount,payment_method)
      		if status == true
      			@out = true, "Success!"
      		else
      			@out =false, "Please try again payment!"
      		end
      	else
      		@out = false, "There has no sale record!"
		end

	end
	
end
