Last active
August 24, 2022 06:33
-
-
Save gtan66/49916a11a37466ac15fa to your computer and use it in GitHub Desktop.
Tokenizing Tranzila Cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Assuming infos is an array of hashes, each having :location ('TLV01' is Herzlyia, 'TLV02' is Dubnov), :code (the member's short code), :exp (expiration), :card, :cvv and :id (should be 'N/A' for int'l cards) | |
require 'net/http' | |
require 'uri' | |
Net::HTTP.get(URI.parse("https://secure5.tranzila.com/cgi-bin/tranzila31cl.cgi?TranzilaPW=#{ENV['TRANZILLA_TOKEN_PW']}&supplier=wework")) | |
uri = URI.parse('https://secure5.tranzila.com/cgi-bin/tranzila31pan.cgi') | |
infos.each do |info| | |
next if info[:id].blank? | |
parameters = { | |
'TranzilaPW' => ENV['TRANZILLA_TOKEN_PW'], | |
'supplier' => 'wework', | |
'ccno' => info[:card], | |
'mycvv' => info[:cvv], | |
'expdate' => info[:exp], | |
'sum' => 0.1, | |
'currency' => 1, | |
'tranmode' => 'VK' | |
} | |
parameters['myid'] = info[:id] if info[:id] != 'N/A' | |
response = Net::HTTP.post_form(uri, parameters) | |
info[:response] = response.body.chomp | |
end | |
# stop and clean up tokens | |
infos.each { |h| h[:token] = h[:response].split('=')[1] } | |
infos.each do |info| | |
location = Location.find_by(code: info[:location]) | |
account = Account.find_by(short_code: info[:code]) | |
user = account.account_admin | |
info = { | |
tokens: { tranzilla_token: info[:token] }, | |
gateway: 'tranzilla', | |
card_number: info[:card], | |
expiration_month: info[:exp][0..1], | |
expiration_year: info[:exp][2..3] | |
} | |
PaymentService.create_payment_profile!(user, location, info) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please remove this or make it a private gist as this is publicly searchable.