Last active
May 6, 2017 22:55
-
-
Save Q-Bert-Reynolds/4b9887eff333222361586010b5743a78 to your computer and use it in GitHub Desktop.
Reads input from a generic magnetic card reader and charges it 50 cents through Stripe.
This file contains 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
import stripe | |
stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" | |
while True: | |
swipe_data = raw_input() | |
if swipe_data[:2] == "%B": | |
fields = swipe_data[2:].split("^") | |
card_number = fields[0] | |
name = fields[1] | |
year = fields[2][:2] | |
month = fields[2][2:4] | |
print("\n" + name + ": " + card_number + " " + month + " - 20" + year + "\n") | |
card_token = stripe.Token.create( | |
card = { | |
"number": card_number, | |
"exp_month": 12, | |
"exp_year": 2018 | |
} | |
) | |
print(card_token + "\n") | |
charge_response = stripe.Charge.create( | |
amount = 50, | |
currency = "usd", | |
source = card_token["id"], | |
description = "Testing arcade payments" | |
) | |
print(charge_response + "\n") | |
else: | |
print("bad swipe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment