10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/controllers/catarse_credit_card_net/credit_card_net_controller.rb', line 10
def pay
contribution.update_attributes payment_method: 'AuthorizeNet'
begin
card_options = {
card_type: card_type(params[:card_number]),
card_number: params[:card_number],
card_code: params[:card_code],
card_month: params[:card_month],
card_year: params[:card_year]
}
card = credit_card(card_options)
if card.valid?
_test = (::Configuration[:test_payments] == 'true')
an_login_id = ::Configuration[:authorizenet_login_id]
an_transaction_key = ::Configuration[:authorizenet_transaction_key]
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new({
:login => an_login_id,
:password => an_transaction_key,
:test => _test
})
response = gateway.purchase(contribution.price_in_cents_with_tax, card, customer_info(contribution))
PaymentEngines.create_payment_notification contribution_id: contribution.id, extra_data: response.inspect
contribution.update_attributes payment_id: response.params['transaction_id']
contribution.update_attributes payment_token: response.params['transaction_id']
if response.success?
contribution.confirm!
session[:thank_you_id] = contribution.project.id
session[:_payment_token] = contribution.payment_token
flash[:success] = t('controllers.projects.contributions.pay.success')
return render :json => { process_status: 'ok', message: response.message } if request.xhr?
redirect_to main_app.project_contribution_path(contribution.project, contribution)
else
return render :json => { process_status: 'error', message: response.message } if request.xhr?
flash[:failure] = response.message
redirect_to main_app.new_project_contribution_path(contribution.project, contribution)
end
else
return render :json => { process_status: 'error', message: card.errors.full_messages.to_sentence } if request.xhr?
flash[:failure] = card.errors.full_messages.to_sentence
redirect_to main_app.new_project_contribution_path(contribution.project, contribution)
end
rescue Exception => e
Rails.logger.info "Checkout direct credit card error -----> #{e.inspect}"
return render :json => { process_status: 'error', message: I18n.t('controllers.projects.contributions.pay.error') } if request.xhr?
flash[:failure] = I18n.t('controllers.projects.contributions.pay.error')
redirect_to main_app.new_project_contribution_path(contribution.project, contribution)
end
end
|