def is_cc_expired(cc): # We will check if is expired... # We already validated this credit card card = pycard.Card(number='4242424242424242', month=cc['exp_month'], year=cc['exp_year'], cvc=cc['cvc']) return card.is_expired
def update(client_id, card_id): try: document = request.json credit_card = document['card'] credit_card['client_id'] = client_id address = document['address'] except: return make_response( jsonify({ 'status': 'ERROR', 'msg': 'São necessários dois objetos: card e address' }), 400) # checar se o schema está valido # ainda não checa se o cartao é valido err = CreditCard(credit_card).validate() if (len(err) > 0): return make_response(jsonify({'status': 'ERROR', 'msg': err}), 400) else: err = Address(address).validate() if (len(err) > 0): return make_response(jsonify({'status': 'ERROR', 'msg': err}), 400) else: card = pycard.Card(number=credit_card['number'], month=credit_card['exp_month'], year=credit_card['exp_year'], cvc=credit_card['cvc']) if card.is_valid: row = queries.find_address_by_card_id(card_id, g.db) if row is not None: queries.update_address(row['id'], address, g.db) queries.update_card(card_id, credit_card, g.db) g.db.commit() res, code = ({ 'status': 'OK', 'msg': 'Cartão atualizado.' }, 200) else: res, code = ({ 'status': 'ERROR', 'msg': 'Cliente ou cartão não encontrado.' }, 404) else: res, code = ({ 'status': 'ERROR', 'msg': 'Cartão inválido. Tente novamente' }, 400) return make_response(jsonify(res), code)
def clean_mes_val(self): """ Validação do cartão """ card = pycard.Card(number=str(self.data['numero']), month=int(self.cleaned_data['mes_val']), year=int(self.data['ano_val']), cvc=int(self.data['cvc'])) if card.is_expired: raise forms.ValidationError('Data de validade do cartão expirou.') return self.cleaned_data['mes_val']
def create(client_id): try: document = request.json credit_card = document['card'] credit_card['client_id'] = client_id address = document['address'] except: return make_response( jsonify({ 'status': 'ERROR', 'msg': 'São necessários dois objetos: card e address' }), 400) # checar se o schema está valido # ainda não checa se o cartao é valido err = CreditCard(credit_card).validate() if (len(err) > 0): return make_response(jsonify({'status': 'ERROR', 'msg': err}), 400) else: err = Address(address).validate() if (len(err) > 0): return make_response(jsonify({'status': 'ERROR', 'msg': err}), 400) else: card = pycard.Card(number=credit_card['number'], month=credit_card['exp_month'], year=credit_card['exp_year'], cvc=credit_card['cvc']) if card.is_valid: #save address first and get the id address_id = queries.save('address', address, g.db) credit_card['id'] = "card_%s" % uuid.uuid4() credit_card['brand'] = card.brand credit_card['last4'] = credit_card['number'][-4:] credit_card['address_id'] = address_id queries.save('card', credit_card, g.db) g.db.commit() res, code = ({ 'status': 'OK', 'msg': 'Cartão adicionado.' }, 201) else: res, code = ({ 'status': 'ERROR', 'msg': 'Cartão inválido. Tente novamente' }, 400) return make_response(jsonify(res), code)
def clean_numero(self): """ Validação do cartão """ card = pycard.Card(number=str(self.cleaned_data['numero']), month=int(self.data['mes_val']), year=int(self.data['ano_val']), cvc=int(self.data['cvc'])) if not card.is_mod10_valid: raise forms.ValidationError( 'Cartão invalido. Verifique se digitou todos os dados corretamente' ) return self.cleaned_data['numero']
def retry(payment_id, charge_id): # We will check if is expired... # We already validated this credit card row = find_charge_and_payment(payment_id, charge_id, g.db) card = pycard.Card(number='4242424242424242', month=row['exp_month'], year=row['exp_year'], cvc=row['cvc']) if not card.is_expired and not row['paid']: # simular... se for <= 80 é pq deu certo. if randint(0, 100) <= 80: # ok row['paid'] = True res, status = ({ 'status': 'OK', 'data': { 'id': row['charge_id'], 'amount': row['amount'], 'paid': row['paid'], 'source': { 'id': row['card_id'], 'last4': row['last4'], 'cvc': row['cvc'], 'brand': row['brand'], 'name': row['name'], 'exp_month': row['exp_month'], 'exp_year': row['exp_year'] } } }, 200) else: row['paid'] = False res, status = ({ 'status': 'ERROR', 'msg': 'Pagamento não autorizado.' }, 402) update(row['paid'], row['charge_id'], row['attempts'] + 1, g.db) return make_response(jsonify(res), status) return make_response( jsonify({ 'status': 'ERROR', 'msg': 'Pagamento já autorizado.' }), 402)
def validate_and_encrypt_cc(self, number, month, year, cvc=None, brand=None, test=False, obscure_char="*"): self.ensure_one() number = number and number.strip().replace(" ", "").replace("-", "") or "" obscure_qty = len(number) - 4 if year and len(str(year)) != 4: raise Warning("Please enter a 4 digit year") if len(number) < 12: raise Warning( "Credit Card number too short. Please check and try again.") card = pycard.Card(number, month, year, cvc) if card.is_expired: raise Warning("This card has expired.") elif not card.is_valid: raise Warning( "Invalid Credit Card number supplied. Please check and try again." ) elif (card.is_test and not test): raise Warning("This card is invalid. Please try a different card.") elif brand and (card.brand != brand) or False: raise Warning( "The card type does not appear to be correct. Please check and try again." ) #the card looks ok. Encrypt and obscure. secure_cc = self.encrypt(number) obscured_cc = self.obscure_text(number, num_visible=4, obscure_char=obscure_char) return (obscured_cc, secure_cc)
╚════██║██╔══██║██║ ██║ ██║ ██╔══██║██╔══╝ ██║ ██╔═██╗ ███████║██║ ██║██║ ██║ ╚██████╗██║ ██║███████╗╚██████╗██║ ██╗ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═╝ """) cardsfile = input(' \033[2;37;40m Enter the Cards file : ') print('\033[0;35m') cardsfile = open(cardsfile, 'r') for card in cardsfile: sp = card.split() number = str(sp[0]) month = int(sp[1]) year = int(sp[2]) cvc = int(sp[3]) #print(number,month,year,cvc) cards = pycard.Card(number, month, year, cvc) time.sleep(1) if cards.is_valid == True: print(" ") print("\033[0;32m [+] Card is valid ==> ", card, card, cards.friendly_brand, cards.is_expired) else: print(" ") print("\033[0;31;40m [!] Card is not valid ==> \033[0;33m", card, cards.friendly_brand)
#!/usr/bin/env python # -*- coding: UTF-8 -*- import pycard # Create a card card = pycard.Card(number='36085700210619', month=11, year=2017, cvc=309) # Validate the card (checks that the card isn't expired and is mod10 valid) assert card.is_valid # Perform validation checks individually assert not card.is_expired assert card.is_mod10_valid # The card is a visa assert card.brand == 'diners_club' assert card.friendly_brand == 'Diners Club' #assert card.mask == 'XXXX-XXXXXX-XXXX' # The card is a known test card assert card.is_test
df_source = pd.read_excel('', sheet_name=0) credit_card = df_source.copy() credit_card.columns credit_card.head() credit_card.columns.to_series().groupby(credit_card.dtypes).groups credit_card.info() #Add assetion to test that info() has no missing values. card = pycard.Card(number='4444333322221111', month=1, year=2020, cvc=123) # Validate the card (checks that the card isn't expired and is mod10 valid) assert card.is_valid # Perform validation checks individually assert not card.is_expired assert card.is_mod10_valid # The card is a visa assert card.brand == 'visa' assert card.friendly_brand == 'Visa' assert card.mask == 'XXXX-XXXX-XXXX-1111' # The card is a known test card assert card.is_test
def get_cc_brand(self, number): card = pycard.Card(number=number, month=1, year=1, cvc=None) return card.brand
def cc_is_expired(self, number, month, year, cvc=None): card = pycard.Card(number=number, month=month, year=year, cvc=cvc) return card.is_expired
def cc_no_is_valid(self, number, test=False): if len(number) < 12: raise Warning( "Credit Card number too short. Please check and try again.") card = pycard.Card(number=number, month=1, year=2000, cvc=None) return card.is_mod10_valid and not (test and not card.is_test)