Esempio n. 1
0
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
Esempio n. 2
0
    def _get_items(self, order):
        items = []
        handling_fee = 0
        for ticketorder in order.get_ticketorders():
            # tickets w/o handling fee
            items.append(
                gmodel.item_t(
                    name=ticketorder.ticket_type.name + ' ticket',
                    description=ticketorder.ticket_type.get_description()
                    or "",
                    unit_price=gmodel.price_t(
                        value=ticketorder.ticket_type.get_price() / 100.0,
                        currency=ticketorder.ticket_type.currency_id,
                    ),
                    quantity=ticketorder.amount))
            # remember handling fee
            handling_fee += ticketorder.ticket_type.get_handling_fee(
            ) * ticketorder.amount / 100.0

        if order.account.subscription.get_feature('service_fee_enabled'):
            # add handling fee total
            items.append(
                gmodel.item_t(name='Handling fee',
                              description="",
                              unit_price=gmodel.price_t(
                                  value=handling_fee,
                                  currency=ticketorder.ticket_type.currency_id,
                              ),
                              quantity=1))

        return items
    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
    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
 def refund_order(self, order_id, amount, reason, comment=None):
     self.send_message(gmodel.refund_order_t(
         google_order_number = order_id,
         amount = gmodel.price_t(value = amount, currency = self.currency),
         reason = reason,
         comment = comment or None
         ))
Esempio n. 6
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
def gcart_item(entry, options):
    return gmodel.item_t(
        name = entry.name,
        description = entry.description,
        unit_price = gmodel.price_t(
            value = entry.cost,
            currency = options.currency,
            ),
        quantity = entry.quantity,
        merchant_item_id = entry.product_code,
        )
Esempio n. 8
0
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
            )
        )
    )
 def charge_order(self, order_id, amount):
     self.send_message(gmodel.charge_order_t(
         google_order_number = order_id,
         amount = gmodel.price_t(value = amount, currency = self.currency)
         ))