def charge_transaction(user, transaction_id, campaign_id): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if bid.is_charged(): return True, None if transaction_id < 0: bid.charged() return True, None profile_id = CustomerID.get_id(user._id) try: api.capture_authorization_hold( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=bid.bid, transaction_id=transaction_id, ) except api.AuthorizationHoldNotFound: # authorization hold has expired bid.void() return False, api.TRANSACTION_NOT_FOUND except api.TransactionError as e: return False, e.message bid.charged() return True, None
def charge_transaction(user, transaction_id, campaign_id): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if bid.is_charged(): return True, None if transaction_id < 0: bid.charged() return True, None profile_id = CustomerID.get_id(user._id) try: api.capture_authorization_hold( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=bid.bid, transaction_id=transaction_id, ) except api.AuthorizationHoldNotFound: # authorization hold has expired bid.void() return False, api.TRANSACTION_NOT_FOUND except api.TransactionError as e: return False, e.message bid.charged() return True, None
def charge_transaction(user, campaign_id, link_id, transaction_id, references): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if bid.is_charged(): return True, None if transaction_id < 0: bid.charged() return True, None references['pay_id'] = bid.pay_id profile_id = CustomerID.get_id(user._id) try: authorize_response = api.capture_authorization_hold( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=bid.bid, transaction_id=transaction_id, ) AuthorizeTransaction._new(authorize_response, **references) except api.AuthorizationHoldNotFound: # authorization hold has expired bid.void() return False, api.TRANSACTION_NOT_FOUND except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return False, e.message bid.charged() return True, None
def charge_transaction(user, campaign_id, link_id, transaction_id, references): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if bid.is_charged(): return True, None if transaction_id < 0: bid.charged() return True, None references["pay_id"] = bid.pay_id profile_id = CustomerID.get_id(user._id) try: authorize_response = api.capture_authorization_hold( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=bid.bid, transaction_id=transaction_id ) AuthorizeTransaction._new(authorize_response, **references) except api.AuthorizationHoldNotFound: # authorization hold has expired bid.void() return False, api.TRANSACTION_NOT_FOUND except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return False, e.message bid.charged() return True, None
def test_capture_authorization_hold(self, CreateRequest): _response = Mock() _request = Mock() _request.make_request.return_value = (True, _response) CreateRequest.return_value = _request # Scenario: call is successful return_value = capture_authorization_hold(self.customer_id, self.payment_profile_id, self.amount, self.transaction_id) self.assertTrue(CreateRequest.called) self.assertTrue(_request.make_request.called) self.assertEqual(return_value, _response) # Scenario: call raises TransactionError _request.make_request.return_value = (False, _response) self.assertRaises(TransactionError, capture_authorization_hold, self.customer_id, self.payment_profile_id, self.amount, self.transaction_id) # Scenario: _request call returns not found error _response.get.return_value = TRANSACTION_NOT_FOUND self.assertRaises(AuthorizationHoldNotFound, capture_authorization_hold, self.customer_id, self.payment_profile_id, self.amount, self.transaction_id)
def test_capture_authorization_hold(self, CreateRequest): _response = Mock() _request = Mock() _request.make_request.return_value = (True, _response) CreateRequest.return_value = _request # Scenario: call is successful return_value = capture_authorization_hold(self.customer_id, self.payment_profile_id, self.amount, self.transaction_id) self.assertTrue(CreateRequest.called) self.assertTrue(_request.make_request.called) self.assertEqual(return_value, _response) # Scenario: call raises TransactionError _request.make_request.return_value = (False, _response) self.assertRaises(TransactionError, capture_authorization_hold, self.customer_id, self.payment_profile_id, self.amount, self.transaction_id) # Scenario: _request call returns not found error _response.get.return_value = TRANSACTION_NOT_FOUND self.assertRaises(AuthorizationHoldNotFound, capture_authorization_hold, self.customer_id, self.payment_profile_id, self.amount, self.transaction_id)