def test_refund_transaction(self, CreateRequest): _request = Mock() _request.make_request.return_value = (True, None) CreateRequest.return_value = _request # Scenario: call is successful refund_transaction(self.customer_id, self.payment_profile_id, self.amount, self.transaction_id) self.assertTrue(_request.make_request.called) # Scenario: call raises TransactionError _request.make_request.return_value = (False, Mock()) self.assertRaises(TransactionError, refund_transaction, self.customer_id, self.payment_profile_id, self.amount, self.transaction_id)
def refund_transaction(user, campaign_id, link_id, amount, transaction_id, references): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if transaction_id < 0: bid.refund(amount) return True, None references['pay_id'] = bid.pay_id profile_id = CustomerID.get_id(user._id) try: authorize_response = api.refund_transaction( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=amount, transaction_id=transaction_id, ) AuthorizeTransaction._new(authorize_response, **references) except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return False, e.message bid.refund(amount) return True, None
def refund_transaction(user, transaction_id, campaign_id, amount): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if transaction_id < 0: bid.refund(amount) return True, None profile_id = CustomerID.get_id(user._id) try: api.refund_transaction( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=amount, transaction_id=transaction_id, ) except api.TransactionError as e: return False, e.message bid.refund(amount) return True, None
def refund_transaction(user, campaign_id, link_id, amount, transaction_id, references): bid = Bid.one(transaction=transaction_id, campaign=campaign_id) if transaction_id < 0: bid.refund(amount) return True, None references["pay_id"] = bid.pay_id profile_id = CustomerID.get_id(user._id) try: authorize_response = api.refund_transaction( customer_id=profile_id, payment_profile_id=bid.pay_id, amount=amount, transaction_id=transaction_id ) AuthorizeTransaction._new(authorize_response, **references) except api.TransactionError as e: authorize_response = e.authorize_response AuthorizeTransaction._new(authorize_response, **references) return False, e.message bid.refund(amount) return True, None