当前位置: 首页>>代码示例>>Python>>正文


Python PagSeguro.checkout方法代码示例

本文整理汇总了Python中pagseguro.PagSeguro.checkout方法的典型用法代码示例。如果您正苦于以下问题:Python PagSeguro.checkout方法的具体用法?Python PagSeguro.checkout怎么用?Python PagSeguro.checkout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pagseguro.PagSeguro的用法示例。


在下文中一共展示了PagSeguro.checkout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pay_pagseguro

# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import checkout [as 别名]
 def pay_pagseguro(self):
     # import pdb;pdb.set_trace()
     pg = PagSeguro(email="[email protected]", token="4194D1DFC27E4E1FAAC0E1B20690B5B5")
     pg.sender = {
         "name": self.user.full_name,
         "email": self.user.email,
     }
     pg.reference_prefix = None
     pg.reference = self.id
     
     for item in self.itens.all():
         pg.add_item(id=item.option.id, description=item.option.title, amount=item.option.new_price, quantity=item.quantity, weight=0)
     # pg.redirect_url = "http://meusite.com/obrigado"
     response = pg.checkout()
     self.code_pagseguro = response.code
     self.save()
     return response.payment_url
开发者ID:victorpluna,项目名称:oferclub,代码行数:19,代码来源:models.py

示例2: PagSeguroProcessor

# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import checkout [as 别名]
class PagSeguroProcessor(BaseProcessor):

    STATUS_MAP = {
        "1": "checked_out",
        "2": "analysing",
        "3": "confirmed",
        "4": "completed",
        "5": "refunding",
        "6": "refunded",
        "7": "cancelled"
    }

    def __init__(self, cart, *args, **kwargs):
        self.cart = cart
        self.config = kwargs.get('config')
        self._record = kwargs.get('_record')
        if not isinstance(self.config, dict):
            raise ValueError("Config must be a dict")
        email = self.config.get('email')
        token = self.config.get('token')
        self.pg = PagSeguro(email=email, token=token)
        self.cart and self.cart.addlog(
            "PagSeguro initialized {}".format(self.__dict__)
        )

    def validate(self, *args, **kwargs):
        self.pg.sender = self.cart.sender_data
        self.pg.shipping = self.cart.shipping_data
        self.pg.reference = self.cart.get_uid()
        extra_costs = self.cart.get_extra_costs()
        if extra_costs:
            self.pg.extra_amount = "%.2f" % extra_costs

        self.pg.items = [
            {
                "id": item.get_uid(),
                "description": item.title[:100],
                "amount": "%.2f" % item.unity_plus_extra,
                "weight": item.weight,
                "quantity": int(item.quantity or 1)
            }
            for item in self.cart.items if item.total >= 0
        ]

        if hasattr(self.cart, 'redirect_url'):
            self.pg.redirect_url = self.cart.redirect_url
        else:
            self.pg.redirect_url = self.config.get('redirect_url')

        if hasattr(self.cart, 'notification_url'):
            self.pg.notification_url = self.cart.notification_url
        else:
            self.pg.notification_url = self.config.get('notification_url')

        self.cart.addlog("pagSeguro validated {}".format(self.pg.data))
        return True  # all data is valid

    def process(self, *args, **kwargs):
        kwargs.update(self._record.config)
        kwargs.update(self.cart.config)
        response = self.pg.checkout(**kwargs)
        self.cart.addlog(
            (
                "lib checkout data:{pg.data}\n"
                " code:{r.code} url:{r.payment_url}\n"
                " errors: {r.errors}\n"
                " xml: {r.xml}\n"
            ).format(
                pg=self.pg, r=response
            )
        )
        if not response.errors:
            self.cart.checkout_code = response.code
            #self.cart.status = 'checked_out'  # should set on redirect url
            self.cart.addlog("PagSeguro processed! {}".format(response.code))
            return redirect(response.payment_url)
        else:
            self.cart.addlog(
                'PagSeguro error processing {}'.format(
                    response.errors
                )
            )
            return render_template("cart/checkout_error.html",
                                   response=response, cart=self.cart)

    def notification(self):
        code = request.form.get('notificationCode')
        if not code:
            return "notification code not found"

        response = self.pg.check_notification(code)
        reference = getattr(response, 'reference', None)
        if not reference:
            return "reference not found"

        PREFIX = self.pg.config.get('REFERENCE_PREFIX', '') or ''
        PREFIX = PREFIX.replace('%s', '')

        status = getattr(response, 'status', None)
        transaction_code = getattr(response, 'code', None)
#.........这里部分代码省略.........
开发者ID:mpmedia,项目名称:quokka-cart,代码行数:103,代码来源:pagseguro_processor.py


注:本文中的pagseguro.PagSeguro.checkout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。