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!'
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')
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')
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')
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')