control for member create and member discount
This commit is contained in:
@@ -81,7 +81,7 @@ class Crm::CustomersController < BaseCrmController
|
||||
nrc = customer_params[:nrc_no]
|
||||
card_no = customer_params[:card_no]
|
||||
paypar_account_no = customer_params[:paypar_account_no]
|
||||
member_group_id = params[:member_group_id]
|
||||
member_group_id = params[:member_group_id]
|
||||
|
||||
if member_group_id.present?
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
@@ -90,13 +90,23 @@ class Crm::CustomersController < BaseCrmController
|
||||
auth_token = memberaction.auth_token.to_s
|
||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
|
||||
# Check for paypar account exists
|
||||
if paypar_account_no != nil || paypar_account_no != ''
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
paypar_account_no: paypar_account_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
end
|
||||
|
||||
begin
|
||||
response = HTTParty.post(url,
|
||||
:body => {name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
paypar_account_no: paypar_account_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
||||
:body => member_params,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
@@ -137,6 +147,12 @@ class Crm::CustomersController < BaseCrmController
|
||||
status = customer.update_attributes(membership_type:member_group_id)
|
||||
end
|
||||
|
||||
# When paypar account no not exist in paypar
|
||||
if response["message"] == "Account has not exist."
|
||||
customer.destroy
|
||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer cannot created.' + response["message"]}
|
||||
end
|
||||
|
||||
if params[:sale_id]
|
||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response["message"]}
|
||||
else
|
||||
@@ -181,23 +197,32 @@ end
|
||||
card_no = customer_params[:card_no]
|
||||
paypar_account_no = customer_params[:paypar_account_no]
|
||||
id = @crm_customer.membership_id
|
||||
member_group_id = params[:member_group_id]
|
||||
member_group_id = params[:member_group_id]
|
||||
|
||||
if id.nil? && !member_group_id.nil?
|
||||
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
|
||||
merchant_uid = memberaction.merchant_account_id.to_s
|
||||
auth_token = memberaction.auth_token.to_s
|
||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
|
||||
# Check for paypar account exists
|
||||
if paypar_account_no != nil || paypar_account_no != ''
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
paypar_account_no: paypar_account_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
end
|
||||
|
||||
begin
|
||||
response = HTTParty.post(url,
|
||||
:body => { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,
|
||||
paypar_account_no: paypar_account_no,
|
||||
card_no:card_no,member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
||||
:body => member_params,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
@@ -230,20 +255,30 @@ end
|
||||
|
||||
format.html { redirect_to crm_customers_path, notice: response["error"] }
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
||||
merchant_uid = memberaction.merchant_account_id.to_s
|
||||
auth_token = memberaction.auth_token.to_s
|
||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
|
||||
# Check for paypar account exists
|
||||
if paypar_account_no != nil || paypar_account_no != ''
|
||||
member_params = { name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
paypar_account_no: paypar_account_no,
|
||||
member_group_id: member_group_id,
|
||||
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
|
||||
end
|
||||
|
||||
begin
|
||||
response = HTTParty.post(url,
|
||||
:body => {name: name,phone: phone,email: email,
|
||||
dob: dob,address: address,nrc:nrc,card_no:card_no,
|
||||
paypar_account_no: paypar_account_no,
|
||||
id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
||||
:body => member_params,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
|
||||
Reference in New Issue
Block a user