Exemplo n.º 1
0
    def test_update_account_with_billing_info(self):
        # Case 1: account exists, but has no billing data
        self.base_account_data['hosted_login_token'] = 'abcd1234'
        self.base_account_data['created_at'] = '2014-08-11'
        mocurly.backend.accounts_backend.add_object(
            self.base_account_data['account_code'], self.base_account_data)

        account = recurly.Account.get(self.base_account_data['account_code'])
        account.company_name = 'Mocurly'
        account.billing_info = billing_info = recurly.BillingInfo()
        billing_info.first_name = 'Verena'
        billing_info.last_name = 'Example'
        billing_info.number = '4111-1111-1111-1111'
        billing_info.verification_value = '123'
        billing_info.month = 11
        billing_info.year = 2015
        account.save()

        self.assertEqual(len(mocurly.backend.accounts_backend.datastore), 1)
        self.assertEqual(len(mocurly.backend.billing_info_backend.datastore),
                         1)
        account_backed = mocurly.backend.accounts_backend.get_object(
            self.base_account_data['account_code'])
        self.assertEqual(account_backed['company_name'], 'Mocurly')
        billing_info_backed = mocurly.backend.billing_info_backend.get_object(
            self.base_account_data['account_code'])
        self.assertEqual(billing_info_backed['first_name'], 'Verena')
        self.assertEqual(billing_info_backed['last_name'], 'Example')
        self.assertEqual(billing_info_backed['number'], '4111-1111-1111-1111')
        self.assertEqual(billing_info_backed['first_six'], '411111')
        self.assertEqual(billing_info_backed['last_four'], '1111')
        self.assertEqual(billing_info_backed['verification_value'], '123')
        self.assertEqual(billing_info_backed['month'], '11')
        self.assertEqual(billing_info_backed['year'], '2015')

        # Case 2: billing data exists
        account = recurly.Account.get(self.base_account_data['account_code'])
        account.email = '*****@*****.**'
        account.billing_info = billing_info = recurly.BillingInfo()
        billing_info.last_name = 'Mocurly'
        account.save()

        self.assertEqual(len(mocurly.backend.accounts_backend.datastore), 1)
        self.assertEqual(len(mocurly.backend.billing_info_backend.datastore),
                         1)
        account_backed = mocurly.backend.accounts_backend.get_object(
            self.base_account_data['account_code'])
        self.assertEqual(account_backed['email'], '*****@*****.**')
        billing_info_backed = mocurly.backend.billing_info_backend.get_object(
            self.base_account_data['account_code'])
        self.assertEqual(billing_info_backed['last_name'], 'Mocurly')
Exemplo n.º 2
0
def new_subscription():

    # We'll wrap this in a try to catch any API
    # errors that may occur
    try:

        # Create the scubscription using minimal
        # information: plan_code, account_code, currency and
        # the token we generated on the frontend
        subscription = recurly.Subscription(
            plan_code='basic',
            currency='USD',
            account=recurly.Account(
                account_code=uuid.uuid1(),
                billing_info=recurly.BillingInfo(
                    token_id=request.form['recurly-token'])))

        # The subscription has been created and we can redirect
        # to a confirmation page
        subscription.save()
        return redirect('SUCCESS_URL')
    except recurly.ValidationError, errors:

        # Here we may wish to log the API error and send the
        # customer to an appropriate URL, perhaps including
        # and error message. See the `error_redirect` and
        # `compose_errors` functions below.
        error_redirect(compose_errors(errors))
Exemplo n.º 3
0
    def new_subscription(self):

        try:
            subscription = recurly.Subscription()
            subscription.plan_code = 'pro'
            subscription.currency = 'USD'

            account = recurly.Account(account_code=uuid.uuid1())
            account.email = '*****@*****.**'
            account.first_name = 'Michael1'
            account.last_name = 'McGovern'

            billing_info = recurly.BillingInfo()
            billing_info.number = '4111-1111-1111-1111'
            billing_info.month = 05
            billing_info.year = 2019

            account.billing_info = billing_info
            subscription.account = account
            log.warn("========================test========================")
            subscription.save()
        except recurly.NotFoundError:
            print 'Account not Found.\n'
        except recurly.errors:
            for e in errors:
                print "%s:%s" % (e.field, e.message)
Exemplo n.º 4
0
    def test_account_creation_with_billing_info(self):
        self.assertFalse(
            mocurly.backend.accounts_backend.has_object(
                self.base_account_data['account_code']))
        self.assertFalse(
            mocurly.backend.billing_info_backend.has_object(
                self.base_account_data['account_code']))

        self.base_account_data['billing_info'] = recurly.BillingInfo(
            **self.base_billing_info_data)
        new_account = recurly.Account(**self.base_account_data)
        new_account.save()
        del self.base_account_data['billing_info']

        # Verify account object exists in backend
        self.assertTrue(
            mocurly.backend.accounts_backend.has_object(
                self.base_account_data['account_code']))
        new_account = mocurly.backend.accounts_backend.get_object(
            self.base_account_data['account_code'])
        for k, v in self.base_account_data.items():
            self.assertEqual(new_account[k], v)
        self.assertTrue('hosted_login_token'
                        in new_account)  # adds a hosted_login_token by default
        self.assertTrue('created_at'
                        in new_account)  # adds a created_at field by default

        # Verify billing info object exists in backend
        self.assertTrue(
            mocurly.backend.billing_info_backend.has_object(
                self.base_account_data['account_code']))
        new_billing_info = mocurly.backend.billing_info_backend.get_object(
            self.base_account_data['account_code'])
        for k, v in self.base_billing_info_data.items():
            self.assertEqual(new_billing_info[k], v)
Exemplo n.º 5
0
def new_subscription():

    # If user is not logged in, have them login or register
    if not current_user.is_authenticated:
        flash('Please login or register to create an account first!', 'danger')
        return redirect(url_for('users.login'))

    # We'll wrap this in a try to catch any API
    # errors that may occur
    try:

        # Get the user_account
        user_account_code = fa.create_account_code(current_user.id)
        user_account = recurly.Account.get(user_account_code)
        billing_info = recurly.BillingInfo(
            token_id=request.form['recurly-token'])
        user_account.billing_info = billing_info

        # Create the scubscription using minimal
        # information: plan_code, account_code, currency and
        # the token we generated on the frontend
        subscription = recurly.Subscription(currency='USD',
                                            account=user_account,
                                            plan_code='testplancode')

    except:
        flash(('Sorry, our servers experienced an issue creating your'
               'subscription. Please try again later!'), 'danger')
    # The subscription has been created and we can redirect to a confirmation page
    subscription.save()
    flash('You have been successfully subscribed to the Basic Plan!',
          'success')
    return redirect(url_for('main.home'))
Exemplo n.º 6
0
def new_recurly_account():

    # If user is not logged in, have them login or register
    if not current_user.is_authenticated:
        flash('Please login or register to create an account first!', 'danger')
        return redirect(url_for('users.login'))

    # Create user's account_code from hidden hash library
    user_account_code = fa.create_account_code(current_user.id)

    try:

        # Create user account
        new_account = recurly.Account(
            account_code=user_account_code,
            billing_info=recurly.BillingInfo(
                token_id=request.form['recurly-token']))

        # Create subscription
        subscription = recurly.Subscription()
        subscription.plan_code = request.form['plan']
        subscription.currency = 'USD'
        subscription.account = new_account
        subscription.save()

        flash('Account subscribed successfully!', 'success')
        return redirect(url_for('users.account'))

    except recurly.ValidationError:
        flash('ValidationError! Please try again shortly.', 'danger')
        return redirect(url_for('users.account'))
Exemplo n.º 7
0
def api_accounts_update():

    # If user is not logged in, have them login or register
    if not current_user.is_authenticated:
        flash('Please login or register to create an account first!', 'danger')
        return redirect(url_for('users.login'))

    try:

        # Load user account
        user_account_code = fa.create_account_code(current_user.id)
        user_account = recurly.Account.get(user_account_code)

        # Save the tokenized billing info
        billing_info = recurly.BillingInfo(
            token_id=request.form['recurly-token'])

        # Apply it to the account
        user_account.update_billing_info(billing_info)

        flash('Account updated successfully!', 'success')
        return redirect(url_for('users.account'))

    except recurly.ValidationError:
        flash('ValidationError! Please try again shortly.', 'danger')
        return redirect(url_for('users.account'))
Exemplo n.º 8
0
def update_account(account_code):
    try:
        account = recurly.Account.get(account_code)
        account.billing_info = recurly.BillingInfo(
            token_id=request.form['recurly-token'])
        account.save()
        return redirect('SUCCESS_URL')
    except recurly.NotFoundError, error:
        error_redirect(error.message)
Exemplo n.º 9
0
    def create(cls, account, first_name, last_name, company, address1,
               address2, city, state, zipcode, country, phone, vat_number,
               ip_address, number, verification_value, month, year):
        recurly_account = account.recurly_account
        try:
            recurly_billing_info = recurly_account.billing_info
        except:
            recurly_billing_info = recurly.BillingInfo()

        recurly_billing_info.first_name = first_name
        recurly_billing_info.last_name = last_name
        recurly_billing_info.company = company
        recurly_billing_info.address1 = address1
        recurly_billing_info.address2 = address2
        recurly_billing_info.city = city
        recurly_billing_info.state = state
        recurly_billing_info.zip = zipcode
        recurly_billing_info.country = country
        recurly_billing_info.phone = phone
        recurly_billing_info.vat_number = vat_number
        recurly_billing_info.ip_address = ip_address
        recurly_billing_info.type = 'credit_card'
        recurly_billing_info.number = number
        recurly_billing_info.verification_value = verification_value
        recurly_billing_info.month = month
        recurly_billing_info.year = year

        try:
            recurly_billing_info.save()
        except:
            recurly_account.update_billing_info(recurly_billing_info)

        billing_info = cls(
            user=account.user,
            account=account,
            first_name=first_name,
            last_name=last_name,
            company=company,
            address1=address1,
            address2=address2,
            city=city,
            state=state,
            zipcode=zipcode,
            country=country,
            phone=phone,
            vat_number=vat_number,
            ip_address=ip_address,
            ip_address_country=recurly_billing_info.ip_address_country,
            card_type=recurly_billing_info.card_type,
            year=year,
            month=month,
            first_six=recurly_billing_info.first_six,
            last_four=recurly_billing_info.last_four)
        billing_info.save()
        return billing_info
Exemplo n.º 10
0
def update_account(account_code):
    try:
        account_update = {
            "billing_info":
            recurly.BillingInfo(token_id=request.form['recurly-token'])
        }
        account = client.update_account("code-%s" % account_code,
                                        account_update)
        return redirect(SUCCESS_URL)
    except recurly.ApiError as error:
        return error_redirect(error.error.message)
Exemplo n.º 11
0
def update_and_sync_recurly_billing_info(account, billing_info_params):
    """
    Gets and returns a LOCAL Account instance.
    """
    recurly_account = account.get_recurly_account()
    billing_info = recurly.BillingInfo(**billing_info_params)
    recurly_account.update_billing_info(billing_info)
    if hasattr(account, "billing_info"):
        account.billing_info.purge_billing_info()
    recurly_account = account.get_recurly_account()  # refresh
    local_account = update_local_account_data_from_recurly_resource(
        recurly_account=recurly_account)
    return local_account
Exemplo n.º 12
0
def new_subscription():

    # We'll wrap this in a try to catch any API
    # errors that may occur
    try:

        recurly_token_id = request.form['recurly-token']
        if 'recurly-account-code' in request.form:
            recurly_account_code = request.form['recurly-account-code']
        else:
            recurly_account_code = uuid.uuid1()

        # Build our billing info object
        billing_info = recurly.BillingInfo(token_id=recurly_token_id)

        # Optionally add a 3D Secure token if one is present. You only need to do this
        # if you are integrating with Recurly's 3D Secure support
        if 'three-d-secure-token' in request.form:
            billing_info.three_d_secure_action_result_token_id = request.form[
                'three-d-secure-token']

        # Create the scubscription using minimal
        # information: plan_code, account_code, currency and
        # the token we generated on the frontend
        subscription = recurly.Subscription(
            plan_code='basic',
            currency='USD',
            account=recurly.Account(account_code=recurly_account_code,
                                    billing_info=billing_info))

        # The subscription has been created and we can redirect
        # to a confirmation page
        subscription.save()
        return redirect(SUCCESS_URL)
    except recurly.ValidationError as error:

        # Here we handle a 3D Secure required error by redirecting to an authentication page
        if error.transaction_error_code == 'three_d_secure_action_required':
            action_token_id = error.transaction_error.three_d_secure_action_token_id
            return redirect("/3d-secure/authenticate.html#token_id=" +
                            recurly_token_id + "&action_token_id=" +
                            action_token_id + "&account_code=" +
                            str(recurly_account_code))

        # Here we may wish to log the API error and send the
        # customer to an appropriate URL, perhaps including
        # and error message. See the `error_redirect` and
        # `compose_errors` functions below.
        error_redirect(compose_errors(error))
Exemplo n.º 13
0
def _construct_recurly_account_resource(account_params,
                                        billing_info_params=None):
    """
    Might modify "account_params" object.

    Returns UNSAVED instance.
    """

    if not isinstance(account_params, recurly.Account):
        account_params = recurly.Account(**account_params)

    if billing_info_params:
        if isinstance(billing_info_params, recurly.BillingInfo):
            billing_info = billing_info_params
        else:
            billing_info = recurly.BillingInfo(**billing_info_params)
        account_params.billing_info = billing_info  # OVERRIDE

    return account_params
Exemplo n.º 14
0
    def test_simple_account_update_billing_info(self):
        # Create a simple account
        recurly.Account(**self.base_account_data).save()

        # Verify account has no billing info
        recurly_account = recurly.Account.get(
            self.base_account_data['account_code'])
        self.assertRaises(AttributeError, lambda: recurly_account.billing_info)

        # Update the billing info using the update_billing_info method
        billing_info = recurly.BillingInfo(**self.base_billing_info_data)
        recurly_account.update_billing_info(billing_info)

        # Verify billing info object exists in backend
        self.assertTrue(
            mocurly.backend.billing_info_backend.has_object(
                self.base_account_data['account_code']))
        new_billing_info = mocurly.backend.billing_info_backend.get_object(
            self.base_account_data['account_code'])
        for k, v in self.base_billing_info_data.items():
            self.assertEqual(new_billing_info[k], v)