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