Exemplo n.º 1
0
    def testStatelessness(self):
        """
        Test for an earlier bug, did not reset hash for new requests.
        """

        # Needs credentials to test
        self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))

        service = PayEx(merchant_number=MERCHANT_NUMBER,
                        encryption_key=ENCRYPTION_KEY,
                        production=False)

        # Create an agreement
        response = service.create_agreement(
            merchantRef='oneclick',
            description=u'One-click shopping æøåÆØÅ',
            purchaseOperation='SALE',
            maxAmount='100000',
        )

        # Create another agreement
        response = service.create_agreement(
            merchantRef='oneclick',
            description=u'One-click shopping æøåÆØÅ',
            purchaseOperation='SALE',
            maxAmount='100000',
        )

        # Ensure that the response is still valid
        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
        self.assertTrue('agreementRef' in response)
Exemplo n.º 2
0
 def auth_payment(self, **post):
     """
     Customer returns from PayEx. Look up status of order.
     """
     _logger.warn(post)
     ref = post.get('orderRef', '')
     if not ref:
         _logger.warn("Error in PayEx return. No reference found!")
         return "Error when contacting PayEx!"
     tx = request.env['payment.transaction'].sudo(
     )._payex_form_get_tx_from_data(post)
     if not tx:
         _logger.warn("Error in PayEx return. No transaction found!")
         return "Error when contacting PayEx!"
     service = PayEx(merchant_number=tx.acquirer_id.payex_account_nr,
                     encryption_key=tx.acquirer_id.payex_key,
                     production=tx.acquirer_id.environment == 'prod')
     response = service.complete(orderRef=ref)
     _logger.warn("PayEx response: %s" % response)
     if response:
         if request.env['payment.transaction'].sudo().with_context({
                 'orderRef':
                 ref
         }).form_feedback(response, 'payex'):
             return werkzeug.utils.redirect('/shop/payment/validate', 302)
         return "Couldn't verify your payment!"
     _logger.warn(
         "Error when contacting PayEx! Didn't get a response.\n%s" %
         response)
     return 'Error when contacting PayEx!'
Exemplo n.º 3
0
 def testStatelessness(self):
     """
     Test for an earlier bug, did not reset hash for new requests.
     """
     
     # Needs credentials to test
     self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))
     
     service = PayEx(
         merchant_number=MERCHANT_NUMBER, 
         encryption_key=ENCRYPTION_KEY, 
         production=False
     )
     
     # Create an agreement
     response = service.create_agreement(
         merchantRef='oneclick',
         description=u'One-click shopping æøåÆØÅ',
         purchaseOperation='SALE',
         maxAmount='100000',
     )
     
     # Create another agreement
     response = service.create_agreement(
         merchantRef='oneclick',
         description=u'One-click shopping æøåÆØÅ',
         purchaseOperation='SALE',
         maxAmount='100000',
     )
     
     # Ensure that the response is still valid
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')
     self.assertTrue('agreementRef' in response)
 def init_payment(self, **post):
     """
     Contact PayEx and redirect customer.
     """
     tx = request.env['payment.transaction'].sudo().browse(request.session.get('sale_transaction_id', []))
     _logger.warn("Hello world!!! TX %s" % tx )
     if not tx:
         werkzeug.utils.redirect('/shop/payment', 302)
     service = PayEx(
         merchant_number=tx.acquirer_id.payex_account_nr,
         encryption_key=tx.acquirer_id.payex_key,
         production=tx.acquirer_id.environment == 'prod')
     response = service.initialize(
         purchaseOperation = 'SALE',
         price = int(tx.amount * 100),
         currency = tx.currency_id.name,
         vat =int( (tx.sale_order_id.amount_tax / tx.sale_order_id.amount_untaxed) * 100),
         orderID = tx.reference,
         productNumber = tx.reference,
         description = 'Web order',
         clientIPAddress = request.httprequest.remote_addr,
         clientIdentifier = 'USERAGENT=%s' % request.httprequest.user_agent.string,
         additionalValues = 'RESPONSIVE=1',
         returnUrl = '%s/payment/payex/verify' % request.env['ir.config_parameter'].sudo().get_param('web.base.url'),
         view = tx.acquirer_id.payex_view,
         cancelUrl = '%s/shop/payment' % request.env['ir.config_parameter'].sudo().get_param('web.base.url'),
     )
     # code 	            String(128) 	Obsolete parameter, check errorCode.
     # errorCode 	    String 	        Indicates the result of the request. Returns OK if request is successful.
     # description 	    String(512) 	A literal description explaining the result. Returns OK if request is successful.
     # paramName 	    String 	        Returns the name of the parameter that contains invalid data.
     # thirdPartyError 	String 	        Returns the error code received from third party (not available for all payment methods).
     # orderRef 	        String(32) 	    This parameter is only returned if the parameter is successful, and returns a 32bit, hexadecimal value (Guid) identifying the orderRef.Example: 8e96e163291c45f7bc3ee998d3a8939c
     # sessionRef 	    String 	        Obsolete parameter.
     # redirectUrl 	    String 	        Dynamic URL to send the end user to, when using redirect model.
     if response:
         # ~ _logger.warn(response)
         _logger.warn("kalas %s" % response)
         status = response.get('status')
         if not status:
             _logger.warn("Error when contacting PayEx! Didn't get a status.\n%s" % response)
             return 'Error when contacting PayEx!'
         tx.state_message = status.get('description')
         if not status.get('errorCode'):
             _logger.warn("Error when contacting PayEx! Didn't get an error code.\n%s" % response)
             return 'Error when contacting PayEx!'
         if status.get('errorCode') != 'OK':
             _logger.warn("Error when contacting PayEx! Status not OK.\n%s" % response)
             return 'Error when contacting PayEx!'
         if not response.get('orderRef'):
             _logger.warn("Error when contacting PayEx! Didn't get an order reference.\n%s" % response)
             return 'Error when contacting PayEx!'
         if not response.get('redirectUrl'):
             _logger.warn("Error when contacting PayEx! Didn't get a redirect url.\n%s" % response)
             return 'Error when contacting PayEx!'
         tx.acquirer_reference = response.get('orderRef')
         return werkzeug.utils.redirect(response.get('redirectUrl'), 302)
     _logger.warn("Error when contacting PayEx! Didn't get a response.\n%s" % response)
     return 'Error when contacting PayEx!'
Exemplo n.º 5
0
    def testServiceSetup(self):

        service = PayEx(merchant_number='123', encryption_key='secret-string')

        # Check default values and setting of kwargs
        self.assertEquals(service.accountNumber, '123')
        self.assertEquals(service.encryption_key, 'secret-string')
        self.assertFalse(service.production)

        # Check that the order handlers are present
        self.assertTrue(
            isinstance(service.initialize, PxOrderInitialize8Handler))
        self.assertTrue(isinstance(service.complete, PxOrderCompleteHandler))
        self.assertTrue(isinstance(service.capture, PxOrderCapture4Handler))
        self.assertTrue(
            isinstance(service.get_transaction_details,
                       PxOrderGetTransactionDetails2Handler))
        self.assertTrue(isinstance(service.cancel, PxCancel2Handler))

        # Check that the agreement handlers are present
        self.assertTrue(
            isinstance(service.create_agreement, PxCreateAgreement3Handler))
        self.assertTrue(
            isinstance(service.delete_agreement, PxDeleteAgreementHandler))
        self.assertTrue(
            isinstance(service.check_agreement, PxAgreementCheckHandler))
        self.assertTrue(isinstance(service.autopay, PxAutoPay2Handler))
Exemplo n.º 6
0
 def is_verified(self):
     """
     Checks with PayEx if the agreement is verified.
     """
     
     from django.conf import settings
     from payex.service import PayEx
     
     # Initialize service
     service = PayEx(
         merchant_number=settings.PAYEX_MERCHANT_NUMBER, 
         encryption_key=settings.PAYEX_ENCRYPTION_KEY, 
         production=settings.PAYEX_IN_PRODUCTION
     )
     
     response = service.check_agreement(agreementRef=self.agreementref)
     
     if response['status']['description'] == 'OK':
         return response['agreementStatus'] == '1'
     
     return False
Exemplo n.º 7
0
    def testPayment(self):
        """
        Test the initialize7 and complete methods.
        """

        # Needs credentials to test
        self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))

        service = PayEx(merchant_number=MERCHANT_NUMBER,
                        encryption_key=ENCRYPTION_KEY,
                        production=False)

        # Initialize a payment
        response = service.initialize(
            purchaseOperation='AUTHORIZATION',
            price='5000',
            currency='NOK',
            vat='2500',
            orderID='test1',
            productNumber='123',
            description=u'This is a test. åâaä',
            clientIPAddress='127.0.0.1',
            clientIdentifier='USERAGENT=test&username=testuser',
            additionalValues='PAYMENTMENU=TRUE',
            returnUrl='http://example.org/return',
            view='PX',
            cancelUrl='http://example.org/cancel')

        # Check the response
        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
        self.assertTrue('orderRef' in response)
        self.assertTrue(response['redirectUrl'].startswith(
            'https://test-account.payex.com/MiscUI/PxMenu.aspx'))

        # Try to complete the order (even if it's not started by user)
        response = service.complete(orderRef=response['orderRef'])

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['errorCode'], 'NoRecordFound')

        # Get the transaction details
        response = service.get_transaction_details(transactionNumber='0')

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['errorCode'], 'NoRecordFound')

        # Try to capture a transaction
        response = service.capture(transactionNumber='0',
                                   amount='1000',
                                   vatAmount='250')

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['errorCode'], 'NoRecordFound')

        # Try to cancel a transaction
        response = service.cancel(transactionNumber='1')

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['errorCode'], 'Error_Generic')
Exemplo n.º 8
0
    def testAgreementHandlers(self):
        """
        Test the various agreement handlers.
        """

        # Needs credentials to test
        self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))

        service = PayEx(merchant_number=MERCHANT_NUMBER,
                        encryption_key=ENCRYPTION_KEY,
                        production=False)

        # Create an agreement
        response = service.create_agreement(
            merchantRef='oneclick',
            description=u'One-click shopping æøåÆØÅ',
            purchaseOperation='AUTHORIZATION',
            maxAmount='100000',
        )

        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
        self.assertTrue('agreementRef' in response)
        self.assertFalse('existingAgreementRef' in response)

        agreement_ref = response['agreementRef']

        # Initialize the payment
        response = service.initialize(
            purchaseOperation='AUTHORIZATION',
            price='5000',
            currency='NOK',
            vat='2500',
            orderID='test2',
            productNumber='123',
            description=u'This is a test with øæå.',
            clientIPAddress='127.0.0.1',
            clientIdentifier='USERAGENT=test&username=testuser',
            additionalValues='PAYMENTMENU=TRUE',
            returnUrl='http://example.org/return',
            view='PX',
            agreementRef=agreement_ref,
            cancelUrl='http://example.org/cancel')

        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
        self.assertTrue('redirectUrl' in response)
        self.assertTrue(response['orderRef'] in response['redirectUrl'])

        # Try to complete the order (even if it's not started by user)
        response = service.complete(orderRef=response['orderRef'])

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response['status']['errorCode'], 'NoRecordFound')

        # AutoPay with the agreement
        response = service.autopay(purchaseOperation='SALE',
                                   agreementRef=agreement_ref,
                                   price='1000',
                                   productNumber='123',
                                   description=u'This is a test with øæå.',
                                   orderId='900')

        self.assertEquals(response['status']['errorCode'],
                          'AgreementNotVerified')

        # Check the agreement
        response = service.check_agreement(agreementRef=agreement_ref)

        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
        self.assertEquals(response['agreementStatus'], '0')

        # Delete the agreement
        response = service.delete_agreement(agreementRef=agreement_ref)

        self.assertEquals(response['status']['description'], 'OK')
        self.assertEquals(response['status']['errorCode'], 'OK')
Exemplo n.º 9
0
 def testPayment(self):
     """
     Test the initialize7 and complete methods.
     """
     
     # Needs credentials to test
     self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))
     
     service = PayEx(
         merchant_number=MERCHANT_NUMBER, 
         encryption_key=ENCRYPTION_KEY, 
         production=False
     )
     
     # Initialize a payment
     response = service.initialize(
         purchaseOperation='AUTHORIZATION',
         price='5000',
         currency='NOK',
         vat='2500',
         orderID='test1',
         productNumber='123',
         description=u'This is a test. åâaä',
         clientIPAddress='127.0.0.1',
         clientIdentifier='USERAGENT=test&username=testuser',
         additionalValues='PAYMENTMENU=TRUE',
         returnUrl='http://example.org/return',
         view='PX',
         cancelUrl='http://example.org/cancel'
     )
     
     # Check the response
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')
     self.assertTrue('orderRef' in response)
     self.assertTrue(response['redirectUrl'].startswith('https://test-account.payex.com/MiscUI/PxMenu.aspx'))
     
     # Try to complete the order (even if it's not started by user)
     response = service.complete(orderRef=response['orderRef'])
     
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['errorCode'], 'NoRecordFound')
     
     # Get the transaction details
     response = service.get_transaction_details(transactionNumber='0')
     
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['errorCode'], 'NoRecordFound')
     
     # Try to capture a transaction
     response = service.capture(
         transactionNumber='0',
         amount='1000',
         vatAmount='250'
     )
     
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['errorCode'], 'NoRecordFound')
     
     # Try to cancel a transaction
     response = service.cancel(transactionNumber='1')
     
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['errorCode'], 'Error_Generic')
Exemplo n.º 10
0
 def testAgreementHandlers(self):
     """
     Test the various agreement handlers.
     """
     
     # Needs credentials to test
     self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))
     
     service = PayEx(
         merchant_number=MERCHANT_NUMBER, 
         encryption_key=ENCRYPTION_KEY, 
         production=False
     )
     
     # Create an agreement
     response = service.create_agreement(
         merchantRef='oneclick',
         description=u'One-click shopping æøåÆØÅ',
         purchaseOperation='AUTHORIZATION',
         maxAmount='100000',
     )
     
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')
     self.assertTrue('agreementRef' in response)
     self.assertFalse('existingAgreementRef' in response)
     
     agreement_ref = response['agreementRef']
     
     # Initialize the payment
     response = service.initialize(
         purchaseOperation='AUTHORIZATION',
         price='5000',
         currency='NOK',
         vat='2500',
         orderID='test2',
         productNumber='123',
         description=u'This is a test with øæå.',
         clientIPAddress='127.0.0.1',
         clientIdentifier='USERAGENT=test&username=testuser',
         additionalValues='PAYMENTMENU=TRUE',
         returnUrl='http://example.org/return',
         view='PX',
         agreementRef=agreement_ref,
         cancelUrl='http://example.org/cancel'
     )
     
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')
     self.assertTrue('redirectUrl' in response)
     self.assertTrue(response['orderRef'] in response['redirectUrl'])
     
     # Try to complete the order (even if it's not started by user)
     response = service.complete(orderRef=response['orderRef'])
     
     self.assertEquals(type(response), XmlDictConfig)
     self.assertEquals(response['status']['errorCode'], 'NoRecordFound')
     
     # AutoPay with the agreement
     response = service.autopay(
         purchaseOperation='SALE',
         agreementRef=agreement_ref,
         price='1000',
         productNumber='123',
         description=u'This is a test with øæå.',
         orderId='900'
     )
     
     self.assertEquals(response['status']['errorCode'], 'AgreementNotVerified')
     
     # Check the agreement
     response = service.check_agreement(agreementRef=agreement_ref)
     
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')
     self.assertEquals(response['agreementStatus'], '0')
     
     # Delete the agreement
     response = service.delete_agreement(agreementRef=agreement_ref)
     
     self.assertEquals(response['status']['description'], 'OK')
     self.assertEquals(response['status']['errorCode'], 'OK')