def test_capture_error_response(stripe_payment, sandbox_gateway_config): INVALID_INTENT = "THIS_INTENT_DOES_NOT_EXISTS" payment_info = create_payment_information(stripe_payment, INVALID_INTENT) response = capture(payment_info, sandbox_gateway_config) assert response.error == "No such payment_intent: " + INVALID_INTENT assert response.transaction_id == INVALID_INTENT assert response.kind == TransactionKind.CAPTURE assert not response.is_success assert response.amount == stripe_payment.total assert response.currency == stripe_payment.currency
def test_capture_not_authorized(stripe_payment, gateway_params): payment = stripe_payment txn, error = capture(payment, TRANSACTION_AMOUNT, **gateway_params) assert error == ORDER_NOT_AUTHORIZED assert txn.payment == payment assert txn.token == '' assert txn.kind == TransactionKind.CAPTURE assert not txn.is_success assert txn.amount == payment.total assert txn.currency == TRANSACTION_CURRENCY assert txn.gateway_response == {}
def test_capture_3d_secure(stripe_payment, sandbox_gateway_config): PAYMENT_INTENT = "pi_1F6YmgIUmJaD6Oqv77HUh6qq" ERROR = ("This PaymentIntent could not be captured because it" " has a status of requires_action." " Only a PaymentIntent with one of the following " "statuses may be captured: requires_capture.") payment_info = create_payment_information(stripe_payment, PAYMENT_INTENT) response = capture(payment_info, sandbox_gateway_config) assert response.error == ERROR assert response.kind == TransactionKind.CAPTURE assert isclose(response.amount, TRANSACTION_AMOUNT) assert response.currency == TRANSACTION_CURRENCY assert not response.is_success assert response.action_required
def test_capture(stripe_authorized_payment, sandbox_gateway_config): # Get id from sandbox for intent not yet captured INTENT_ID = "pi_1F5BsRIUmJaD6Oqvz2XMKZCD" payment_info = create_payment_information(stripe_authorized_payment, payment_token=INTENT_ID) response = capture(payment_info, sandbox_gateway_config) assert not response.error assert response.transaction_id == INTENT_ID assert response.kind == TransactionKind.CAPTURE assert response.is_success assert isclose(response.amount, TRANSACTION_AMOUNT) assert response.currency == TRANSACTION_CURRENCY assert response.card_info == CARD_SIMPLE_DETAILS
def test_capture_error_response(mock_charge_retrieve, stripe_authorized_payment, gateway_params): payment = stripe_authorized_payment stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error txn, error = capture(payment, TRANSACTION_AMOUNT, **gateway_params) assert error == ERROR_MESSAGE assert txn.payment == payment assert txn.token == '' assert txn.kind == TransactionKind.CAPTURE assert not txn.is_success assert txn.amount == payment.total assert txn.currency == payment.currency assert txn.gateway_response == _get_error_response_from_exc(stripe_error)
def test_capture(mock_charge_retrieve, stripe_authorized_payment, gateway_params, stripe_charge_success_response): payment = stripe_authorized_payment response = stripe_charge_success_response mock_charge_retrieve.return_value = Mock(capture=Mock( return_value=response)) txn, error = capture(payment, TRANSACTION_AMOUNT, **gateway_params) assert not error assert txn.payment == payment assert txn.token == TRANSACTION_TOKEN assert txn.kind == TransactionKind.CAPTURE assert txn.is_success assert isclose(txn.amount, TRANSACTION_AMOUNT) assert txn.currency == TRANSACTION_CURRENCY assert txn.gateway_response == response
def test_capture(mock_charge_retrieve, stripe_authorized_payment, gateway_params, stripe_charge_success_response): payment = stripe_authorized_payment payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT) response = stripe_charge_success_response mock_charge_retrieve.return_value = Mock(capture=Mock( return_value=response)) response = capture(payment_info, gateway_params) assert not response.error assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE assert response.is_success assert isclose(response.amount, TRANSACTION_AMOUNT) assert response.currency == TRANSACTION_CURRENCY assert response.raw_response == stripe_charge_success_response
def test_capture_error_response(mock_charge_retrieve, stripe_authorized_payment, gateway_params): payment = stripe_authorized_payment payment_info = create_payment_information(payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error response = capture(payment_info, gateway_params) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE assert not response.is_success assert response.amount == payment.total assert response.currency == payment.currency assert response.raw_response == _get_error_response_from_exc(stripe_error)
def test_capture_error_response( mock_charge_retrieve, stripe_authorized_payment, gateway_config ): payment = stripe_authorized_payment payment_info = create_payment_information( payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT ) stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None) mock_charge_retrieve.side_effect = stripe_error response = capture(payment_info, gateway_config) assert response.error == ERROR_MESSAGE assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE assert not response.is_success assert response.amount == payment.total assert response.currency == payment.currency assert response.raw_response == _get_error_response_from_exc(stripe_error)
def test_partial_capture(mock_charge_retrieve, stripe_authorized_payment, gateway_params, stripe_partial_charge_success_response): payment = stripe_authorized_payment payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT) response = stripe_partial_charge_success_response mock_charge_retrieve.return_value = Mock(capture=Mock( return_value=response)) response = capture(payment_info, gateway_params) assert not response['error'] assert response['transaction_id'] == TRANSACTION_TOKEN assert response['kind'] == TransactionKind.CAPTURE assert response['is_success'] assert isclose(response['amount'], TRANSACTION_AMOUNT - TRANSACTION_REFUND_AMOUNT) assert response['currency'] == TRANSACTION_CURRENCY assert response['raw_response'] == stripe_partial_charge_success_response
def test_partial_capture( mock_charge_retrieve, stripe_authorized_payment, gateway_config, stripe_partial_charge_success_response, ): payment = stripe_authorized_payment payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT) response = stripe_partial_charge_success_response mock_charge_retrieve.return_value = Mock(capture=Mock(return_value=response)) response = capture(payment_info, gateway_config) assert not response.error assert response.transaction_id == TRANSACTION_TOKEN assert response.kind == TransactionKind.CAPTURE assert response.is_success assert isclose(response.amount, TRANSACTION_AMOUNT - TRANSACTION_REFUND_AMOUNT) assert response.currency == TRANSACTION_CURRENCY assert response.raw_response == stripe_partial_charge_success_response
def test_partial_capture( mock_charge_retrieve, stripe_authorized_payment, gateway_params, stripe_partial_charge_success_response): payment = stripe_authorized_payment payment_info = create_payment_information( payment, amount=TRANSACTION_AMOUNT) response = stripe_partial_charge_success_response mock_charge_retrieve.return_value = Mock( capture=Mock(return_value=response)) response = capture(payment_info, gateway_params) assert not response['error'] assert response['transaction_id'] == TRANSACTION_TOKEN assert response['kind'] == TransactionKind.CAPTURE assert response['is_success'] assert isclose(response['amount'], TRANSACTION_AMOUNT - TRANSACTION_REFUND_AMOUNT) assert response['currency'] == TRANSACTION_CURRENCY assert response['raw_response'] == stripe_partial_charge_success_response