當前位置: 首頁>>代碼示例>>Python>>正文


Python PagSeguro.check_notification方法代碼示例

本文整理匯總了Python中pagseguro.PagSeguro.check_notification方法的典型用法代碼示例。如果您正苦於以下問題:Python PagSeguro.check_notification方法的具體用法?Python PagSeguro.check_notification怎麽用?Python PagSeguro.check_notification使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pagseguro.PagSeguro的用法示例。


在下文中一共展示了PagSeguro.check_notification方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pagseguro_notification

# 需要導入模塊: from pagseguro import PagSeguro [as 別名]
# 或者: from pagseguro.PagSeguro import check_notification [as 別名]
def pagseguro_notification(request):
    notification_code = request.POST.get('notificationCode', None)
    if notification_code:
    	pg = PagSeguro(
    		email=settings.PAGSEGURO_EMAIL, token=settings.PAGSEGURO_TOKEN,
    		config={'sandbox': settings.PAGSEGURO_SANDBOX}
    		)
    	notification_data = pg.check_notification(notification_code)
    	status = notification_data.status
    	reference = notification_data.reference
    	try:
    		order = Order.objects.get(pk=reference)
    	except Order.DoesNotExist:
    		pass
    	else:
    		order.pagseguro_update_status(status)
    	return HttpResponse('OK')	
開發者ID:Renanf68,項目名稱:gir_ecommerce,代碼行數:19,代碼來源:views.py

示例2: notification_view

# 需要導入模塊: from pagseguro import PagSeguro [as 別名]
# 或者: from pagseguro.PagSeguro import check_notification [as 別名]
def notification_view(request):
    notification_code = request.POST['notificationCode']
    pg = PagSeguro(email=app.config['EMAIL'], token=app.config['TOKEN'])
    pg.check_notification(notification_code)
開發者ID:Jandersolutions,項目名稱:python-pagseguro,代碼行數:6,代碼來源:views.py

示例3: PagSeguroProcessor

# 需要導入模塊: from pagseguro import PagSeguro [as 別名]
# 或者: from pagseguro.PagSeguro import check_notification [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.check_notification方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。