def test_generate_sticker_number_for_ws_lease(provider_base_config, order: Order): create_ws_sticker_sequences() order.status = OrderStatus.OFFERED order.order_number = "abc123" order.save() application = order.lease.application application.area_type = ApplicationAreaType.UNMARKED application.save() rf = RequestFactory() request = rf.get("/payments/success/", success_params) payment_provider = create_bambora_provider(provider_base_config, request) returned = payment_provider.handle_success_request() order_after = Order.objects.get( order_number=success_params.get("ORDER_NUMBER").split("-")[0]) assert order_after.status == OrderStatus.PAID assert order_after.lease.application.status == ApplicationStatus.HANDLED assert order_after.lease.sticker_number == 1 assert isinstance(returned, HttpResponse) url = returned.url assert "/payment-result" in url assert "payment_status=success" in url
def test_handle_notify_request_success( provider_base_config, order: Order, ): """Test request notify helper returns http 204 and order status is correct when successful""" order.order_number = "abc123" order.status = OrderStatus.PAID order.lease.status = LeaseStatus.PAID order.lease.save() order.save() refund = OrderRefundFactory( order=order, refund_id="1234567", amount=order.total_price ) rf = RequestFactory() request = rf.get("/payments/notify_refund/", notify_success_params) payment_provider = create_bambora_provider(provider_base_config, request) assert refund.status == OrderRefundStatus.PENDING returned = payment_provider.handle_notify_refund_request() refund = OrderRefund.objects.get(refund_id=notify_success_params.get("REFUND_ID")) order = refund.order assert refund.status == OrderRefundStatus.ACCEPTED assert order.status == OrderStatus.REFUNDED assert order.lease.status == LeaseStatus.TERMINATED assert isinstance(returned, HttpResponse) assert returned.status_code == 204
def test_fulfill_contract(superuser_api_client, order: Order): order.lease.contract.save() order.order_number = FULFILL_CONTRACT_MUTATION_INPUT["orderNumber"] order.save() executed = superuser_api_client.execute( FULFILL_CONTRACT_MUTATION, input=FULFILL_CONTRACT_MUTATION_INPUT) assert (executed["data"]["fulfillContract"]["signingUrl"] == TestContractService.signing_url)
def test_fulfill_contract_no_contract_for_order(superuser_api_client, order: Order): order.lease.contract = None order.lease.save() order.order_number = FULFILL_CONTRACT_MUTATION_INPUT["orderNumber"] order.save() executed = superuser_api_client.execute( FULFILL_CONTRACT_MUTATION, input=FULFILL_CONTRACT_MUTATION_INPUT) assert_in_errors("No contract found for given order", executed)
def test_handle_notify_request_success( provider_base_config, berth_order: Order, order_status: OrderStatus, expected_order_status: OrderStatus, ): """Test request notify helper returns http 204 and order status is correct when successful""" berth_order.order_number = "abc123" berth_order.status = order_status berth_order.save() rf = RequestFactory() request = rf.get("/payments/notify/", success_params) payment_provider = create_bambora_provider(provider_base_config, request) returned = payment_provider.handle_notify_request() order_after = Order.objects.get( order_number=success_params.get("ORDER_NUMBER").split("-")[0]) assert order_after.status == expected_order_status assert isinstance(returned, HttpResponse) assert returned.status_code == 204
def test_handle_notify_request_success_for_ap_order( provider_base_config, berth_order: Order, ): berth_order.order_number = "abc123" berth_order.status = OrderStatus.OFFERED berth_order.order_type = OrderType.ADDITIONAL_PRODUCT_ORDER berth_order.save() rf = RequestFactory() request = rf.get("/payments/notify/", success_params) payment_provider = create_bambora_provider(provider_base_config, request) returned = payment_provider.handle_notify_request() order_after = Order.objects.get( order_number=success_params.get("ORDER_NUMBER").split("-")[0]) assert order_after.status == OrderStatus.PAID # it should not change the application and lease status in case of additional product order assert order_after.lease.application.status == ApplicationStatus.PENDING assert order_after.lease.status == LeaseStatus.DRAFTED assert isinstance(returned, HttpResponse) assert returned.status_code == 204
def test_handle_success_request_success(provider_base_config, order: Order): """Test request helper changes the order status to PAID Also check it returns a success url with order number""" order.status = OrderStatus.OFFERED order.order_number = "abc123" order.save() rf = RequestFactory() request = rf.get("/payments/success/", success_params) payment_provider = create_bambora_provider(provider_base_config, request) returned = payment_provider.handle_success_request() order_after = Order.objects.get( order_number=success_params.get("ORDER_NUMBER").split("-")[0]) assert order_after.status == OrderStatus.PAID assert order_after.lease.application.status == ApplicationStatus.HANDLED assert isinstance(returned, HttpResponse) url = returned.url assert "/payment-result" in url assert "payment_status=success" in url
def test_duplicate_payments_tokens_cancelled_notify_payment( provider_base_config, order: Order): # Fake the Payment initiate flow order.status = OrderStatus.OFFERED order.order_number = "abc123" order.save() request = RequestFactory().request() payment_provider = create_bambora_provider(provider_base_config, request) assert OrderToken.objects.count() == 0 with mock.patch( "payments.providers.bambora_payform.requests.post", side_effect=mocked_response_create, ) as mock_call: payment_provider.initiate_payment(order) assert OrderToken.objects.count() == 1 token = OrderToken.objects.first() assert token.order == order assert token.valid_until.isoformat( ) == "2019-01-20T21:59:59.999999+00:00" # Try to pay again 7 days after the day when the payment was created with freeze_time("2019-01-21T08:00:00Z"): url = payment_provider.initiate_payment(order) # Verify that the return URL passed includes the application language assert order.lease.application.language in mock_call.call_args.kwargs.get( "json").get("payment_method").get("return_url") assert OrderToken.objects.count() == 2 assert url.startswith(payment_provider.url_payment_api) assert "token/token123" in url # Fake the part where Bambora notifies the success/failure params = { "VENE_UI_RETURN_URL": "http%3A%2F%2F127.0.0.1%3A8000%2Fv1", "AUTHCODE": "DD789BA71ACD627892517745AF4C4CE2068F006C602CD54264E1FC5E4C2EE6CF", "RETURN_CODE": "1", "ORDER_NUMBER": "abc123-1602145394.662132", } rf = RequestFactory() request = rf.get("/payments/success/", params) payment_provider = create_bambora_provider(provider_base_config, request) payment_provider.handle_notify_request() order_after = Order.objects.get( order_number=params.get("ORDER_NUMBER").split("-")[0]) assert all([token.cancelled for token in order_after.tokens.all()]) with mock.patch( "payments.providers.bambora_payform.requests.post", side_effect=mocked_response_create, ): with freeze_time("2019-01-31T08:00:00Z"): payment_provider.initiate_payment(order) # The last token shouldn't be cancelled assert OrderToken.objects.count() == 3 assert OrderToken.objects.filter(cancelled=True).count() == 2 assert OrderToken.objects.filter(cancelled=False).count() == 1