コード例 #1
0
ファイル: simple.py プロジェクト: zandeez/gchecky
def create_cart():
    """
    Create a sample cart which will be then encoded into html for the sake
    of the sample.
    The cart contains 2 apples and 5 oranges. It also indicates to GC to prompt
    the user for a phone number.
    """
    cart = gmodel.checkout_shopping_cart_t(
        shopping_cart = gmodel.shopping_cart_t(
            items = [gmodel.item_t(
                name = 'Apple',
                description = 'A Golden Apple for You, my dear',
                unit_price = gmodel.price_t(
                    value=0.15,
                    currency = GCHECKOUT_CURRENCY
                ),
                quantity = 2
            ),
            gmodel.item_t(
                name = 'Orange',
                description = 'Vitamin C is the powa',
                unit_price = gmodel.price_t(
                    value=.07,
                    currency = GCHECKOUT_CURRENCY
                ),
                quantity = 5
            )]
        ),
        checkout_flow_support = gmodel.checkout_flow_support_t(
            # TODO: Does it really ask for the phone number?
            request_buyer_phone_number = True
        )
    )
    return cart
コード例 #2
0
def make_gco_request(rd):

    merch_info = get_merchant_info()

    controller = Controller(str(merch_info.merchant_id), str(merch_info.merchant_key), is_sandbox=merch_info.sandbox)

    shopping_cart = gmodel.shopping_cart_t(
        items=[
            gmodel.item_t(
                merchant_item_id=rd.transaction_id,
                name=rd.event_name,
                description=rd.description,
                unit_price=gmodel.price_t(value=rd.price, currency="USD"),
                quantity=1,
            )
        ]
    )

    checkout_flow_support = gmodel.checkout_flow_support_t(
        continue_shopping_url=get_site_url(), request_buyer_phone_number=False
    )

    order = gmodel.checkout_shopping_cart_t(shopping_cart=shopping_cart, checkout_flow_support=checkout_flow_support)

    prepared = controller.prepare_order(order)

    logging.info(prepared.html)

    return prepared.html
コード例 #3
0
 def _get_cart(self, order):
     cart = gmodel.checkout_shopping_cart_t(
         shopping_cart=gmodel.shopping_cart_t(
             items=self._get_items(order),
             merchant_private_data=order.payment_key),
         checkout_flow_support=gmodel.checkout_flow_support_t(
             request_buyer_phone_number=True))
     return cart
コード例 #4
0
    def createCart(self, cart):
        """
        Create a shopping cart compatible with gchecky from our local cart.
        @return : a gmodel.checkout_shopping_cart_t
        """
        items = []
        for cartitem in cart.cartitem_set.all():
            item = gmodel.item_t(
                name=cartitem.product.title,
                description=cartitem.product.description,
                unit_price=gmodel.price_t(
                    value=cartitem.price, currency=self.checkout_currency),
                quantity=cartitem.qty)
            items.append(item)

        url_success = "http://%s/payments/success" % (cart.shop.default_dns)

        merchant_private_data = "cart_id:%s#shop_id:%s" % (cart.id,
                                                           cart.shop.id)

        shopping_cart = gmodel.shopping_cart_t(
            items=items, merchant_private_data=merchant_private_data)

        support = gmodel.checkout_flow_support_t(
            edit_cart_url=None,
            continue_shopping_url=url_success,
            tax_tables=gmodel.tax_tables_t(
                merchant_calculated=False,
                default=gmodel.default_tax_table_t(tax_rules=[
                    gmodel.default_tax_rule_t(
                        shipping_taxed=False,
                        rate=cart.rate_taxes(),
                        tax_area=gmodel.tax_area_t(world_area=True))
                ])),
            shipping_methods=gmodel.shipping_methods_t(flat_rate_shippings=[
                gmodel.flat_rate_shipping_t(
                    name='Standard Shipping',
                    price=gmodel.price_t(
                        currency=self.checkout_currency,
                        value=float(str(cart.shipping_charge())),
                    ),
                    #                                        allowed_areas = gmodel.allowed_areas_t(
                    #                                            postal_areas = [gmodel.postal_area_t(
                    #                                                country_code = 'US',
                    #                                                )],
                    #                                        ),
                    #                                        excluded_areas = gmodel.excluded_areas_t(
                    #                                            postal_areas = [gmodel.postal_area_t(
                    #                                                country_code = 'US',
                    #                                                )],
                    #                                        ),
                )
            ]))
        cart = gmodel.checkout_shopping_cart_t(
            shopping_cart=shopping_cart, checkout_flow_support=support)
        logging.debug(cart)
        return cart
コード例 #5
0
    def createCart(self, cart):
        """
        Create a shopping cart compatible with gchecky from our local cart.
        @return : a gmodel.checkout_shopping_cart_t
        """
        items = []
        for cartitem in cart.cartitem_set.all():
            item = gmodel.item_t(name=cartitem.product.title,
                                 description=cartitem.product.description,
                                 unit_price=gmodel.price_t(
                                     value=cartitem.price,
                                     currency=self.checkout_currency),
                                 quantity=cartitem.qty)
            items.append(item)

        url_success = "http://%s/payments/success" % (cart.shop.default_dns)

        merchant_private_data = "cart_id:%s#shop_id:%s" % (cart.id,
                                                           cart.shop.id)

        shopping_cart = gmodel.shopping_cart_t(
            items=items, merchant_private_data=merchant_private_data)

        support = gmodel.checkout_flow_support_t(
            edit_cart_url=None,
            continue_shopping_url=url_success,
            tax_tables=gmodel.tax_tables_t(
                merchant_calculated=False,
                default=gmodel.default_tax_table_t(tax_rules=[
                    gmodel.default_tax_rule_t(shipping_taxed=False,
                                              rate=cart.rate_taxes(),
                                              tax_area=gmodel.tax_area_t(
                                                  world_area=True))
                ])),
            shipping_methods=gmodel.shipping_methods_t(flat_rate_shippings=[
                gmodel.flat_rate_shipping_t(
                    name='Standard Shipping',
                    price=gmodel.price_t(
                        currency=self.checkout_currency,
                        value=float(str(cart.shipping_charge())),
                    ),
                    #                                        allowed_areas = gmodel.allowed_areas_t(
                    #                                            postal_areas = [gmodel.postal_area_t(
                    #                                                country_code = 'US',
                    #                                                )],
                    #                                        ),
                    #                                        excluded_areas = gmodel.excluded_areas_t(
                    #                                            postal_areas = [gmodel.postal_area_t(
                    #                                                country_code = 'US',
                    #                                                )],
                    #                                        ),
                )
            ]))
        cart = gmodel.checkout_shopping_cart_t(shopping_cart=shopping_cart,
                                               checkout_flow_support=support)
        logging.debug(cart)
        return cart
コード例 #6
0
 def checkout_shopping_cart(self, cart, analytics_data=None):
     options = IGoogleCheckoutOptions(self.context)
     cart_key = getUtility(IShoppingCartUtility).getKey(self.context)
     edit_cart_url = '%s/getpaid-cart' % self.context.absolute_url()
     continue_shopping_url = self.context.absolute_url()
     return gmodel.checkout_shopping_cart_t(
         shopping_cart = gmodel.shopping_cart_t(
             items = [gcart_item(entry, options) for entry in cart.values()],
             merchant_private_data={'cart-key': cart_key},
             ),
         checkout_flow_support = gmodel.checkout_flow_support_t(
             shipping_methods = IGoogleCheckoutShipping(self.context)(cart),
             analytics_data = analytics_data,
             edit_cart_url = edit_cart_url,
             continue_shopping_url = continue_shopping_url,
             ),
         )
コード例 #7
0
ファイル: donations.py プロジェクト: zandeez/gchecky
def prepare_simple_donation(controller, amount, title):
    # TODO: get view url
    CONTINUE_SHOPPING_URL = '%s/donation/continue' % ('http://demo.gchecky.com',)
    return controller.prepare_donation(
        order = gmodel.checkout_shopping_cart_t(
            shopping_cart = gmodel.shopping_cart_t(
                items = [gmodel.item_t(
                    name = title,
                    description = title,
                    unit_price = gmodel.price_t(
                        value = amount,
                        currency = controller.currency
                    ),
                    quantity = 1
                )],
                merchant_private_data = 'donation'
            ),
            checkout_flow_support = gmodel.checkout_flow_support_t(
                continue_shopping_url = CONTINUE_SHOPPING_URL
            )
        )
    )