finished Customer save and return data from membership in crm

This commit is contained in:
Aung Myo
2017-06-06 18:07:38 +06:30
parent 8fd23bfd87
commit 9e3eaaf214
4 changed files with 76 additions and 23 deletions

View File

@@ -5,9 +5,11 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers.json
def index
@crm_customers = Customer.all
@customers = Customer.new
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @crm_customers }
@@ -33,14 +35,39 @@ class Crm::CustomersController < ApplicationController
# POST /crm/customers
# POST /crm/customers.json
def create
@crm_customer = Customer.new(customer_params)
puts "Hello"
puts customer_params.to_json
@crm_customers = Customer.new(customer_params)
respond_to do |format|
if @crm_customer.save
format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' }
format.json { render :show, status: :created, location: @crm_customer }
if @crm_customers.save
name = customer_params[:name]
phone = customer_params[:contact_no]
email = customer_params[:email]
date_of_birth = customer_params[:date_of_birth]
membership_id = params[:membership_id]
membership = MembershipSetting.find_by_membership_type("smartpay_url")
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s
response = HTTParty.post(url,
:body => { name: name,phone: phone,email: email,date_of_birth: date_of_birth,membership_id: membership_id}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
puts "rrrrrrrrrrrrrr"
puts response.to_json
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
format.json { render :index, status: :created, location: @crm_customers }
else
format.html { render :new }
format.html { render :index }
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
end
end
@@ -78,6 +105,9 @@ class Crm::CustomersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def customer_params
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code)
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code)
end
end