def createCheckoutRequest(cls, credentials, paymentRequest):
     LogPagSeguro.info("PagSeguroPaymentService.Register(%s) - begin" % paymentRequest)
     connectionData = PagSeguroConnectionData(credentials, cls.serviceName)
     
     try:
         connection = PagSeguroHttpConnection()
         connection.post(cls.buildCheckoutRequestUrl(connectionData), PagSeguroPaymentParser.getData(paymentRequest), connectionData.getServiceTimeout(), connectionData.getCharset())
         httpStatus = PagSeguroHttpStatus(connection.getStatus())
         httpStatusType = httpStatus.getType()
         if httpStatusType == 'OK':
             paymentParserData = PagSeguroPaymentParser.readSuccessXml(connection.getResponse())
             paymentUrl = cls.buildCheckoutUrl(connectionData, paymentParserData.getCode())
             LogPagSeguro.info("PagSeguroPaymentService.Register(%s) - end %s" % (paymentRequest, paymentParserData.getCode()))
         elif httpStatusType == 'BAD_REQUEST':
             errors = PagSeguroPaymentParser.readErrors(connection.getResponse())
             e = PagSeguroServiceException(httpStatus, errors)
             LogPagSeguro.info("PagSeguroPaymentService.Register(%s) - error %s" % (paymentRequest, e.getOneLineMessage()))
             raise e
         else:
             e = PagSeguroServiceException(httpStatus)
             LogPagSeguro.info("PagSeguroPaymentService.Register(%s) - error %s" % (paymentRequest, e.getOneLineMessage()))
             raise e
         if paymentUrl:
             return paymentUrl
         return False
     except:
         LogPagSeguro.error("Exception:")
         raise NameError("ERROR")
 def searchByCode(cls, credentials, transactionCode):
     LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByCode(%s) - begin" % transactionCode);
     connectionData = PagSeguroConnectionData(credentials, cls.serviceName)
     try:
         connection = PagSeguroHttpConnection()
         connection.get(cls.buildSearchUrlByCode(connectionData, transactionCode),connectionData.getServiceTimeout(), connectionData.getCharset())
         httpStatus = PagSeguroHttpStatus(connection.getStatus())
         httpStatusType = httpStatus.getType()
         if httpStatusType == 'OK':
             x = connection.getResponse()
             transaction = PagSeguroTransactionParser.readTransaction(x)
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByCode(transactionCode=%s) - end %s" % (transactionCode, transaction))
         elif httpStatusType == 'BAD_REQUEST':
             errors = PagSeguroTransactionParser.readErrors(connection.getResponse())
             e = PagSeguroServiceException(httpStatus, errors)
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByCode(transactionCode=%s) - error %s" % (transactionCode, e.getOneLineMessage()))
             raise e
         else:
             e = PagSeguroServiceException(httpStatus)
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByCode(transactionCode=%s) - error %s" % (transactionCode, e.getOneLineMessage()))
             raise e
         if transaction:
             return transaction
         return False
     except:
         LogPagSeguro.error("Exception:")
         raise NameError("Error:")
 def searchByDate(cls, credentials, pageNumber, maxPageResults, initialDate, finalDate = None):
     LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByDate(initialDate=%s, finalDate=%s) - begin" % (PagSeguroHelper.formatDate(initialDate), PagSeguroHelper.formatDate(finalDate)))
     connectionData = PagSeguroConnectionData(credentials, cls.serviceName)
     searchParams = {'initialDate': PagSeguroHelper.formatDate(initialDate),
                     'pageNumber': pageNumber,
                     'maxPageResults': maxPageResults }
     if finalDate:
         searchParams['finalDate'] = PagSeguroHelper.formatDate(searchParams['finalDate'])
     else:
         searchParams['finalDate'] = None
     
     try:
         connection = PagSeguroHttpConnection()
         connection.get(cls.buildSearchUrlByDate(connectionData, searchParams),connectionData.getServiceTimeout(), connectionData.getCharset())
         httpStatus = PagSeguroHttpStatus(connection.getStatus())
         httpStatusType = httpStatus.getType()
         if httpStatusType == 'OK':
             searchResult = PagSeguroTransactionParser.readSearchResult(connection.getResponse())
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByDate(initialDate=%s,finalDate=%s) - end %s" % (PagSeguroHelper.formatDate(initialDate),PagSeguroHelper.formatDate(finalDate), searchResult))
         elif httpStatusType == 'BAD_REQUEST':
             errors = PagSeguroTransactionParser.readErrors(connection.getResponse())
             e = PagSeguroServiceException(httpStatus, errors)
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByDate(initialDate=%s,finalDate=%s) - error %s" % (PagSeguroHelper.formatDate(initialDate),PagSeguroHelper.formatDate(finalDate), e.getOneLineMessage()))
             raise e
         else:
             e = PagSeguroServiceException(httpStatus)
             LogPagSeguro.info("PagSeguroTransactionSearchService.SearchByDate(initialDate=%s,finalDate=%s) - error %s" % (PagSeguroHelper.formatDate(initialDate),PagSeguroHelper.formatDate(finalDate), e.getOneLineMessage()))
             raise e
         if searchResult:
             return searchResult
         return False
     except e:
         LogPagSeguro.error("Exception: %s" % e.getMessage())
         raise e
 def checkTransaction(cls, credentials, notificationCode):
     LogPagSeguro.info("PagSeguroNotificationService.CheckTransaction(notificationCode=%s) - begin" % notificationCode)
     connectionData = PagSeguroConnectionData(credentials, cls.serviceName)
     try:
         connection = PagSeguroHttpConnection()
         connection.get(cls.buildTransactionNotificationUrl(connectionData, notificationCode),connectionData.getServiceTimeout(),connectionData.getCharset())
         httpStatus = PagSeguroHttpStatus(connection.getStatus())
         httpStatusType = httpStatus.getType()
         if httpStatusType == 'OK':
             response = connection.getResponse()
             transaction = PagSeguroTransactionParser.readTransaction(response)
             #LogPagSeguro.info("PagSeguroNotificationService.CheckTransaction(notificationCode=%s) - end %s" % (notificationCode, transaction))
         elif httpStatusType == 'BAD_REQUEST':
             errors = PagSeguroTransactionParser.readErrors(connection.getResponse())
             e = PagSeguroServiceException(httpStatus, errors)
             LogPagSeguro.info("PagSeguroNotificationService.CheckTransaction(notificationCode=%s) - error %s" % (notificationCode, e.getOneLineMessage()))
             raise e
         else:
             e = PagSeguroServiceException(httpStatus)
             LogPagSeguro.info("PagSeguroNotificationService.CheckTransaction(notificationCode=%s) - error %s" % (notificationCode, e.getOneLineMessage()))
             raise e
         if transaction:
             return transaction
         return None
     except e:
         LogPagSeguro.error("Exception: %s" % e.getMessage())
         raise e
Esempio n. 5
0
	def __init__(self, email, token):
		resources = {
			'environment': {
				'production': {
					'webserviceUrl': "https://ws.pagseguro.uol.com.br"
				}		
			},
			'paymentService' : {
				'servicePath': "/v2/checkout",
				'checkoutUrl': "https://pagseguro.uol.com.br/v2/checkout/payment.html",
				'serviceTimeout': 20
			},
			'notificationService': {
				'servicePath': "/v2/transactions/notifications",
				'serviceTimeout': 20
			},
			'transactionSearchService': {
				'servicePath': "/v2/transactions",
				'serviceTimeout': 20
			}
		}
		configs = {
			'environment': {
				'environment': "production"
			},
			'credentials': {
				'email': email,
				'token': token
			},
			'application': {
				'charset': "ISO-8859-1"
			},
			'log': {
				'active': False,
				'fileLocation': ""
			}
		}
		self.resources = PagSeguroResources.init(resources)
		self.config = PagSeguroConfig.init(configs)
		self.log = LogPagSeguro.init()