thirtysixthspan / magtek_card_reader

Provides a convenient wrapper around libusb to read credit cards with a Magtek Credit Card Reader
MIT License
21 stars 1 forks source link

example keeps returning false #1

Closed mfrederickson closed 11 years ago

mfrederickson commented 11 years ago

I made sure that I had r/w access to the usb device, then ran the example code from the README, and it keeps returning false when I try to swipe my own card. Not using the server, just want to see it successfully read the card. Any ideas?

irb(main):004:0> mad = Magtek.available_devices
=> [[17, "USB Swipe Reader"]]
irb(main):005:0> mcr = Magtek::CardReader.new
=> #<Magtek::CardReader:0xa6e3b10 @usb=#<LIBUSB::Context:0xa6e2f6c @ctx=#<FFI::Pointer address=0xa774268>>, @device=#<LIBUSB::Device 6/2 0801:0011 Mag-Tek USB Swipe Reader B05A9C4 (HID (00,00))>, @interface=#<LIBUSB::Interface 0>, @endpoint=#<LIBUSB::Endpoint 1 IN  Interrupt>, @open=false>
irb(main):006:0> mcr.open
=> true
irb(main):007:0> s,n,na,y,m = mcr.read(:timeout => 10000)
=> false
irb(main):008:0> s,n,na,y,m = mcr.read(:timeout => 10000)
=> false
thirtysixthspan commented 11 years ago

What type of card is it? Have you tried others?

On Wed, Apr 17, 2013 at 3:30 AM, Marvin Frederickson < notifications@github.com> wrote:

I made sure that I had r/w access to the usb device, then ran the example code from the README, and it keeps returning false when I try to swipe my own card. Not using the server, just want to see it successfully read the card. Any ideas?

irb(main):004:0> mad = Magtek.available_devices => [[17, "USB Swipe Reader"]] irb(main):005:0> mcr = Magtek::CardReader.new => #<Magtek::CardReader:0xa6e3b10 @usb=#<LIBUSB::Context:0xa6e2f6c @ctx=#>, @device=#<LIBUSB::Device 6/2 0801:0011 Mag-Tek USB Swipe Reader B05A9C4 (HID (00,00))>, @interface=#<LIBUSB::Interface 0>, @endpoint=#<LIBUSB::Endpoint 1 IN Interrupt>, @open=false> irb(main):006:0> mcr.open => true irb(main):007:0> s,n,na,y,m = mcr.read(:timeout => 10000) => false irb(main):008:0> s,n,na,y,m = mcr.read(:timeout => 10000) => false

— Reply to this email directly or view it on GitHubhttps://github.com/thirtysixthspan/magtek_card_reader/issues/1 .

mfrederickson commented 11 years ago

I tried both a credit and a debit card. MagTek said that that unit has level 3 security and is encrypted at the head.

So most likely we can't parse the data. Does this make sense? He said to get a different unit that has level 2 which a sends data out plain text.

mfrederickson commented 11 years ago

I've got the new reader. When I run Sublime Text and swipe the card, data shows up in the window. When I try the sample code in the README, I'm having a problem where it can't open the device. I've installed the two gems.

irb(main):002:0> mcr = Magtek::CardReader.new
=> #<Magtek::CardReader:0x00000006647868 @usb=#<LIBUSB::Context:0x000000066744a8 @ctx=#<FFI::Pointer address=0x0000000653c060>>, @device=#<LIBUSB::Device 1/16 0801:0001 ? ? ? (HID (01,01))>, @interface=#<LIBUSB::Interface 0>, @endpoint=#<LIBUSB::Endpoint 1 IN  Interrupt>, @open=false>
irb(main):004:0> mcr.open
=> false
irb(main):005:0> Magtek::available_devices
=> [[1, "?"]]
irb(main):006:0> 

Seems like it doesn't know about the model of the device since it's showing "?"...

and lsusb shows

Bus 001 Device 016: ID 0801:0001 MagTek Mini Swipe Reader (Keyboard Emulation)

Maybe it's in the wrong mode?

I've got a point-of-sale system running as a rails app on the server (kiosk machine) and I want the user to be able to click the "swipe card" button, then swipe the card and have the information go into the appropriate fields. I'm planning on having the button use ujs to invoke the command to read/parse the card and then send the results back and have js populate the appropriate fields. Is this the correct way to do it?

What do I need to do to get it to read the card as in the example?

mfrederickson commented 11 years ago

I switched the mode from Keyboard Emulation to HID and the product id changed to 0002, but still no dice. Then I ran irb via rvmsudo and it worked. Now I just need to research setting the proper permissions...

mfrederickson commented 11 years ago

I solved it by adding a file to my Ubuntu Desktop 12.04 system under /etc/udev/rules.d called 99-magtek.rules with the following contents.

ATTRS{idVendor}=="0801", ATTRS{idProduct}=="0002", MODE="666", GROUP="plugdev"

Then I made sure I was a member of the plugdev group. Works fine now.

As a side note, when I ran lsusb -v -d 0801:0002 before I had this fixed, as a normal user, it would say Couldn't open device,some information will be missing but when I ran it as root via sudo it would give me the whole listing-- just like it does now when I run it as a normal user now that the permissions are fixed. I had tried a little tighter security with a MODE of 660 but that did not solve the problem.

@thirtysixthspan I'd be interested in your feedback on my planned implementation for the reader that I mentioned a couple posts up... Thanks.

thirtysixthspan commented 11 years ago

Glad you got these permission issues sorted out.

We created a kiosk as well, but our server is in the cloud. Using ajax, the website polls the card reader server which handles reading from the device and encrypting the CC data. You might not need the encryption component if your rails server is right on the machine.

The only suggestion I can make is: there is no reason to force the user to push a swipe card button. Instead you can continually poll the device for a card swipe with a short timeout. This will eliminate one step.

Thanks!