Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gateway
- import datetime
- import smtplib
- merchant = {'merchantKey': '',
- 'processorId': '',
- }
- data = dict(merchant)
- cardNumber = request.GET.get("cardNumber", "")
- cardExpYear = request.GET.get("cardExpYear", "")
- cardExpMonth = request.GET.get("cardExpMonth", "")
- fullName = request.GET.get("fullName", "")
- accountIDOriginal = request.GET.get("accountID", "")
- accountID = accountIDOriginal.split('-')[0]
- if Payments.objects.filter(accountID=accountID,paymentDate=str(datetime.date.today())).count() > 0:
- return HttpResponse('You Have already ran a payment today.')
- else:
- theAccount = Account.objects.get(acctno=accountID)
- collectorID = theAccount.collector_id
- collectorEmail = Collector.objects.get(pk=collectorID).email
- ownerZip = request.GET.get("ownerZip", "")
- ownerState = request.GET.get("ownerState", "")
- ownerStreet = request.GET.get("ownerStreet", "")
- ownerCity = request.GET.get("ownerCity", "")
- cVV = request.GET.get("cVV", "")
- transactionAmountString = request.GET.get("transactionAmount", "")
- transactionAmount = Decimal(transactionAmountString)
- if ownerState == "CO" or ownerState == "co" or ownerState == "Co":
- creditCardCharge = round(transactionAmount * Decimal(1.00),2)
- else:
- creditCardCharge = round(transactionAmount * Decimal(1.03),2)
- data['cardNumber'] = cardNumber
- data['cardExpMonth'] = cardExpMonth
- data['cardExpYear'] = cardExpYear
- data['ownerState'] = ownerState
- data['ownerCity'] = ownerCity
- data['ownerName'] = fullName
- data['ownerStreet'] = ownerStreet
- data['ownerState'] = ownerState
- data['ownerZip'] = ownerZip
- data['cVV'] = cVV
- data['transactionAmount'] = creditCardCharge
- sale = gateway.RestGateway(data)
- resultsCC = str(sale.createSale())
- if sale.status == 'Success':
- fromaddr = 'email@domain.com'
- subject = 'New CC Payment'
- actualaccountid = Account.objects.get(acctno=accountID).accountid
- email = str(fullName) + str(' has made a payment for the amount of ') + str(transactionAmount) + str(
- '. Account ID is ') + str(accountID) + str("""
- https://web.domain.com/admin/web/account/""") + str(actualaccountid)
- message = 'Subject: %snn%s' % (subject, email)
- username = 'emailaddress'
- password = 'password'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- server.login(username, password)
- server.sendmail(fromaddr, collectorEmail, message)
- server.quit()
- previousBalance = theAccount.balance
- clientNumber = Account.objects.get(acctno=accountID).cl_no
- client = Client.objects.get(cl_no=clientNumber)
- clRates = Decimal(client.cl_rates)
- clientsRateCorrected = clRates / Decimal(100.00)
- agFee = Decimal(clientsRateCorrected) * transactionAmount
- # calculate taxes
- if client.cl_taxable == "Y":
- tax = transactionAmount * Decimal(client.cl_taxrate)
- tax = transactionAmount * Decimal(client.cl_taxrate)
- else:
- tax = '0.0'
- # calculate new balance
- newBalance = Decimal(theAccount.balance) - transactionAmount
- # save Account with new Balance
- theAccount.balance = Decimal(newBalance)
- # set new DLP
- theAccount.lastamt = transactionAmount
- theAccount.doctor_id = 3
- theAccount.lastpay = str(datetime.date.today())
- theAccount.save()
- newPayment = Payments(paymentDate=str(datetime.date.today()),
- # claimDate='',
- accountID_id=theAccount.acctno,
- firstName=theAccount.first,
- lastName=theAccount.last,
- clientID=clientNumber,
- pAgency=transactionAmount,
- pClient=0.00,
- rate=client.cl_rates,
- agFee=agFee,
- taxable=client.cl_taxable,
- tax=tax,
- # desc='',
- fee=0.00,
- # expense='',
- # adjust='',
- # salesman='',
- balance=newBalance,
- # intDue='',
- status='$',
- # area='',
- ref_no='',
- collector=theAccount.collector,
- # cref_date='',
- clName=client.cl_name,
- # referred='',
- # contact='',
- isCC=True,
- isProccessed=False,
- creditCardChargedDate=str(datetime.date.today()),
- )
- newPayment.save()
- paymentID = newPayment.paymentID
- handlingFee = Decimal(creditCardCharge) - Decimal(transactionAmount)
- clientName = Client.objects.get(cl_no=theAccount.cl_no).cl_name
- colelctorEmail = Collector.objects.get(name=theAccount.collector).email
- newReceipt = Invoice(paymentID=paymentID,
- clientName=clientName,
- accountNumber=theAccount.acctno,
- claimNumber=theAccount.ref_no,
- handlingFee=Decimal(handlingFee),
- paymentAmount=Decimal(transactionAmount),
- paymentAmountWithHandling=Decimal(creditCardCharge),
- ccCharge=True,
- newBalance=Decimal(newBalance),
- previousBalance=Decimal(previousBalance),
- originalBalance=Decimal(theAccount.referred),
- paymentDate=str(datetime.date.today()),
- collector=theAccount.collector,
- fullName=fullName,
- lastFourofCard=1234,
- collectorEmailAddress = colelctorEmail
- )
- newReceipt.save()
- return HttpResponse(str('https://domain.com/invoices/') + str(newReceipt.pk) + str('/') + str(theAccount.acctno) + str('/'))
- #return HttpResponse(final)
- else:
- fromaddr = 'email'
- subject = 'Error CC Payment'
- actualaccountid = Account.objects.get(acctno=accountID).accountid
- email = str(fullName) + str(' has attempted to make a payment for the amount of ') + str(transactionAmount) + str(
- '. Account ID is ') + str(accountID) + str("""
- Attached are the error results from the card being ran:
- """) + str(resultsCC)
- message = 'Subject: %snn%s' % (subject, email)
- username = 'email'
- password = 'Password'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- server.login(username, password)
- server.sendmail(fromaddr, collectorEmail, message)
- server.quit()
- response = "An Error Has Occured. Please Contact ____ for Help."
- return HttpResponse(response)
Add Comment
Please, Sign In to add comment