Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import random
- from traceback import print_exc
- from suds.client import Client
- from suds.client import Client, sys
- from suds.sax.element import Element
- from suds.sax.attribute import Attribute
- from suds.xsd.sxbasic import Import
- from suds.wsse import UsernameToken, Security, Token, Timestamp
- import logging
- logging.getLogger('suds.client').setLevel(logging.DEBUG)
- from suds.plugin import MessagePlugin
- import uuid
- import json
- def payuMeaDoTransactionApiCall(args):
- urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
- if (args['store']['environment'] == 'staging') :
- urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'
- class LogPlugin(MessagePlugin):
- #def sending(self, context):
- # print(str(context.envelope))
- def received(self, context):
- #print(str(context.reply))
- return str(context.reply)
- #------------------------------------- CREATING CLIENT OBJECT--------------------------------------
- client = Client(urlToQuery, faults=False, plugins=[LogPlugin()])
- #------------------------------------- CREATING CUSTOM HEADER--------------------------------------
- wsse = ('wsse','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
- mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
- addressAttributeSecurity = Attribute('xmlns:wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
- AttributeUsernameToken1 = Attribute('wsu:Id','UsernameToken-9')
- addressAttributeUsernameToken = Attribute('xmlns:wsu','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd')
- addressAttributePassword = Attribute('Type','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')
- msgUsername = Element('Username', ns=wsse).setText(args['store']['soapUsername'])
- msgPassword = Element('Password', ns=wsse).setText(args['store']['soapPassword']).append(addressAttributePassword)
- msgUsernameToken = Element('UsernameToken', ns=wsse)
- msgUsernameToken.append(AttributeUsernameToken1)
- msgUsernameToken.append(addressAttributeUsernameToken)
- msgUsernameToken.insert(msgPassword).insert(msgUsername)
- msgSecurity = Element('Security', ns=wsse).addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
- msgSecurity.append(mustAttributeSecurity)
- msgSecurity.append(addressAttributeSecurity)
- msgSecurity.insert(msgUsernameToken)
- client.set_options(soapheaders=[msgSecurity])
- #------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
- transaction = {}
- transaction['Api'] = 'ONE_ZERO';
- transaction['Safekey'] = args['store']['safekey'];
- transaction['TransactionType'] = 'PAYMENT';
- transaction['AdditionalInformation'] = args['additionalInformation']
- transaction['Basket'] = args['basket']
- transaction['Customer'] = args['customer']
- transaction['Creditcard'] = args['creditcard']
- #------------------------------------- DOING SOAP CALL HERE--------------------------------------
- try:
- setTransaction = client.service.doTransaction(** transaction)
- trx_details = (setTransaction)[1]
- message = trx_details['displayMessage']
- payUReference = trx_details['payUReference']
- amountInCents = trx_details['paymentMethodsUsed'][0]['amountInCents']
- print amountInCents
- except Exception, e:
- print "----------------"
- print 'type is:', e.__class__.__name__
- print_exc()
- print "----------------"
- if __name__ == '__main__':
- try:
- doTransactionDetails = {}
- doTransactionDetails['store'] = {}
- doTransactionDetails['store']['soapUsername'] = '200208 '
- doTransactionDetails['store']['soapPassword'] = 'g1Kzk8GY'
- doTransactionDetails['store']['safekey'] = '{A580B3C7-3EF3-47F1-9B90-4047CE0EC54C}'
- doTransactionDetails['store']['environment'] = 'staging'
- doTransactionDetails['additionalInformation'] = {}
- doTransactionDetails['additionalInformation']['merchantReference'] = '02345670123' #random.randrange(1,10+1)
- doTransactionDetails['additionalInformation']['payUReference'] = str(uuid.uuid4())[:11]#11999149346
- doTransactionDetails['additionalInformation']['secure3d'] = False
- doTransactionDetails['basket'] = {}
- doTransactionDetails['basket']['description'] = "Product Description"
- doTransactionDetails['basket']['amountInCents'] = "10000"
- doTransactionDetails['basket']['currencyCode'] = 'NGN'
- doTransactionDetails['creditcard'] = {}
- doTransactionDetails['creditcard']['nameOnCard'] = "Mr John Doe"
- doTransactionDetails['creditcard']['cardNumber'] = "5453010000064261"
- doTransactionDetails['creditcard']['cardExpiry'] = "052017"
- doTransactionDetails['creditcard']['cvv'] = "123"
- doTransactionDetails['creditcard']['amountInCents'] = doTransactionDetails['basket']['amountInCents']
- doTransactionDetails['customer'] = {}
- doTransactionDetails['customer']['email'] = "john@doe.com"
- doTransactionDetails['customer']['firstName'] = 'John'
- doTransactionDetails['customer']['lastName'] = 'Doe'
- doTransactionDetails['customer']['mobile'] = '012345678'#'+2347035706380'
- payuMeaDoTransactionApiCall(doTransactionDetails)
- except Exception, e:
- print 'type is:', e.__class__.__name__
- print_exc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement