Example #1
0
 def afterSetUp( self ):
     super(WarehouseFunctionalTestCase,self).afterSetUp()
     self.portal.portal_quickinstaller.installProduct('PloneGetPaid')
     #Here we are setting Documents as shippeable
     options = IGetPaidManagementOptions(self.portal)
     options.shippable_types = ['Document']
     # Set browser and error handling
     self.browser = Browser()
     self.browser.handleErrors = False
 def canDisplayWidget(self, widget):
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     try:
         IGetPaidManagementOptions(portal).use_contact_me_with_offers
     except AttributeError:
         return True
     else:
         # If there was more than just a boolean in the CheckoutOptions, we
         # could see if the current widget is in the whitelist or blacklist.
         # However, the following will suffice for now
         if widget.name == 'form.marketing_preference':
             return IGetPaidManagementOptions(
                 portal).use_contact_me_with_offers
         else:
             return True
 def _getProperty(self, name):
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     settings = IGetPaidManagementOptions(portal)
     value = getattr(settings, name, '')
     if value:
         transforms = getToolByName(self.context, 'portal_transforms')
         value = transforms(
             'web_intelligent_plain_text_to_html', value
         ).strip()
     return value
 def checkUseSSL(self):
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     if IGetPaidManagementOptions(portal).use_ssl_for_checkout:
         # we need to become https if we are not already
         # unless we are cancelling or on the thank you page
         url = self.request.getURL()
         if not 'https://' in url:
             url = url.replace("http://", "https://")
             self.request.response.redirect('%s?%s' % (
                 url, make_query(self.request.form)))
     return True
 def checkAuthenticated(self):
     membership = getToolByName(self.context, 'portal_membership')
     if membership.isAnonymousUser():
         portal = getToolByName(
             self.context, 'portal_url').getPortalObject()
         if IGetPaidManagementOptions(portal).allow_anonymous_checkout:
             return True
         self.request.response.redirect(
             'login_form?came_from=@@getpaid-checkout-wizard')
         return False
     return True
Example #6
0
 def addToCart(self):
     # XXX this duplicates functionality available elsewhere
     #     (in the name of simplicity -- pah)
     super(ShoppingCartAddItemAndGoToCheckout, self).addToCart()
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     url = portal.absolute_url()
     # check if anonymous checkout is allowed
     if IGetPaidManagementOptions(portal).allow_anonymous_checkout or \
         getSecurityManager().getUser().getId() is not None:
         url = url + '/@@getpaid-checkout-wizard'
     else:
         url = "%s/%s?%s" % (url, 'login_form',
                             urlencode([('came_from', url +
                                         '/@@getpaid-checkout-wizard')]))
     return self.request.RESPONSE.redirect(url)
Example #7
0
    def addToCart(self):

        # create a line item and add it to the cart
        item_factory = component.getMultiAdapter((self.cart, self.context),
                                                 interfaces.ILineItemFactory)

        # check amount from request
        # todo handle non-floats
        amount = float(self.request.get('amount', 1))
        try:
            item_factory.create(amount=amount)

        except interfaces.AddRecurringItemException:
            came_from = self.request.environ.get('HTTP_REFERER',
                                                 getSite().absolute_url())
            msg = "Your shopping cart already has items in it. \
                   A recurring payment item may not be added until \
                   you check out or delete the existing items."

            IStatusMessage(self.request).addStatusMessage(msg, type='error')
            self.request.response.redirect(came_from)
            return ''

        except interfaces.RecurringCartItemAdditionException:
            came_from = self.request.environ.get('HTTP_REFERER',
                                                 getSite().absolute_url())
            msg = "Your shopping cart already holds a recurring payment. \
                   Please purchase the current item or delete it from your \
                   cart before adding addtional items."

            IStatusMessage(self.request).addStatusMessage(msg, type='error')
            self.request.response.redirect(came_from)
            return ''
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        url = portal.absolute_url()

        # check if anonymous checkout is allowed
        if IGetPaidManagementOptions(portal).allow_anonymous_checkout or \
            getSecurityManager().getUser().getId() is not None:
            url = url + '/@@getpaid-checkout-wizard'
        else:
            url = "%s/%s?%s" % (url, 'login_form',
                                urlencode([('came_from', url +
                                            '/@@getpaid-checkout-wizard')]))
        return self.request.RESPONSE.redirect(url)
Example #8
0
 def makePayment(self, action, data):
     """ create an order, and submit to the pxpay processor """
     portal = self.context.portal_url.getPortalObject()
     manage_options = IGetPaidManagementOptions(portal)
     processor_name = manage_options.payment_processor
     if not processor_name:
         raise RuntimeError("No Payment Processor Specified")
     processor = component.getAdapter(portal, interfaces.IPaymentProcessor,
                                      processor_name)
     order = self.createOrder()
     order.processor_id = processor_name
     order.finance_workflow.fireTransition("create")
     order_manager = component.getUtility(interfaces.IOrderManager)
     order_manager.store(order)
     # the following will redirect to the pxpay web interface to
     # capture creditcard details
     if IPXPayPaymentProcessor.providedBy(processor):
         processor.authorize(order, None, self.request)
     else:
         raise PXPayException(
             "This checkout implementation requires the PXPay payment processor."
         )
    def setupShippingOptions(self):
        """
        Queries shipping utilities and adapters to get the available shipping
        methods and returns a list of them for the template to display and the
        user to choose among.

        """
        ship_method_code = self.request.form.get('form.shipping_method_code')
        if type(ship_method_code) == type([]):
            self.request.form['form.shipping_method_code'] = \
                    self.request.form['form.shipping_method_code'][-1]

        siteroot = getToolByName(self.context, "portal_url").getPortalObject()
        ship_service_names = IGetPaidManagementOptions(
            siteroot).shipping_services

        if not ship_service_names:
            self.status = _(
                "Misconfigured Store - No Shipping Method Activated"
            )
            return

        order = self.createTransientOrder()

        service_options = {}
        for service_name in ship_service_names:
            service = component.getUtility(
                interfaces.IShippingRateService, name=service_name)
            rates = service.getRates(order)
            if rates.error is not None:
                self.status = '%(name)s Error: %(error)s.' % {
                    'name': service_name,
                    'error': rates.error
                }
            service_options[service_name] = rates.shipments

        self.ship_service_names = ship_service_names
        self.service_options = service_options
    def update(self):
        processInputs(self.request)
        self.adapters = self.wizard.data_manager.adapters
        super(CheckoutAddress, self).update()

        # If the user has set up alternate opt-in language, use it instead
        opt_in_text = None
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        try:
            opt_in_text = IGetPaidManagementOptions(
                portal).alternate_opt_in_text
        except AttributeError:
            opt_in_text = None

        if opt_in_text and len(opt_in_text):
            formSchemas = component.getUtility(interfaces.IFormSchemas)
            widgets = self._getWidgetsByInterface(
                formSchemas.getInterface('contact_information')
            )

            for w in widgets:
                if w.name == 'form.marketing_preference':
                    w.context.title = opt_in_text
Example #11
0
def setup_payment_options(self):
    """ Set the default payment options for credit card types.
    """
    manage_options = IGetPaidManagementOptions(self)
    manage_options.setProperty('credit_cards', CREDIT_CARD_TYPES)
Example #12
0
def createOrders(self):

    manager = component.getUtility(interfaces.IOrderManager)

    # make sure we don't accidentally create notifications for sample orders

    settings = IGetPaidManagementOptions(self)
    m_a_value = settings.send_merchant_auth_notification
    c_a_value = settings.send_customer_auth_notification

    m_c_value = settings.send_merchant_charge_notification
    c_c_value = settings.send_customer_charge_notification

    m_d_value = settings.send_merchant_decline_notification
    c_d_value = settings.send_customer_decline_notification

    settings.send_merchant_auth_notification = False
    settings.send_customer_auth_notification = False

    settings.send_merchant_charge_notification = False
    settings.send_customer_charge_notification = False

    settings.send_merchant_decline_notification = False
    settings.send_customer_decline_notification = False

    for i in range(40, 60):
        o = order.Order()
        o.order_id = str(i)

        o.shopping_cart = sc = cart.ShoppingCart()

        for i in range(0, 10):
            myItem = item.LineItem()
            myItem.name = "p%s" % random.choice(string.letters)
            myItem.quantity = random.randint(1, 25)
            myItem.cost = random.randint(30, 100)
            myItem.item_id = "i%s" % random.choice(string.letters)
            if myItem.item_id in sc:
                continue
            sc[myItem.item_id] = myItem

        o.user_id = "u%s" % random.choice(string.letters)
        o.finance_workflow.fireTransition('create')
        o.fulfillment_workflow.fireTransition('create')

        manager.store(o)

    settings.send_merchant_auth_notification = m_a_value
    settings.send_customer_auth_notification = c_a_value

    settings.send_merchant_charge_notification = m_c_value
    settings.send_customer_charge_notification = c_c_value

    settings.send_merchant_decline_notification = m_d_value
    settings.send_customer_decline_notification = c_d_value

    return "Created 20 Orders"
Example #13
0
    def makePayment(self, action, data):
        """ create an order, and submit to the processor
        """
        siteroot = getToolByName(self.context, "portal_url").getPortalObject()
        manage_options = IGetPaidManagementOptions(siteroot)
        processor_name = manage_options.payment_processor

        if not processor_name:
            raise RuntimeError("No Payment Processor Specified")

        processor = component.getAdapter(siteroot, IPaymentProcessor,
                                         processor_name)

        adapters = self.wizard.data_manager.adapters

        order = self.createOrder()
        order.processor_id = processor_name
        order.finance_workflow.fireTransition("create")
        # extract data to our adapters

        formSchemas = component.getUtility(IFormSchemas)
        last4 = None
        if adapters[formSchemas.getInterface('payment')].credit_card:
            last4 = adapters[formSchemas.getInterface(
                'payment')].credit_card[-4:]
        order.user_payment_info_last4 = last4
        order.name_on_card = adapters[formSchemas.getInterface(
            'payment')].name_on_card
        order.bill_phone_number = adapters[formSchemas.getInterface(
            'payment')].bill_phone_number
        result = processor.authorize(
            order, adapters[formSchemas.getInterface('payment')])
        if result is keys.results_async:
            # shouldn't ever happen, on async processors we're already directed to the third party
            # site on the final checkout step, all interaction with an async processor are based on processor
            # adapter specific callback views.
            pass
        elif result is interfaces.keys.results_success:
            order_manager = component.getUtility(IOrderManager)
            order_manager.store(order)
            order.finance_workflow.fireTransition("authorize")
            template_key = 'order_template_entry_name'
            order_template_entry = self.wizard.data_manager.get(template_key)
            del self.wizard.data_manager[template_key]
            # if the user submits a name, it means he wants this order named
            if order_template_entry:
                uid = getSecurityManager().getUser().getId()
                if uid != 'Anonymous':
                    named_orders_list = component.getUtility(
                        INamedOrderUtility).get(uid)
                    if order_template_entry not in named_orders_list:
                        named_orders_list[
                            order.order_id] = order_template_entry
            # kill the cart after we create the order
            component.getUtility(IShoppingCartUtility).destroy(self.context)
            self._next_url = self.getNextURL(order)
        else:
            order.finance_workflow.fireTransition('reviewing-declined')
            self.status = result
            self.form_reset = False
            self._next_url = self.getNextURL(order)
def createOrders( self ):

    manager = component.getUtility( interfaces.IOrderManager )

    # make sure we don't accidentally create notifications for sample orders

    settings = IGetPaidManagementOptions( self )
    m_a_value = settings.send_merchant_auth_notification
    c_a_value = settings.send_customer_auth_notification

    m_c_value = settings.send_merchant_charge_notification
    c_c_value = settings.send_customer_charge_notification

    m_d_value = settings.send_merchant_decline_notification
    c_d_value = settings.send_customer_decline_notification

    settings.send_merchant_auth_notification = False
    settings.send_customer_auth_notification = False

    settings.send_merchant_charge_notification = False
    settings.send_customer_charge_notification = False

    settings.send_merchant_decline_notification = False
    settings.send_customer_decline_notification = False

    for i in range(40, 60):
        o = order.Order()
        o.order_id = str(i)

        o.shopping_cart = sc = cart.ShoppingCart()

        for i in range(0, 10):
            myItem = item.LineItem()
            myItem.name = "p%s"%random.choice( string.letters )
            myItem.quantity = random.randint(1,25)
            myItem.cost = random.randint(30, 100)
            myItem.item_id = "i%s"%random.choice( string.letters )
            if myItem.item_id in sc:
                continue
            sc[myItem.item_id] = myItem

        o.user_id = "u%s"%random.choice( string.letters )
        o.finance_workflow.fireTransition('create')
        o.fulfillment_workflow.fireTransition('create')

        manager.store( o )

    settings.send_merchant_auth_notification = m_a_value
    settings.send_customer_auth_notification = c_a_value

    settings.send_merchant_charge_notification = m_c_value
    settings.send_customer_charge_notification = c_c_value

    settings.send_merchant_decline_notification = m_d_value
    settings.send_customer_decline_notification = c_d_value

    return "Created 20 Orders"
def setup_payment_options(self):
    """ Set the default payment options for credit card types.
    """
    manage_options = IGetPaidManagementOptions(self)
    manage_options.setProperty('credit_cards', CREDIT_CARD_TYPES)