def checkout(self): gateway = AfricasTalkingGateway(self.APP_USERNAME, self.API_KEY) try: transactionId = gateway.bankPaymentCheckoutCharge( productName_='Airtime Distribution', currencyCode_='NGN', amount_=100, narration_='Airtime Purchase Request', bankAccount_={ 'accountName': 'Fela Kuti', 'accountNumber': '123456789', 'bankCode': 234004 }, metadata_={'Reason': 'To Test The Gateways'}) print transactionId except AfricasTalkingGatewayException, e: print 'Encountered an error while sending: %s' % str(e)
class AfricasTalkingUtils: def __init__(self, **kwargs): #Specify your credentials self.username = "******" self.apiKey = os.environ.get('API_KEY') self.phonenumber = kwargs.get('phoneNumber', [None])[0] self.caller_number = kwargs.get('callerNumber', [None])[0] self.is_active = kwargs.get('isActive', [None])[0] self.duration_in_seconds = kwargs.get('du=rationInSeconds', [None])[0] self.currency_code = kwargs.get('currencyCode', [None])[0] self.amount = kwargs.get('amount', [None])[0] self.session_id = kwargs.get('sessionId', [None])[0] self.service_code = kwargs.get('serviceCode', [None])[0] self.text = kwargs.get('text')[0] self.customer = models.Account.get_current_customer(self.phonenumber) #Create an instance of our awesome gateway class and pass your credentials self.gateway = AfricasTalkingGateway(self.username, self.apiKey) def bank_checkout(self, **kwargs): # receive fund from customer try: # Send the request to the gateway. If successful, we will respond with # a transactionId that you can then use to validate the transaction transactionId = self.gateway.bankPaymentCheckoutCharge( productName_=PRODUCT_NAME, currencyCode_=CURRENCY, amount_=kwargs['amount'], narration_=kwargs['narration'], bankAccount_={ 'accountName': kwargs['account_name'], 'accountNumber': kwargs['account_num'], 'bankCode': kwargs['bank_code'] }, metadata_={'Reason': 'To Test The Gateways'}) return transactionId except AfricasTalkingGatewayException, e: print 'Encountered an error while sending: %s' % str(e)