A payment processor simulator
- Card and bank details RSA encrypted before stored
- Exception on credit cards starting with 1111 or 8888
- Exception on any expiry date in the past
- Bank routing numbers are validated
- Payouts made net of fees assessed at 2.9% + 30c per transaction or 1% + 1ドル for a bank transfer
- Transactions marked paid via date_paid_out after payout processing
main.rb is the program entry point
ruby main.rb
Create a Merchant
merchant_amazon = Merchant.new("Amazon")
Create a Credit Card
credit_card = CreditCard.new( card_number=4242424242424242, expiry=(Date.today + 365), cvv="123", billing_zip=92509, )
Create a Credit Card Transaction
cc_transaction = CreditCardTransaction.new( credit_card, today, 6.55, merchant_amazon )
Create a Bank Account
bank_account = BankAccount.new( "01100001534214", routing_number="011000015" )
Create a Bank Account Transaction
bank_transaction = BankTransaction.new( bank_account, today, 12.23, merchant_ebay )
Create a Payment Processor
payment_processor = PaymentProcessor.new
Accept Transactions
payment_processor.accept(cc_transaction) payment_processor.accept(bank_transaction)
Create Payouts given a Date
payouts = payment_processor.payout(today)
Pretty Print Transactions and Payouts
payment_processor.audit_date_and_merchant(today, merchant_ebay) payment_processor.audit_payouts(payouts)
Sample Ruby RSA Encryption and Decryption scripts
require 'openssl' require 'base64' # 1. Generate a private.pem key file # > openssl genrsa -des3 -out private.pem 2048 # config/rsa/private.pem # # 2. password: paymentprocessor # # 3. Generate public.pem keyfile # > openssl rsa -in private.pem -out public.pem -outform PEM -pubout # config/rsa/public.pem # Encrypt a string using public.pem keyfile public_key_file = "./config/rsa/public.pem" string = "Hello World!" public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file)) encrypted_string = Base64.encode64(public_key.public_encrypt(string)) p encrypted_string # Decrypt an encrypted string using private.pem keyfile private_key_file = './config/rsa/private.pem'; password = 'paymentprocessor' private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file),password) string = private_key.private_decrypt(Base64.decode64(encrypted_string)) print string, "\n"
Sample payment_processor_spec.rb RSpecs
> bundle exec rspec- RSpec standard output suppression
- Audit methods output format cleanup
- In payout.rb, instead of calculate_lump_sum_payout, consider running sum
- In payment_processor.rb, consider selecting transactions in one pass
- More specs, boundary case specs
- 'require' cleanup
- Web or desktop app w/ database
- Use cents (int) to transfer, store, and calculate price data, etc.