Skip to content

Instantly share code, notes, and snippets.

@joeljackson
Created June 24, 2015 23:06
Show Gist options
  • Save joeljackson/8025d3a4032b5bbbe4ac to your computer and use it in GitHub Desktop.
Save joeljackson/8025d3a4032b5bbbe4ac to your computer and use it in GitHub Desktop.
#This function encrypts
#returns encrypted card number (if successful) and code
chaseEncrypt = (ccNumber, cvv) ->
embed = embed_encryption
card = {}
payment_provider =
options: {}
if is_pie_encryption_download_error() || is_pie_key_download_error()
scribe.log({user_id: user.id, error: 'cant load encryption js'}, 'payments_log', 'payments/credit_card/chase/tokenization/encrypting_card/failure')
scribe.log({user_id: user.id, error: 'cant load encryption js'}, 'payments_log', 'payments/chase/javascript_failure')
card.code = 2
if embed && !ValidatePANChecksum(ccNumber)
# Check MOD 10 digit, since PIE embedded encryption requires that the MOD 10 checksum is valid.
scribe.log({user_id: user.id, error: 'credit card number invalid checksum'}, 'payments_log', 'payments/credit_card/chase/tokenization/encrypting_card/failure')
card.code = 2
#returns encrypted cc number, encrypted cvv and integrity check value
response = ProtectPANandCVV(ccNumber, cvv, !embed)
if response != null && cvv.match(/^[0-9]{3,4}$/) != null
scribe.log({user_id: user.id, response: response}, 'payments_log', 'payments/credit_card/chase/tokenization/encrypting_card/success')
card.code = 0
payment_provider.options.embed_encryption = embed
payment_provider.options.key = PIE.key_id
payment_provider.options.phase = PIE.phase
payment_provider.options.integrity_check = response[2]
payment_provider.provider = 'chase'
card.cc_number = response[0].replace(/\D/g,'')
card.cvv = response[1]
card.credit_card_tokens_attributes = [payment_provider]
else
scribe.log({user_id: user.id, response: response, error: 'invalid cc or cvv'}, 'payments_log', 'payments/credit_card/chase/tokenization/encrypting_card/failure')
card.code = 1
card
@pugazhendhis
Copy link

I would like to know where this ProtectPANandCVV function is coming from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment