Guest User

Untitled

a guest
Dec 7th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. import gateway
  2. import datetime
  3. import smtplib
  4. merchant = {'merchantKey': '',
  5. 'processorId': '',
  6. }
  7. data = dict(merchant)
  8. cardNumber = request.GET.get("cardNumber", "")
  9. cardExpYear = request.GET.get("cardExpYear", "")
  10. cardExpMonth = request.GET.get("cardExpMonth", "")
  11. fullName = request.GET.get("fullName", "")
  12. accountIDOriginal = request.GET.get("accountID", "")
  13. accountID = accountIDOriginal.split('-')[0]
  14. if Payments.objects.filter(accountID=accountID,paymentDate=str(datetime.date.today())).count() > 0:
  15. return HttpResponse('You Have already ran a payment today.')
  16. else:
  17. theAccount = Account.objects.get(acctno=accountID)
  18. collectorID = theAccount.collector_id
  19. collectorEmail = Collector.objects.get(pk=collectorID).email
  20. ownerZip = request.GET.get("ownerZip", "")
  21. ownerState = request.GET.get("ownerState", "")
  22. ownerStreet = request.GET.get("ownerStreet", "")
  23. ownerCity = request.GET.get("ownerCity", "")
  24. cVV = request.GET.get("cVV", "")
  25. transactionAmountString = request.GET.get("transactionAmount", "")
  26. transactionAmount = Decimal(transactionAmountString)
  27. if ownerState == "CO" or ownerState == "co" or ownerState == "Co":
  28. creditCardCharge = round(transactionAmount * Decimal(1.00),2)
  29. else:
  30. creditCardCharge = round(transactionAmount * Decimal(1.03),2)
  31. data['cardNumber'] = cardNumber
  32. data['cardExpMonth'] = cardExpMonth
  33. data['cardExpYear'] = cardExpYear
  34. data['ownerState'] = ownerState
  35. data['ownerCity'] = ownerCity
  36. data['ownerName'] = fullName
  37. data['ownerStreet'] = ownerStreet
  38. data['ownerState'] = ownerState
  39. data['ownerZip'] = ownerZip
  40. data['cVV'] = cVV
  41. data['transactionAmount'] = creditCardCharge
  42. sale = gateway.RestGateway(data)
  43. resultsCC = str(sale.createSale())
  44. if sale.status == 'Success':
  45. fromaddr = 'email@domain.com'
  46. subject = 'New CC Payment'
  47. actualaccountid = Account.objects.get(acctno=accountID).accountid
  48. email = str(fullName) + str(' has made a payment for the amount of ') + str(transactionAmount) + str(
  49. '. Account ID is ') + str(accountID) + str("""
  50. https://web.domain.com/admin/web/account/""") + str(actualaccountid)
  51. message = 'Subject: %snn%s' % (subject, email)
  52. username = 'emailaddress'
  53. password = 'password'
  54. server = smtplib.SMTP('smtp.gmail.com:587')
  55. server.ehlo()
  56. server.starttls()
  57. server.login(username, password)
  58. server.sendmail(fromaddr, collectorEmail, message)
  59. server.quit()
  60. previousBalance = theAccount.balance
  61. clientNumber = Account.objects.get(acctno=accountID).cl_no
  62. client = Client.objects.get(cl_no=clientNumber)
  63. clRates = Decimal(client.cl_rates)
  64. clientsRateCorrected = clRates / Decimal(100.00)
  65. agFee = Decimal(clientsRateCorrected) * transactionAmount
  66. # calculate taxes
  67. if client.cl_taxable == "Y":
  68. tax = transactionAmount * Decimal(client.cl_taxrate)
  69. tax = transactionAmount * Decimal(client.cl_taxrate)
  70. else:
  71. tax = '0.0'
  72. # calculate new balance
  73. newBalance = Decimal(theAccount.balance) - transactionAmount
  74. # save Account with new Balance
  75. theAccount.balance = Decimal(newBalance)
  76. # set new DLP
  77. theAccount.lastamt = transactionAmount
  78. theAccount.doctor_id = 3
  79. theAccount.lastpay = str(datetime.date.today())
  80. theAccount.save()
  81. newPayment = Payments(paymentDate=str(datetime.date.today()),
  82. # claimDate='',
  83. accountID_id=theAccount.acctno,
  84. firstName=theAccount.first,
  85. lastName=theAccount.last,
  86. clientID=clientNumber,
  87. pAgency=transactionAmount,
  88. pClient=0.00,
  89. rate=client.cl_rates,
  90. agFee=agFee,
  91. taxable=client.cl_taxable,
  92. tax=tax,
  93. # desc='',
  94. fee=0.00,
  95. # expense='',
  96. # adjust='',
  97. # salesman='',
  98. balance=newBalance,
  99. # intDue='',
  100. status='$',
  101. # area='',
  102. ref_no='',
  103. collector=theAccount.collector,
  104. # cref_date='',
  105. clName=client.cl_name,
  106. # referred='',
  107. # contact='',
  108. isCC=True,
  109. isProccessed=False,
  110. creditCardChargedDate=str(datetime.date.today()),
  111. )
  112. newPayment.save()
  113. paymentID = newPayment.paymentID
  114. handlingFee = Decimal(creditCardCharge) - Decimal(transactionAmount)
  115. clientName = Client.objects.get(cl_no=theAccount.cl_no).cl_name
  116. colelctorEmail = Collector.objects.get(name=theAccount.collector).email
  117. newReceipt = Invoice(paymentID=paymentID,
  118. clientName=clientName,
  119. accountNumber=theAccount.acctno,
  120. claimNumber=theAccount.ref_no,
  121. handlingFee=Decimal(handlingFee),
  122. paymentAmount=Decimal(transactionAmount),
  123. paymentAmountWithHandling=Decimal(creditCardCharge),
  124. ccCharge=True,
  125. newBalance=Decimal(newBalance),
  126. previousBalance=Decimal(previousBalance),
  127. originalBalance=Decimal(theAccount.referred),
  128. paymentDate=str(datetime.date.today()),
  129. collector=theAccount.collector,
  130. fullName=fullName,
  131. lastFourofCard=1234,
  132. collectorEmailAddress = colelctorEmail
  133. )
  134. newReceipt.save()
  135. return HttpResponse(str('https://domain.com/invoices/') + str(newReceipt.pk) + str('/') + str(theAccount.acctno) + str('/'))
  136. #return HttpResponse(final)
  137. else:
  138. fromaddr = 'email'
  139. subject = 'Error CC Payment'
  140. actualaccountid = Account.objects.get(acctno=accountID).accountid
  141. email = str(fullName) + str(' has attempted to make a payment for the amount of ') + str(transactionAmount) + str(
  142. '. Account ID is ') + str(accountID) + str("""
  143.  
  144. Attached are the error results from the card being ran:
  145. """) + str(resultsCC)
  146. message = 'Subject: %snn%s' % (subject, email)
  147. username = 'email'
  148. password = 'Password'
  149. server = smtplib.SMTP('smtp.gmail.com:587')
  150. server.ehlo()
  151. server.starttls()
  152. server.login(username, password)
  153. server.sendmail(fromaddr, collectorEmail, message)
  154. server.quit()
  155. response = "An Error Has Occured. Please Contact ____ for Help."
  156. return HttpResponse(response)
Add Comment
Please, Sign In to add comment