def getButton(self):
        button = ClickAndBuyStandardProcessor(self.context)
        cart_util = getUtility(IShoppingCartUtility)
        cart = cart_util.get(self.context, create=True)
        manage_options = IGetPaidManagementOptions(self.context)

        # we'll get the order_manager, create the new order, and store it.
        order_manager = getUtility(IOrderManager)
        new_order_id = order_manager.newOrderId()
        order = Order()

        order.finance_workflow.fireTransition('create')

        # register the payment processor name to make the workflow handlers happy
        order.processor_id = manage_options.payment_processor

        # registering an empty contact information list
        order.contact_information = payment.ContactInformation()
        order.billing_address = payment.BillingAddress()
        order.shipping_address = payment.ShippingAddress()
        order.order_id = new_order_id

        # make cart safe for persistence by using pickling
        order.shopping_cart = loads(dumps(cart))
        order.user_id = getSecurityManager().getUser().getId()
        order_manager.store(order)

        import ipdb; ipdb.set_trace()

        return button.cart_post_button(order)
Example #2
0
    def __call__( self, adapters, shopping_cart=None ):
        order = Order()

        portal = component.getSiteManager()
        portal = getToolByName(portal,'portal_url').getPortalObject()
        if shopping_cart is None:
            """
            This deservers a bit of explanation, when using the formgen adapter
            for 'disposable' carts (this means that we don't use the site's
            cart but a transient one just for the ocasion) we want this cart
            to be different from the user's one and to cease to exist after
            the transaction (means no persistence) .
            """
            shopping_cart =  component.getUtility( interfaces.IShoppingCartUtility ).get( portal )
        formSchemas = component.getUtility( interfaces.IFormSchemas )

        order.shopping_cart = shopping_cart

        for section in ('contact_information','billing_address','shipping_address'):
            interface = formSchemas.getInterface(section)
            bag = formSchemas.getBagClass(section).frominstance(adapters[interface])
            setattr(order,section,bag)

        order_manager = component.getUtility( interfaces.IOrderManager )
        order.order_id = order_manager.newOrderId()
        
        order.user_id = getSecurityManager().getUser().getId()

        return order
    def createTransientOrder(self):
        order = Order()
        shopping_cart = component.getUtility(
            interfaces.IShoppingCartUtility
        ).get(self.context)
        formSchemas = component.getUtility(interfaces.IFormSchemas)

        # shopping cart is attached to the session, but we want to switch the
        # storage to the persistent zodb, we pickle to get a clean copy to
        # store.
        adapters = self.wizard.data_manager.adapters

        order.shopping_cart = loads(dumps(shopping_cart))

        for section in (
            'contact_information',
            'billing_address',
            'shipping_address'):
            interface = formSchemas.getInterface(section)
            bag = formSchemas.getBagClass(
                section).frominstance(adapters[interface])
            setattr(order, section, bag)

        order.order_id = self.wizard.data_manager.get('order_id')
        order.user_id = getSecurityManager().getUser().getId()

        return order
    def placeOrder(self, data, cart):
        # disable ZPublisher retries for this request
        self.request.retry_max_count = 0

        conn = self.context._p_jar
        order_manager = getUtility(IOrderManager)
        order = Order()
        conn.add(order)
        order.shopping_cart = loads(dumps(cart))
        # make sure the cart is not in session storage
        conn.add(order.shopping_cart)
        order.order_id = order_manager.newOrderId()

        order.contact_information = self.getContactInformation()
        conn.add(order.contact_information)
        order.billing_address = BillingAddressInfo(**data)
        conn.add(order.billing_address)
        order.user_id = self.getBuyerUsername()

        order.processor_id, processor = IPaymentProcessor(getSite())
        order.finance_workflow.fireTransition("create")
        order.bill_phone_number = ''

        if self.total_is_zero:
            order.user_payment_info_last4 = None
            order.name_on_card = None

            order_manager.store(order)
            order.finance_workflow.fireTransition("authorize")
            order.finance_workflow.fireTransition('charge-charging')
        else:
            order.user_payment_info_last4 = data['credit_card'][-4:]
            order.name_on_card = data['name_on_card']

            payment_info = PaymentInfo(**data)
            # XXX Should rewrite to do a single auth_capture if possible
            result = processor.authorize(order, payment_info)
            if result is gp_interfaces.keys.results_success:
                order_manager.store(order)
                order.finance_workflow.fireTransition("authorize")
            elif result is gp_interfaces.keys.results_async:
                # Asynchronous handling of authorization; we don't know status
                return order
            else:
                order.finance_workflow.fireTransition('reviewing-declined')
                return False

        return order
def fixedCreateTransientOrder(self):
    order = Order()
    cart = getCart(self.context)
    formSchemas = getUtility(IFormSchemas)

    # shopping cart is attached to the session, but we want to switch the
    # storage to the persistent zodb, we pickle to get a clean copy to store.
    adapters = self.wizard.data_manager.adapters

    order.shopping_cart = loads(dumps(cart))

    for section in ("contact_information", "billing_address", "shipping_address"):
        interface = formSchemas.getInterface(section)
        bag = formSchemas.getBagClass(section).frominstance(adapters[interface])
        setattr(order, section, bag)

    order.order_id = self.wizard.data_manager.get("order_id")
    order.user_id = getSecurityManager().getUser().getId()

    return order
    def getButton(self):
        button = PaypalStandardProcessor(self.context)
        cart_util = getUtility(IShoppingCartUtility)
        cart = cart_util.get(self.context, create=True)
        site = self.context.portal_url.getPortalObject()
        manage_options = IGetPaidManagementOptions( site )
        
        # we'll get the order_manager, create the new order, and store it.
        order_manager = getUtility(IOrderManager)
        new_order_id = order_manager.newOrderId()
        order = Order()
        
        # register the payment processor name to make the workflow handlers happy
        order.processor_id = manage_options.payment_processor
        
        # FIXME: registering an empty contact information list for now - need to populate this from user
        # if possible
        order.contact_information = payment.ContactInformation()
        order.billing_address = payment.BillingAddress()
        order.shipping_address = payment.ShippingAddress()

        order.order_id = new_order_id
        
        # make cart safe for persistence by using pickling
        order.shopping_cart = loads(dumps(cart))
        order.user_id = getSecurityManager().getUser().getId()

        order.finance_workflow.fireTransition('create')
        
        order_manager.store(order)

        # have to wait for the order to be created and the cart added for this to work
        order.finance_workflow.fireTransition('authorize')

        # save html for button - we'll destroy the cart later on
        html = button.cart_post_button(order)
        
        # and destroy the cart
        cart_util.destroy(self.context)

        return html
Example #7
0
def create_test_order(context, order_id='1111111111'):
    """
    creates an order with a line item using a new cart.
    """
    item = LineItem()
    item.item_id = order_id
    item.name = "Jug of beer"
    item.cost = 5.00
    item.quantity = 5
    item.description = "Really nice beer"

    cart_util = getUtility(IShoppingCartUtility)
    cart = cart_util.get(context, create=True)
    cart[item.item_id] = item

    order = Order()
    order.order_id = order_id
    order.shopping_cart = cart
    order.processor_id = 'PXPay Processor'
    order.contact_information = ContactInformation()
    return order
Example #8
0
def create_test_order(context, order_id='1111111111'):
    """
    creates an order with a line item using a new cart.
    """
    item = LineItem()
    item.item_id = order_id
    item.name = "Jug of beer"
    item.cost = 5.00
    item.quantity = 5
    item.description = "Really nice beer"

    cart_util = getUtility(IShoppingCartUtility)
    cart = cart_util.get(context, create=True)
    cart[ item.item_id ] = item

    order = Order()
    order.order_id = order_id
    order.shopping_cart = cart
    order.processor_id = 'PXPay Processor'
    order.contact_information = ContactInformation()
    return order