Skip to content

Instantly share code, notes, and snippets.

@leylaKapi
Created February 27, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leylaKapi/fc098cf6fc9e036bc1eafe88fc775a0e to your computer and use it in GitHub Desktop.
Save leylaKapi/fc098cf6fc9e036bc1eafe88fc775a0e to your computer and use it in GitHub Desktop.
Payment with a Bank
%form{:action => @teb.url, :method => 'post'}
.form-inputs
-#= f.input :pan
.form-group
%label= t('activerecord.attributes.payment.card_number')
%input{name: 'pan', type: 'number',class: ''}
.form-group
%label= t('activerecord.attributes.payment.end_year')
%input{name: 'Ecom_Payment_Card_ExpDate_Year', type: 'text'}
.form-group
%label= t('activerecord.attributes.payment.end_moth')
%input{name: 'Ecom_Payment_Card_ExpDate_Month', type: 'text'}
.form-group
%label= t('activerecord.attributes.payment.card_owner')
%input{name: 'card_owner', type: 'text'}
.form-group
%label= t('activerecord.attributes.payment.cvv')
%input.form-control{name: 'cv2', type: 'number'}
%br/
-#= f.input :Ecom_Payment_Card_ExpDate_Year
-#= f.input :Ecom_Payment_Card_ExpDate_Month
-#= f.input :card_owner
-#= f.input :cv2
%input{name: 'clientid', type: 'hidden', value: Settings.teb.client_id}
%input{name: 'amount', type: 'hidden', value: @amount}
%input{name: 'cardType', type: 'hidden', value: '1'}
%input{name: 'oid', type: 'hidden', value: @oid}
%input{name: 'okUrl', type: 'hidden', value: '#{Settings.teb.okurl}'}
%input{name: 'failUrl', type: 'hidden', value: '#{Settings.teb.failurl}'}
%input{name: 'rnd', type: 'hidden', value: @time}
%input{name: 'hash', type: 'hidden', value: @hash}
%input{name: 'storetype', type: 'hidden', value: '#{Settings.teb.storetype}'}
%input{name: 'lang', type: 'hidden', value: '#{Settings.teb.language}'}
%input{name: 'currency', type: 'hidden', value: '#{Settings.teb.currency}'}
.form-actions
 
%input.st-btn.primary-btn.hvr-back.hvr-sweep-to-right.pull-right{type: 'submit', value: "#{t('btn.sent')}"}
class PaymentsController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:fail, :success]
def new
add_breadcrumb t('activerecord.models.payment'), new_payment_path
@teb = Settings.teb
@payment = Payment.new
@oid = current_order.order_no
@amount = current_order.total_price
@time = Time.zone.now.utc.strftime('%Y%m%d%H%M%S')
#$hashstr = $clientId . $oid . $amount . $okUrl . $failUrl . $rnd . $storekey;
hash_text = @teb.client_id.to_s + @oid + @amount.to_s + @teb.okurl + @teb.failurl + @time + @teb.store_key.to_s
@hash = Digest::SHA1.base64digest(hash_text)
end
def create
@payment = Payment.new(payment_params)
end
def fail
render :fail
end
def success
@teb = Settings.teb
@payment = Payment.new
@oid = current_order.order_no
@amount = current_order.total_price
@time = Time.zone.now.utc.strftime('%Y%m%d%H%M%S')
#$hashstr = $clientId . $oid . $amount . $okUrl . $failUrl . $rnd . $storekey;
hash_text = @teb.client_id.to_s + @oid + @amount.to_s + @teb.okurl + @teb.failurl + @time + @teb.store_key.to_s
@hash = Digest::SHA1.base64digest(hash_text)
# if params[:hash] != @hash
# abort "fail"
# end
@md = params[:md]
@mdStatus = params[:mdStatus]
if @mdStatus == '1' || @mdStatus == '2' || @mdStatus == '3' || @mdStatus == '4'
@xid = params[:xid]
@eci = params[:eci]
@cavv = params[:cavv]
xml_data = render_to_string "payments/payment_request", :layout => false
uri = URI("https://entegrasyon.asseco-see.com.tr/fim/api")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
req = Net::HTTP::Post.new(uri)
req['Content-Type'] = 'application/xml'
req.body = xml_data
http.request(req)
end
if response.code == "200"
current_order.update_column(:status, Order.statuses[:paid])
doc = Nokogiri::XML(response.body)
render :success
else
render :fail
end
else
render :fail
end
end
private
def payment_params
params.require(:payment).permit(:card_owner, :card_number, :cvv, :end_month, :end_year)
end
end
bank:
client_id: your_client_id
password: your_pass
store_key: your_store_key
okurl: okurl
failurl: failurl
process_type: Auth
url: https://entegrasyon.asseco-see.com.tr/fim/est3Dgate
api: https://entegrasyon.asseco-see.com.tr/fim/api
storetype: storetype
language: tr
currency: 949
api:
user: user
password: password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment