コード例 #1
0
def test_checkout_non_existing_price(authenticated_client,
                                     non_existing_price_id, stripe_public_key,
                                     checkout_session_data, restrict_products):
    make_request(authenticated_client.get,
                 'go-to-checkout',
                 404,
                 url_params={'price_id': non_existing_price_id})
コード例 #2
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_product_restrict_products(authenticated_client_with_customer_id, stripe_subscription_product_id,
                                   restrict_products, stripe_unsubscribed_product_id,
                                   expected_restricted_product, subscription, stripe_price_id,
                                   restricted_product_error, stripe_unsubscribed_price_id):
    response = make_request(authenticated_client_with_customer_id.get, 'products', 200)
    assert response.data == expected_restricted_product
    response = make_request(authenticated_client_with_customer_id.get, 'products', 403,
                            ids=[stripe_unsubscribed_product_id])
    assert response.data == restricted_product_error
    response = make_request(authenticated_client_with_customer_id.get, 'products', 200,
                            url_params={'obj_id': stripe_subscription_product_id})
    assert response.data == expected_restricted_product[0]
    response = make_request(authenticated_client_with_customer_id.get, 'products', 403,
                            url_params={'obj_id': stripe_unsubscribed_product_id})
    assert response.data == restricted_product_error
コード例 #3
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_new_setup_intent(authenticated_client_with_without_customer_id):
    response = make_request(authenticated_client_with_without_customer_id.post, "setup-intents", 201,
                            signal=signals.setup_intent_created)
    data = response.data
    assert data['id']
    assert data['client_secret']
    assert data['payment_method_types'] == ['card']
コード例 #4
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_payment_method(authenticated_client_with_customer_id,
                               user_with_customer_id,
                               payment_method_from_api):
    pm_id = payment_method_from_api['id']
    billing_details = {
                                'address': {
                                    'city': 'Castleknock',
                                    'state': 'Co. Dublin',
                                    'country': 'IE',
                                    'line1': 'Áras an Uachtaráin',
                                    'line2': 'Phoenix Park',
                                    'postal_code': 'D08 E1W3',
                                },
                                'name': 'Michael D Higgins',
                                'email': '*****@*****.**',
                                'phone': '+35312345678'
                            }
    response = make_request(authenticated_client_with_customer_id.put, "payment-methods", 200,
                            url_params={'obj_id': pm_id}, set_as_default=True,
                            billing_details=billing_details)
    updated_payment_method_info = response.data
    payment_method_from_api['billing_details'] = billing_details
    payment_method_from_api.pop('default')
    payment_method_from_api['card']['checks']['address_line1_check'] = "pass"
    payment_method_from_api['card']['checks']['address_postal_code_check'] = "pass"
    assert updated_payment_method_info == payment_method_from_api
コード例 #5
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_other_user_subscription(authenticated_client_second_user,
                                        stripe_subscription_product_id, payment_method_id,
                                        subscription, not_owned_subscription_error):
    response = make_request(authenticated_client_second_user.put, "subscriptions", 500,
                            url_params={'obj_id': subscription['id']},
                            default_payment_method=payment_method_id)
    assert response.data == not_owned_subscription_error
コード例 #6
0
def test_billing_portal(authenticated_client, billing_portal_data):
    response = make_request(authenticated_client.get,
                            "go-to-billing-portal",
                            302,
                            signal=signals.billing_portal_created)
    billing_portal_session = billing_portal_data['session']
    assert response.url == billing_portal_session['url']
コード例 #7
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_product_list_subscribed(authenticated_client_with_customer_id, expected_subscription_products_and_prices,
                                 stripe_subscription_product_id, stripe_unsubscribed_product_id,
                                 subscription):
    response = make_request(authenticated_client_with_customer_id.get, 'products', 200,
                            ids=[stripe_subscription_product_id,
                                 stripe_unsubscribed_product_id])
    assert response.data == expected_subscription_products_and_prices
コード例 #8
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_checkout_non_existing_price(authenticated_client_with_without_customer_id, user,
                                     non_existing_price_id, non_existing_price_id_error):
    response = make_request(authenticated_client_with_without_customer_id.post,
                            'checkout',
                            404,
                            url_params={'price_id': non_existing_price_id})
    assert response.data == non_existing_price_id_error
コード例 #9
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_subscription_non_existing_payment_method(authenticated_client_with_customer_id,
                                                         non_existing_payment_method_id,
                                                         non_existing_payment_method_error_2, subscription):
    response = make_request(authenticated_client_with_customer_id.put, "subscriptions", 500,
                            url_params={'obj_id': subscription['id']},
                            default_payment_method=non_existing_payment_method_id)
    assert response.data == non_existing_payment_method_error_2
コード例 #10
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_non_existing_subscription(authenticated_client_with_customer_id,
                                          stripe_subscription_product_id, payment_method_id,
                                          non_existing_subscription_id, no_such_subscription_error):
    response = make_request(authenticated_client_with_customer_id.put, "subscriptions", 500,
                            url_params={'obj_id': non_existing_subscription_id},
                            default_payment_method=payment_method_id)
    assert response.data == no_such_subscription_error
コード例 #11
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_product_list(client_no_user_and_user_with_and_without_stripe_id,
                      expected_subscription_products_and_prices_unsubscribed,
                      stripe_subscription_product_id, stripe_unsubscribed_product_id):
    response = make_request(client_no_user_and_user_with_and_without_stripe_id.get, 'products', 200,
                            ids=[stripe_subscription_product_id,
                                 stripe_unsubscribed_product_id])
    assert response.data == expected_subscription_products_and_prices_unsubscribed
コード例 #12
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_checkout_restrict_product(authenticated_client_with_without_customer_id, user, stripe_unsubscribed_price_id,
                                   restricted_price_error, restrict_products):
    response = make_request(authenticated_client_with_without_customer_id.post,
                            'checkout',
                            403,
                            url_params={'price_id': stripe_unsubscribed_price_id})
    assert response.data == restricted_price_error
コード例 #13
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_billing_portal(authenticated_client_with_without_customer_id, user):
    response = make_request(authenticated_client_with_without_customer_id.post,
                            'billing',
                            201,
                            signal=signals.billing_portal_created)
    assert list(response.data.keys()) == ['url']
    assert "stripe.com" in response.data["url"]
    assert_customer_id_exists(user)
コード例 #14
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_delete_subscription(authenticated_client_with_customer_id, stripe_subscription_product_id,
                             user_with_customer_id, subscription_id):
    response = make_request(authenticated_client_with_customer_id.delete, "subscriptions", 200,
                            signal=signals.subscription_cancelled, url_params={'obj_id': subscription_id})
    assert response.data['status'] == 'canceled'
    response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id)
    assert response['sub_id'] is None
    assert response['cancel_at'] is None
コード例 #15
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_subscription_change_default_payment_method_with_no_payment_method(
        authenticated_client_with_customer_id, subscription, default_payment_method_id,
        user_with_customer_id, no_default_payment_method_to_set_as_default_error, stripe_price_id):
    response = make_request(authenticated_client_with_customer_id.post, "subscriptions", 400,
                            price_id=stripe_price_id, set_as_default_payment_method=True)
    assert response.data == no_default_payment_method_to_set_as_default_error
    customer = stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id)
    assert customer['invoice_settings']['default_payment_method'] == default_payment_method_id
コード例 #16
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_unauthenticated_requests_blocked(api_client, method, view, price_id_as_url_params, stripe_price_id):
    method = getattr(api_client, method)
    url_params = {'price_id': stripe_price_id} if price_id_as_url_params else None
    response = make_request(method,
                            view,
                            403,
                            url_params=url_params)
    assert response.data == {'detail': 'Authentication credentials were not provided.'}
コード例 #17
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_setup_checkout(authenticated_client_with_without_customer_id, user, stripe_unsubscribed_price_id):
    response = make_request(authenticated_client_with_without_customer_id.post,
                            'setup-checkout',
                            201,
                            signal=signals.checkout_created)
    assert list(response.data.keys()) == ['id']
    assert response.data['id']
    assert_customer_id_exists(user)
コード例 #18
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_invoice_get_one(authenticated_client_with_customer_id, invoice):
    response = make_request(authenticated_client_with_customer_id.get, "invoices", 200,
                            url_params={'obj_id': invoice['id']})
    data = response.data
    assert data['hosted_invoice_url'] == invoice['hosted_invoice_url']
    assert tuple(data.keys()) == ('id', "amount_due", "amount_paid", "amount_remaining", "billing_reason",
                                  "created","hosted_invoice_url", "invoice_pdf",  "next_payment_attempt", "status",
                                  "subscription")
コード例 #19
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_get_one_subscription(authenticated_client_with_customer_id, subscription, subscription_response):
    response = make_request(authenticated_client_with_customer_id.get, "subscriptions", 200,
                            url_params={'obj_id': subscription['id']})
    assert response.data.pop('current_period_start') is not None
    assert response.data.pop('id') is not None
    assert response.data.pop('latest_invoice') is not None
    assert response.data.pop('start_date') is not None
    assert response.data.pop('created') is not None
    assert response.data == subscription_response
コード例 #20
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_delete_other_user_subscription(authenticated_client_second_user, user_with_customer_id,
                                        stripe_subscription_product_id, payment_method_id,
                                        subscription_id, not_owned_subscription_error):
    response = make_request(authenticated_client_second_user.delete, "subscriptions", 500,
                            url_params={'obj_id': subscription_id})
    assert response.data == not_owned_subscription_error
    response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id)
    assert response['sub_id'] == subscription_id
    assert response['cancel_at'] is None
コード例 #21
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_new_subscription_no_payment_method(authenticated_client_with_customer_id, user_with_customer_id,
                                            stripe_price_id, stripe_subscription_product_id,
                                            no_default_payment_method_error):
    response = make_request(authenticated_client_with_customer_id.post, "subscriptions", 500,
                            price_id=stripe_price_id)
    assert response.data == no_default_payment_method_error
    response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id)
    assert response['sub_id'] is None
    assert response['cancel_at'] is None
コード例 #22
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_invoice_list(authenticated_client_with_customer_id, invoice_filters):
    response = make_request(authenticated_client_with_customer_id.get, "invoices", 200, **invoice_filters)
    invoice = response.data[0]
    assert invoice["status"] == 'paid'
    assert invoice['billing_reason'] == 'subscription_create'
    assert invoice['hosted_invoice_url']
    assert invoice['invoice_pdf']
    assert tuple(invoice.keys()) == ('id', "amount_due", "amount_paid", "amount_remaining", "billing_reason", "created",
                                     "hosted_invoice_url", "invoice_pdf", "next_payment_attempt", "status",
                                     "subscription")
コード例 #23
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_list_subscriptions(authenticated_client_with_customer_id, subscription, subscription_response):
    response = make_request(authenticated_client_with_customer_id.get, "subscriptions", 200)
    sub = response.data[0]
    assert sub.pop('current_period_end') is not None
    assert sub.pop('current_period_start') is not None
    assert sub.pop('id') is not None
    assert sub.pop('latest_invoice') is not None
    assert sub.pop('start_date') is not None
    assert sub.pop('created') is not None
    assert response.data == [sub]
コード例 #24
0
def test_checkout_restricted_product(authenticated_client,
                                     stripe_unsubscribed_price_id,
                                     stripe_public_key, stripe_price_id,
                                     checkout_session_data, restrict_products):
    response = make_request(authenticated_client.get,
                            'go-to-checkout',
                            200,
                            signal=signals.checkout_created,
                            url_params={'price_id': stripe_price_id})
    html = response.rendered_content
    assert stripe_public_key.startswith('pk')
    checkout_session = checkout_session_data['session']
    expected_html = get_expected_checkout_html(stripe_public_key,
                                               checkout_session["id"])
    assert html == expected_html
    make_request(authenticated_client.get,
                 'go-to-checkout',
                 403,
                 url_params={'price_id': stripe_unsubscribed_price_id})
コード例 #25
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_change_default_payment_method(authenticated_client_with_customer_id,
                                       user_with_customer_id,
                                       default_payment_method_from_api,
                                       payment_method_from_api):
    pm_id = payment_method_from_api['id']
    response = make_request(authenticated_client_with_customer_id.put, "payment-methods", 200,
                            url_params={'obj_id': pm_id}, set_as_default=True)
    data = response.data
    payment_method_from_api.pop('default')
    assert data == payment_method_from_api
    assert stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id)['invoice_settings']['default_payment_method'] == pm_id
コード例 #26
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_new_subscription_change_default_payment_method_with_no_payment_method(
        authenticated_client_with_customer_id, stripe_price_id,
        stripe_subscription_product_id, user_with_customer_id, no_default_payment_method_to_set_as_default_error):
    response = make_request(authenticated_client_with_customer_id.post, "subscriptions", 400,
                            price_id=stripe_price_id, set_as_default_payment_method=True)
    assert response.data == no_default_payment_method_to_set_as_default_error
    response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id)
    assert response['sub_id'] is None
    assert response['cancel_at'] is None
    customer = stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id)
    assert customer['invoice_settings']['default_payment_method'] == None
コード例 #27
0
def test_checkout(authenticated_client, stripe_unsubscribed_price_id,
                  stripe_public_key, checkout_session_data, viewname,
                  url_params):
    response = make_request(authenticated_client.get,
                            viewname,
                            200,
                            signal=signals.checkout_created,
                            url_params=url_params)
    html = response.rendered_content
    assert stripe_public_key.startswith('pk')
    checkout_session = checkout_session_data['session']
    expected_html = get_expected_checkout_html(stripe_public_key,
                                               checkout_session["id"])
    assert html == expected_html
コード例 #28
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_modify_subscription(authenticated_client_with_customer_id, stripe_subscription_product_id,
                             payment_method_id, user_with_customer_id, subscription,
                             subscription_response_alternative_payment_method,
                             data, customer_default_payment_methods):
    response = make_request(authenticated_client_with_customer_id.put, "subscriptions", 200,
                            signal=signals.subscription_modified, url_params={'obj_id': subscription['id']},
                            default_payment_method=payment_method_id, **data)
    sub_id = response.data['id']
    assert response.data.pop('current_period_start') is not None
    assert response.data.pop('id') is not None
    assert response.data.pop('latest_invoice') is not None
    assert response.data.pop('start_date') is not None
    assert response.data.pop('created') is not None
    assert response.data == subscription_response_alternative_payment_method
    response = payments.is_subscribed_and_cancelled_time(user_with_customer_id, stripe_subscription_product_id)
    assert response['sub_id'] == sub_id
    assert response['cancel_at'] is None
    customer = stripe.Customer.retrieve(user_with_customer_id.stripe_customer_id)
    assert customer['invoice_settings']['default_payment_method'] == customer_default_payment_methods
コード例 #29
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_price_list(client_no_user_and_user_with_and_without_stripe_id, expected_subscription_prices_unsubscribed,
                    stripe_subscription_product_id, stripe_price_currency):
    response = make_request(client_no_user_and_user_with_and_without_stripe_id.get, 'prices', 200,
                            product=stripe_subscription_product_id,
                            currency=stripe_price_currency)
    assert response.data == expected_subscription_prices_unsubscribed
コード例 #30
0
ファイル: test_api.py プロジェクト: primal100/django_stripe
def test_non_existing_invoice(authenticated_client_with_customer_id, non_existing_invoice_id, invoice_not_exist_error):
    response = make_request(authenticated_client_with_customer_id.get, "invoices", 500,
                            url_params={'obj_id': non_existing_invoice_id})
    assert response.data == invoice_not_exist_error