def testinfo(self): transactions.info('123456', alternate_token='AN OAUTH TOKEN', dwollaparse='dwolla') transactions.r._get.assert_any_call('/transactions/123456', { 'client_secret': 'SOME ID', 'client_id': 'SOME ID' }, { 'alternate_token': 'AN OAUTH TOKEN', 'dwollaparse': 'dwolla' })
def dwolla_charge(sender, amount, order, event, pin, source): """ Charges to dwolla and returns a charge transaction. """ dwolla_prep(event.api_type) access_token = dwolla_get_token(sender, event.api_type) organization_access_token = dwolla_get_token(event.organization, event.api_type) if event.api_type == LIVE: destination = event.organization.dwolla_user_id else: destination = event.organization.dwolla_test_user_id user_charge_id = transactions.send( destinationid=destination, amount=amount, alternate_token=access_token, alternate_pin=pin, params={ "facilitatorAmount": float(get_fee(event, amount)), "fundsSource": source, "notes": "Order {} for {}".format(order.code, event.name), }, ) # Charge id returned by send_funds is the transaction ID # for the user; the event has a different transaction ID. # But we can use this one to get that one. event_charge = transactions.info(tid=str(user_charge_id), alternate_token=organization_access_token) return event_charge
def dwolla_charge(account, amount, order, event, pin, source): """ Charges to dwolla and returns a charge transaction. """ if amount < 0: raise InvalidAmountException('Cannot charge an amount less than zero.') if account.api_type != event.api_type: raise ValueError("Account and event API types do not match.") org_account = event.organization.get_dwolla_account(event.api_type) if not org_account or not org_account.is_connected(): raise ValueError("Event is not connected to dwolla.") dwolla_prep(account.api_type) access_token = account.get_token() organization_access_token = org_account.get_token() destination = org_account.user_id user_charge_id = transactions.send( destinationid=destination, amount=amount, alternate_token=access_token, alternate_pin=pin, params={ 'facilitatorAmount': float(get_fee(event, amount)), 'fundsSource': source, 'notes': "Order {} for {}".format(order.code, event.name), }, ) # Charge id returned by send_funds is the transaction ID # for the user; the event has a different transaction ID. # But we can use this one to get that one. event_charge = transactions.info(tid=str(user_charge_id), alternate_token=organization_access_token) return event_charge
def test_dwolla_charge__user(self): event = EventFactory(api_type=Event.TEST, application_fee_percent=Decimal('2.5')) event.organization.dwolla_test_account = DwollaOrganizationAccountFactory( ) event.organization.save() self.assertTrue(event.dwolla_connected()) dwolla_prep(Event.TEST) person = PersonFactory() person.dwolla_test_account = DwollaUserAccountFactory() person.save() order = OrderFactory(person=person, event=event, code='dwoll1') charge = dwolla_charge( account=person.dwolla_test_account, amount=42.15, order=order, event=event, pin=settings.DWOLLA_TEST_USER_PIN, source='Balance', ) self.assertIsInstance(charge, dict) self.assertEqual(charge["Type"], "money_received") self.assertEqual(len(charge['Fees']), 1) self.assertEqual(charge["Notes"], "Order {} for {}".format(order.code, event.name)) txn = Transaction.from_dwolla_charge(charge, event=event) # 42.15 * 0.025 = 1.05 self.assertEqual(Decimal(txn.application_fee), Decimal('1.05')) # 0.25 self.assertEqual(Decimal(txn.processing_fee), Decimal('0')) refund = dwolla_refund(order=order, event=event, payment_id=txn.remote_id, amount=txn.amount, pin=settings.DWOLLA_TEST_ORGANIZATION_PIN) self.assertIsInstance(refund, dict) self.assertEqual(refund["Amount"], txn.amount) refund_info = transactions.info( tid=str(refund['TransactionId']), alternate_token=event.organization.get_dwolla_account( event.api_type).get_token()) self.assertEqual(refund_info["Notes"], "Order {} for {}".format(order.code, event.name)) refund_txn = Transaction.from_dwolla_refund(refund, txn, event=event) self.assertEqual(refund_txn.amount, -1 * txn.amount) self.assertEqual(refund_txn.application_fee, 0) self.assertEqual(refund_txn.processing_fee, 0)
def test_dwolla_charge__user(self): event = EventFactory(api_type=Event.TEST, application_fee_percent=Decimal('2.5')) self.assertTrue(event.dwolla_connected()) dwolla_prep(Event.TEST) person = PersonFactory() order = OrderFactory(person=person, event=event) charge = dwolla_charge( sender=person, amount=42.15, order=order, event=event, pin=settings.DWOLLA_TEST_USER_PIN, source='Balance', ) self.assertIsInstance(charge, dict) self.assertEqual(charge["Type"], "money_received") self.assertEqual(len(charge['Fees']), 2) self.assertEqual(charge["Notes"], "Order {} for {}".format(order.code, event.name)) txn = Transaction.from_dwolla_charge(charge, event=event) # 42.15 * 0.025 = 1.05 self.assertEqual(Decimal(txn.application_fee), Decimal('1.05')) # 0.25 self.assertEqual(Decimal(txn.processing_fee), Decimal('0.25')) refund = dwolla_refund( order=order, event=event, payment_id=txn.remote_id, amount=txn.amount, pin=settings.DWOLLA_TEST_ORGANIZATION_PIN ) self.assertIsInstance(refund, dict) self.assertEqual(refund["Amount"], txn.amount) refund_info = transactions.info( tid=str(refund['TransactionId']), alternate_token=dwolla_get_token(event.organization, event.api_type) ) self.assertEqual(refund_info["Notes"], "Order {} for {}".format(order.code, event.name)) refund_txn = Transaction.from_dwolla_refund(refund, txn, event=event) self.assertEqual(refund_txn.amount, -1 * txn.amount) self.assertEqual(refund_txn.application_fee, 0) self.assertEqual(refund_txn.processing_fee, 0)
# Example 3: Refund $2 from "Balance" from transaction # '123456' print transactions.refund('3452346', 'Balance', 2.00) # Return: # { # "TransactionId": 4532, # "RefundDate": "2014-12-10T12:01:09Z", # "Amount": 2.00 # } # Example 4: Get info for transaction ID '123456'. print transactions.info('113533') # Return: # { # "Id": 113533, # "Amount": 5.50, # "Date": "2014-12-13T05:07:15Z", # "Type": "money_sent", # "UserType": "Email", # "DestinationId": "812-197-4121", # "DestinationName": "Some Name", # "Destination": { # "Id": "812-197-4121", # "Name": "Some Name", # "Type": "dwolla", # "Image": "" # },
def testinfo(self): transactions.info('123456', alternate_token='AN OAUTH TOKEN', dwollaparse='dwolla') transactions.r._get.assert_any_call('/transactions/123456', {'client_secret': 'SOME ID', 'client_id': 'SOME ID'}, {'alternate_token':'AN OAUTH TOKEN', 'dwollaparse':'dwolla'})
# Example 3: Refund $2 from "Balance" from transaction # '123456' print(transactions.refund('3452346', 'Balance', 2.00)) # Return: # { # "TransactionId": 4532, # "RefundDate": "2014-12-10T12:01:09Z", # "Amount": 2.00 # } # Example 4: Get info for transaction ID '123456'. print(transactions.info('113533')) # Return: # { # "Id": 113533, # "Amount": 5.50, # "Date": "2014-12-13T05:07:15Z", # "Type": "money_sent", # "UserType": "Email", # "DestinationId": "812-197-4121", # "DestinationName": "Some Name", # "Destination": { # "Id": "812-197-4121", # "Name": "Some Name", # "Type": "dwolla", # "Image": "" # },
def testinfo(self): transactions.info('123456') transactions.r._get.assert_any_call('/transactions/123456', {'client_secret': 'SOME ID', 'oauth_token': 'AN OAUTH TOKEN', 'client_id': 'SOME ID'})
# ] # Example 3: Refund $2 from "Balance" from transaction # '123456' print(transactions.refund('3452346', 'Balance', 2.00)) # Return: # { # "TransactionId": 4532, # "RefundDate": "2014-12-10T12:01:09Z", # "Amount": 2.00 # } # Example 4: Get info for transaction ID '123456'. print(transactions.info('113533')) # Return: # { # "Id": 113533, # "Amount": 5.50, # "Date": "2014-12-13T05:07:15Z", # "Type": "money_sent", # "UserType": "Email", # "DestinationId": "812-197-4121", # "DestinationName": "Some Name", # "Destination": { # "Id": "812-197-4121", # "Name": "Some Name", # "Type": "dwolla", # "Image": "" # },