==============================================================================
Recurring items checkout Doctest
by jpg_at_rcom.com.ar
==============================================================================

Create the browser object we'll be using.

	>>> from Products.Five.testbrowser import Browser
	>>> browser = Browser()
	>>> portal.error_log._ignored_exceptions = ()
	>>> browser.handleErrors = False
    >>> portal = self.portal
    >>> folder = self.folder
    >>> portal_url = portal.absolute_url()
    >>> folder_url = self.folder.absolute_url()
    >>> login_url = portal_url + '/login_form'
    >>> logout_url = portal_url + '/logout'

Testing checkout process for authenticated user (in this case, admin)

	>>> membership = self.portal.portal_membership
	>>> membership.addMember('testmanager', 'secret',
	...		     ['Member', 'Manager'], [])

	>>> browser.open(portal_url)
	>>> browser.getLink('Log in').click()
	>>> browser.getControl('Login Name').value = 'testmanager'
	>>> browser.getControl('Password').value = 'secret'
	>>> browser.getControl('Log in').click()

	>>> self.portal.portal_quickinstaller.installProduct('PloneGetPaid')
	'...'
	>>> browser.getLink('Home').click()

Testing the setup aspects of GetPaid. Setting required settings.

	>>> browser.getLink('Site Setup').click()
	>>> browser.getLink('GetPaid').click()
	>>> browser.getLink('Site Profile').click()
	>>> browser.getControl('Contact Email').value = 'info@plonegetpaid.com'
	>>> browser.getControl( name="form.store_name").value = 'Test this fake company'
	>>> browser.getControl('Contact Country').displayValue = ['ARGENTINA']
	>>> browser.getControl('Apply').click()
	>>> browser.getLink('GetPaid').click()
	>>> browser.getLink('Content Types').click()
	>>> browser.getLink('GetPaid').click()
	>>> browser.getLink('Payment Options').click()
	>>> browser.getControl(name = 'form.payment_processor').displayValue = ['Testing Processor']
	>>> browser.getControl(name = 'form.allow_anonymous_checkout.used').value = 'on'
	>>> browser.getControl('Apply').click()
	>>> browser.getLink('GetPaid').click()
	>>> browser.getLink('Payment Processor Settings').click()
	>>> browser.getControl(name="form.allow_authorization").displayValue = ['allow_authorization']
	>>> browser.getControl(name="form.allow_capture").displayValue = ['allow_capture']
	>>> browser.getControl(name="form.allow_refunds").displayValue = ['allow_refund']
	>>> browser.getControl('Apply').click()
	>>> browser.getLink('GetPaid').click()
	>>> browser.getLink('Legal Disclaimers').click()
	>>> browser.getControl(name='form.disclaimer').value = 'Test disclaimer'
	>>> browser.getControl(name='form.privacy_policy').value = 'Test privacy policy'
	>>> browser.getControl('Apply').click()
	>>> browser.getLink('GetPaid').click()

Here we are setting the buyable types for use in the following tests

	>>> from Products.PloneGetPaid.interfaces import IGetPaidManagementOptions
	>>> options = IGetPaidManagementOptions(self.portal)
	>>> options.buyable_types = ['Document', 'Link', 'Event']
	>>> options.donate_types = ['Document']
	>>> options.shippable_types = ['Document']

Here we set up the Credit cards accepted for payment:

	 >>> options.accepted_credit_cards = ["Visa"]

Check to make sure the settings we put in Site Profile appear on this page.

	 >>> browser.getLink('Home').click()

Setup Donatable

	>>> browser.getLink('Make Recurring Payable').click()
	>>> browser.getControl(name='form.price').value = '11.00'
	>>> browser.getControl(name='form.interval').value = '12.00'
	>>> browser.getControl(name='form.total_occurrences').value = '5'
	>>> browser.getControl('Activate').click()

Test donation checkout, which should go directly to checkout screen from the portlet.

	>>> browser.getControl('Add to Cart').click()

Continue where we left of after clicking Donate.

	>>> browser.getControl('Checkout').click()
	>>> browser.getControl('Your Name').value = 'Test'
	>>> browser.getControl('Phone Number').value = '1234567'
	>>> browser.getControl('Phone Number').value = '12345678'
	>>> browser.getControl(name='form.email').value = 'test@test.com'
	>>> browser.getControl(name='form.bill_name').value = 'Test'
	>>> browser.getControl(name='form.bill_first_line').value = 'Test'
	>>> browser.getControl(name='form.bill_city').value = 'Test'
	>>> browser.getControl(name='form.bill_state').value = ('US-HI',)
	>>> browser.getControl(name='form.bill_postal_code').value = '12345'
	>>> browser.getControl(name='form.ship_first_line').value = 'Test'
	>>> browser.getControl(name='form.ship_city').value = 'Test'
	>>> browser.getControl(name='form.ship_state').value = ('US-HI',)
	>>> browser.getControl(name='form.ship_postal_code').value = '12345'

Now go to the next form.

	>>> browser.getControl('Continue').click()

Continue filling in the current form.

	>>> browser.getControl('Card Holder Name').value = 'Test Cardholder'
	>>> browser.getControl('Phone Number').value = '12345678'
	>>> browser.getControl(name='form.cc_expiration_month').value = ('02',)
	>>> browser.getControl(name='form.cc_expiration_year').value = ('2012',)

Use real test credit card numbers, available from http://developer.authorize.net/faqs/#7429

	>>> browser.getControl('Credit Card Verification Number').value = '1234'
	>>> browser.getControl('Credit Card Number').value = '4007000000027'
	>>> browser.getControl('Credit Card Type').value = ('Visa',)
	>>> browser.getControl('Make Payment').click()

Donation checkout completed. Now check order

Verify order was for what we checked out.

	>>> 'CHARGED' in browser.contents
	True

This completes test of donation checkout. Verified that item was
listed on order for user.

Now test add to cart and checkout process.
Create the browser object we'll be using.

	>>> browser.open('http://nohost/plone')
	>>> browser.getLink('Link').click()
	>>> browser.getControl('Title').value = 'Test Link'
	>>> browser.getControl('URL').value = 'http://plonegetpaid.com/'
	>>> browser.getControl('Save').click()

Make it buyable.

	>>> browser.getLink('Make Buyable').click()
	>>> browser.getControl('Price').value = '12.50'
	>>> browser.getControl('Activate').click()

Add it to my cart.

	>>> browser.getControl('Add to Cart').click()
	>>> browser.getControl('Continue Shopping').click()
	>>> 'Contains <span>1</span> Items' in browser.contents
	True

Add a buyable event.

	>>> browser.open('http://nohost/plone/createObject?type_name=Event')
	>>> browser.getControl('Title').value = 'It is payday!'
	>>> browser.getControl('Save').click()
	>>> browser.open('http://nohost/plone/it-is-payday/@@activate-buyable')
	>>> browser.getControl('Product Code').value = 'PAY-ME'
	>>> browser.getControl('Price').value = '42.17'
	>>> browser.getControl('Activate').click()

We want it so we buy it.

	>>> browser.open(portal.absolute_url() + '/folder_contents')
	>>> browser.getLink('It is payday!').click()

XXX FIXME.  Now why does this fail with an InvalidObjectReference????
The link "Add to Cart" is there when you check browser.contents...

	>>> 'Add to Cart' in browser.contents
	True
	>>> browser.getControl('Add to Cart').click()
	>>> browser.getControl('Checkout').click()
	>>> browser.getControl('Your Name').value = 'test'
	>>> browser.getControl('Phone Number').value = '12345678'
	>>> browser.getControl(name='form.email').value = 'test@test.com'
	>>> browser.getControl(name='form.bill_name').value = 'Test'
	>>> browser.getControl(name='form.bill_first_line').value = 'Test'
	>>> browser.getControl(name='form.bill_city').value = 'Test'
	>>> browser.getControl(name='form.bill_state').value = ('US-HI',)
	>>> browser.getControl(name='form.bill_postal_code').value = '12345'

Note: we are only buying something, not shipping it, so maybe these
controls are not available here (or they are but they should not be).

	>>> browser.getControl(name='form.ship_first_line').value = 'Test'
	>>> browser.getControl(name='form.ship_city').value = 'Test'
	>>> browser.getControl(name='form.ship_state').value = ('US-HI',)
	>>> browser.getControl(name='form.ship_postal_code').value = '12345'
	>>> browser.getControl('Continue').click()

We move to the next form and fill in the current form.

	>>> browser.getControl('Card Holder Name').value = 'Test Cardholder'
	>>> browser.getControl('Phone Number').value = '12345678'
	>>> browser.getControl(name='form.cc_expiration_month').value = ('02',)
	>>> browser.getControl(name='form.cc_expiration_year').value = ('2012',)

Use real test credit card numbers, available from http://developer.authorize.net/faqs/#7429

	>>> browser.getControl('Credit Card Verification Number').value = '1234'
	>>> browser.getControl('Credit Card Number').value = '4007000000027'
	>>> browser.getControl('Credit Card Type').value = ('Visa',)
	>>> browser.getControl('Make Payment').click()

Donation checkout completed. Now check order

	>>> browser.getLink('here').click()
	>>> browser.url.startswith('http://nohost/plone/@@getpaid-order/')
	True

Verify order was for what we checked out.  Well, that is not listed
actually.  We may want to follow the link that is displayed.  But for
me (Maurits) the tests never come this far, so it is hard to say...

	>>> 'CHARGED' in browser.contents
	True

Finished verification.
